> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agnost.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Strands Agents

> Capture traces from Strands Agents with its built-in OpenTelemetry export

## Choose a setup method

| Method | Use it when |
| - | - |
| **Agnost AI skill** | You want your coding agent to inspect the app, make the change, and verify it. |
| **Agnost AI SDK** | You want explicit control over the interaction boundaries and fields. |
| **OpenTelemetry** | The framework already emits useful spans or you operate an OTel pipeline. |

Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.

## Recommended: Agnost AI skill

> [!NOTE]
>
> **Recommended.** Choose this path when you want your coding agent to inspect the
> project, select a supported transport, make the smallest instrumentation change,
> send a test event, and verify that it reached Agnost AI.

Install the skill once in your coding-agent environment:

```bash theme={null}
npx skills add AgnostAI/skills --skill agnost-ai
```

Run the framework-specific prompt below from the application root. Review the
resulting diff before deploying it.

```text theme={null}
Use the agnost-ai skill to add Agnost AI analytics to this Strands Agents application.
Org ID: your-org-id
Instrument the real agent() call path, set session.id and user.id in trace_attributes, and verify one fresh interaction.
```

## Manual setup: Agnost AI SDK

```bash theme={null}
pip install agnost
```

```python theme={null}
import agnost

agnost.init("your-org-id")
interaction = agnost.begin(
    user_id="u-42",
    agent_name="strands-support",
    input=prompt,
    conversation_id="sess-123",  # groups turns into one conversation
)
if interaction is None:
    raise RuntimeError("Agnost is not initialized. Call agnost.init() first.")
try:
    result = agent(prompt)
    interaction.end(output=str(result))
except Exception as exc:
    interaction.end(output=str(exc), success=False)
    raise
```

Call `agnost.shutdown()` once when the application exits, not after each request.

## Manual setup: OpenTelemetry

Strands Agents emits OpenTelemetry spans for every agent run, event loop cycle, model call, and tool call, using the OpenTelemetry GenAI semantic conventions. Point its OTLP exporter at Agnost AI and set the session and user on the agent.

### Install

```bash theme={null}
pip install 'strands-agents[anthropic,otel]'
```

The `otel` extra installs the OTLP HTTP exporter. Swap `anthropic` for the extra of your model provider.

### Setup

Set this before Strands starts:

```bash theme={null}
export OTEL_SEMCONV_STABILITY_OPT_IN="gen_ai_latest_experimental,gen_ai_span_attributes_only"
```

`gen_ai_latest_experimental` switches Strands to the current GenAI conventions, and `gen_ai_span_attributes_only` writes prompts and answers as span attributes instead of span events. With both set, Agnost AI shows each turn's user message and answer as plain text. Without them, Strands still works, but messages show up wrapped in Strands content blocks such as `[{"text": "..."}]`.

```python theme={null}
from strands import Agent, tool
from strands.models.anthropic import AnthropicModel
from strands.telemetry import StrandsTelemetry

telemetry = StrandsTelemetry()
telemetry.setup_otlp_exporter(
    endpoint="https://otel.agnost.ai/v1/traces",
    headers={"X-Agnost-Org-ID": "your-org-id"},
)


@tool
def get_weather(city: str) -> str:
    """Return the current weather for a city."""
    return f"It is sunny in {city}."


agent = Agent(
    name="weather-agent",
    model=AnthropicModel(model_id="claude-haiku-4-5", max_tokens=1024),
    tools=[get_weather],
    system_prompt="Answer weather questions with get_weather.",
    trace_attributes={"session.id": "sess-123", "user.id": "u-42"},
)

agent("What's the weather in Paris?")
agent("And in Tokyo?")
telemetry.tracer_provider.force_flush()
```

`trace_attributes` puts `session.id` and `user.id` on every Strands span. Agnost AI groups all turns with the same `session.id` into one conversation and attributes it to `user.id`. Create one `Agent` per user session, or set a new `trace_attributes` value for each session.

You can also configure the exporter with the standard variables instead of arguments: set `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://otel.agnost.ai/v1/traces` and `OTEL_EXPORTER_OTLP_TRACES_HEADERS=X-Agnost-Org-ID=your-org-id`, then call `setup_otlp_exporter()` with no arguments.

### What appears in Agnost AI

* **Conversations**: one per `session.id`. The raw value is kept as `original_conversation_id` in the conversation metadata.
* **Users**: the `user.id` from `trace_attributes`.
* **Messages**: the user's prompt and the agent's final answer for each `agent(...)` call, from the root `invoke_agent` span.
* **Events**: `invoke_agent`, `execute_event_loop_cycle`, `chat`, and `execute_tool` spans in a nested tree. Tool events carry the tool name, arguments, and result. Model events carry token counts.

### Verify

Run one agent call, wait about 30 seconds, then open **Conversations** in Agnost AI. Confirm the conversation shows your `user.id`, a user message and an assistant answer, and a `get_weather` tool event with arguments and a result.

### Troubleshooting

* **Nothing arrives**: confirm the exporter header is `X-Agnost-Org-ID` and the endpoint ends in `/v1/traces`. Short scripts must call `telemetry.tracer_provider.force_flush()` before they exit, because the exporter sends in batches.
* **Each turn is its own conversation, or the user is empty**: `trace_attributes` is missing `session.id` or `user.id`.
* **Messages look like `[{"text": "..."}]`**: set `OTEL_SEMCONV_STABILITY_OPT_IN` as shown above before the process starts.
* **Model calls appear twice**: the Anthropic Python SDK 2.x also emits its own `anthropic.messages.create` span for each API call, without message content. Set `ANTHROPIC_OPEN_TELEMETRY=false` to turn it off.
* **Your app already has a tracer provider**: Strands writes its spans to the global tracer provider. Skip `StrandsTelemetry()` and add an `OTLPSpanExporter` for Agnost AI to the provider your app already registered.

### References

* [Strands Agents traces](https://strandsagents.com/docs/user-guide/sdk/observability-evaluation/traces/)
* [Strands Agents Anthropic model provider](https://strandsagents.com/docs/user-guide/sdk/model-providers/anthropic/)
* [OpenTelemetry GenAI agent spans](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-agent-spans/)

## Next steps

* [Conversations](https://docs.agnost.ai/using-conversations.md): review the complete Strands session.
* [Events](https://docs.agnost.ai/using-events.md): inspect agent, model, and tool activity.
* [Patterns](https://docs.agnost.ai/using-patterns.md): organize production conversations by what users wanted.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.