Configuration
All runtime configuration is resolved once at startup by
agentcore/config/loader.py. The result is an immutable AppConfig cached in a
module global for the container’s lifetime.
Platform-wide configuration is in Configuration and secrets; this page covers only the runtime.
load_config()
def load_config() -> AppConfig:
global _cached_config
if _cached_config is not None:
return _cached_config # 1. cache hit
secret_arn = os.environ.get("SECRET_ARN")
if not secret_arn:
raise RuntimeError("SECRET_ARN environment variable is not set. …") # 2. fail fast
sm_client = boto3.client("secretsmanager", region_name="us-east-1") # 3. fetch
response = sm_client.get_secret_value(SecretId=secret_arn)
secrets = _SecretsSchema.model_validate(json.loads(response["SecretString"])) # 4. validate
os.environ["OPENAI_API_KEY"] = secrets.OPENAI_API_KEY # 5. inject
if secrets.CLAUDE_API_KEY:
os.environ["ANTHROPIC_API_KEY"] = secrets.CLAUDE_API_KEY
os.environ["HUBSPOT_CLIENT_ID"] = secrets.HUBSPOT_CLIENT_ID
os.environ["HUBSPOT_CLIENT_SECRET"] = secrets.HUBSPOT_CLIENT_SECRET
os.environ["HUBSPOT_REFRESH_TOKEN"] = secrets.HUBSPOT_REFRESH_TOKEN
if secrets.TAVILY_API_KEY:
os.environ["TAVILY_API_KEY"] = secrets.TAVILY_API_KEY
_cached_config = AppConfig(...) # 6. build + cache
return _cached_config
Two things to note:
-
SECRET_ARNis mandatory. Its absence raises at import time, so a misconfiguration surfaces at container start rather than at the first invocation. -
The region is hardcoded to
us-east-1for the Secrets Manager client, not read fromAWS_REGION.
CLAUDE_API_KEY is injected under the name ANTHROPIC_API_KEY, which is what the
Anthropic SDK looks for. It is unnecessary on Bedrock, where the IAM role
authenticates.
Secret schema
_SecretsSchema — only these keys are read by the runtime; everything else in the
shared secret is ignored.
| Key | Required | Purpose |
|---|---|---|
|
yes |
Validated non-empty. Reserved for a future OpenAI provider. |
|
yes |
Validated non-empty |
|
yes |
Validated non-empty |
|
yes |
Validated non-empty |
|
no |
Injected as |
|
no |
Injected when present |
|
|
A field_validator rejects whitespace-only values for the four required keys, so a
blank string fails as loudly as a missing key.
AppConfig
class AppConfig(BaseModel):
# credentials (also injected into os.environ)
openai_api_key: str
claude_api_key: str | None
hubspot_client_id: str
hubspot_client_secret: str
hubspot_refresh_token: str
tavily_api_key: str | None
# provider defaults
provider: str
model_id: str
agent_name: str
system_prompt: str
max_tokens: int
max_turns: int
Agent modules read the credential fields from this object rather than from
os.environ, and pass them explicitly into tool factories. See
Tools.
Environment variables
Required
| Variable | Source |
|---|---|
|
Injected by the CDK stack when |
Injected by CDK
| Variable | Value |
|---|---|
|
The stack’s region |
|
|
|
|
Optional provider defaults
Read by load_config(), each with a code fallback:
| Variable | Default | Effect |
|---|---|---|
|
|
Selects the default model table entry |
|
|
|
|
|
Display name |
|
|
Fallback system prompt |
|
|
|
|
|
|
|
These defaults are currently unused by the registered workflows. Both agents carry
their own explicit Note also that |
Rotating credentials
The secret is cached in a module global for the container’s lifetime. A rotated value takes effect on the next cold start. Force one by redeploying, or by updating the runtime configuration so the platform recycles the container.
Adding a secret key
-
Add the key to the Secrets Manager secret.
-
Add the field to
_SecretsSchemainagentcore/config/loader.py— optional unless the runtime genuinely cannot start without it. -
Inject it into
os.environonly if a third-party SDK needs to auto-discover it. -
Add it to
AppConfigand populate it in the_cached_configconstructor. -
Pass it explicitly to whatever needs it, rather than having that code read
os.environ. -
Document it in the shared secret.