

# 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
<a name="_what_runtime_supplies_automatically"></a>

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
<a name="_instrument_with_adot"></a>

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
<a name="_invoke_with_a_session_id"></a>

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](acv-pass-required-attributes.md).

## Turn on tracing for the agent runtime and for each AgentCore resource it uses
<a name="_turn_on_tracing_for_the_agent_runtime_and_for_each_agentcore_resource_it_uses"></a>

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
<a name="_if_you_want_per_tenant_cost"></a>

To attribute cost to a tenant, do two things:

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

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

   ```bash
   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
<a name="_cost_dimensions_covered"></a>

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](acv-cost-coverage-by-primitive.md).

## If you use plain OpenTelemetry instead of ADOT
<a name="_if_you_use_plain_opentelemetry_instead_of_adot"></a>

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.

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

   ```bash
   export OTEL_PROPAGATORS=tracecontext,xray,baggage
   ```

1.  **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](acv-self-hosted-compute.md).

## Confirm
<a name="_confirm"></a>

See [Check your setup is ready for cost](acv-check-your-setup-is-ready.md).