View a markdown version of this page

Strands agents on AgentCore Runtime - Amazon Bedrock AgentCore

Strands agents on AgentCore Runtime

When you run a Strands agent on Amazon Bedrock AgentCore Runtime, you want to know the setup steps, so cost attributes flow without extra wiring.

What Runtime supplies automatically

AgentCore Runtime:

  • Creates the session id (or keeps the one you supply) and makes it available to your agent.

  • Derives the agent identity from the runtime resource.

  • Propagates the identity to the AgentCore tools your agent calls.

You do not wire session or agent identifiers by hand on AgentCore Runtime.

Instrument with ADOT

ADOT is not bundled. AgentCore Runtime injects the OpenTelemetry environment variables (OTEL_PYTHON_DISTRO=aws_distro, OTEL_PYTHON_CONFIGURATOR=aws_configurator, resource attributes, and exporter headers), but you must install the AWS Distro for OpenTelemetry (ADOT) in the agent and start the agent under it.

Add ADOT and its dependencies to your agent. For Python, add them to requirements.txt:

aws-opentelemetry-distro>=0.22.0 # 0.18.0 = AgentCore observability minimum; 0.22.0 = prompt-cache tokens priced bedrock-agentcore strands-agents boto3

Start the agent under ADOT’s auto-instrumentation. For a container image, set the Dockerfile CMD:

CMD ["opentelemetry-instrument", "python", "main.py"]

For direct code deployment, set the entryPoint in agentRuntimeArtifact.codeConfiguration:

"entryPoint": ["opentelemetry-instrument", "main.py"]

ADOT 0.18.0 is the minimum for AgentCore observability; 0.16.0 is the minimum for OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS (per-tenant cost); and 0.22.0 is the minimum to price cache-read and cache-write tokens. No minimum bedrock-agentcore SDK version is needed for cost.

Invoke with a session id

Pass a runtimeSessionId of at least 33 characters on the invoke, and reuse it for every call in one conversation. See Pass the required session and agent attributes.

Turn on tracing for the agent runtime and for each AgentCore resource it uses

Turn on tracing for the agent runtime itself and for each AgentCore resource the agent uses (Gateway, Memory, Code Interpreter, Browser), with the console’s Enable tracing. Without it, only the agent’s ADOT model-call spans reach aws/spans, so no Runtime, Gateway, Memory, Code Interpreter, or Browser cost appears.

Transaction Search must also be on for the account and Region. This is a one-time per-account setup; if you deploy with the AgentCore CLI, agentcore deploy turns it on for you.

If you want per-tenant cost

To attribute cost to a tenant, do two things:

  1. Pass the tenant on each invoke: baggage="aws.tenant.id=<your tenant>".

  2. Tell ADOT to copy the tenant onto spans by setting this environment variable on the agent runtime (ADOT 0.16.0 or later):

    export OTEL_BAGGAGE_SPAN_ATTRIBUTE_KEYS=aws.tenant.id

    session.id is copied automatically; the tenant is not, so without this variable per-tenant cost does not appear. Set it on every agent runtime and instance. The per-tenant figure is an estimate calculated from public list prices and can differ from your AWS bill; the tenant value is whatever you pass.

Cost dimensions covered

All in-path primitives: model inference, Runtime compute, Gateway, Memory, Browser, Code Interpreter, and online evaluations when in the path. See Cost estimate coverage and limits.

If you use plain OpenTelemetry instead of ADOT

ADOT is the recommended setup above. If you instrument a Strands agent on AgentCore Runtime with plain OpenTelemetry instead of ADOT, cost attributes when you do the following. AgentCore Runtime already sets the agent identity, so you do not set it yourself.

  1. Use the session id Runtime supplies. Read it from BedrockAgentCoreContext.get_session_id() if your agent uses the AgentCore Python SDK app, or from the X-Amzn-Bedrock-AgentCore-Runtime-Session-Id request header. A sub-agent uses the session id its caller passed along.

  2. Add the AWS X-Ray trace format to your propagators, or the agent’s spans are not linked to the Runtime trace:

    export OTEL_PROPAGATORS=tracecontext,xray,baggage
  3. Emit the model-call span, pass the values in baggage, and copy them onto your own spans, as in Steps 5 to 7 of Self-hosted compute.

Confirm

See Check your setup is ready for cost.