Strands Agents
Overview
Strands Agents is an open-source SDK from AWS for building and running AI agents. It emits OpenTelemetry spans natively using the OTel GenAI semantic conventions, making it straightforward to integrate with Confident AI for real-time tracing and evaluation.
The integration works via OpenTelemetry: instrument_strands() registers a StrandsSpanInterceptor and a ContextAwareSpanProcessor on the global TracerProvider. Strands’ built-in tracer picks up the provider automatically — so you only need to call instrument_strands() once before creating your Agent, and all spans flow to Confident AI in real time.
Tracing Quickstart
For users in the EU region, please set the OTEL endpoint to the EU version as shown below:
Instrument Strands
Call instrument_strands once at startup, before creating your Agent. It registers deepeval’s processors on the global TracerProvider so Strands’ built-in tracer picks them up automatically.
Strands emits OTel GenAI semantic convention attributes natively (gen_ai.user.message, gen_ai.choice, gen_ai.usage.input_tokens, gen_ai.operation.name, etc.), so the integration captures agent, LLM, and tool spans automatically with no extra configuration.
Run your agent
Execute the script to send traces to Confident AI:
You can directly view the traces on Confident AI by clicking on the link in the output printed in the console.
What Gets Captured
The Strands integration automatically extracts the following data from each span:
Token counts are read from gen_ai.usage.input_tokens / gen_ai.usage.output_tokens (and the prompt_tokens / completion_tokens aliases). The LLM provider is inferred from the model name, or read directly from gen_ai.response.provider when available.
Advanced Usage
Logging threads
Threads group related traces together and are useful for chat apps, agents, or any multi-turn interactions. You can learn more about threads here. Pass thread_id to instrument_strands.
Strands supports passing custom attributes via trace_attributes={"session.id": "..."} when creating an agent. The integration automatically promotes session.id to thread_id when no explicit thread_id is provided.
Trace attributes
All trace-level attributes are optional and apply to every trace produced while the instrumentation is active.
View Trace Attributes
Your Confident AI API key. Defaults to the CONFIDENT_API_KEY environment variable when omitted.
The name of the trace. Learn more.
Tags are string labels that help you group related traces. Learn more.
Attach any metadata to the trace. Learn more.
Supply the thread or conversation ID to view and evaluate conversations. Learn more.
Supply the user ID to enable user analytics. Learn more.
The turn ID for multi-turn conversations.
Associate this trace with a specific test case ID.
The name of the metric collection to use for online evals at the trace level.
The deployment environment. Accepted values: "production", "staging", "development", "testing". Defaults to "development".
Each attribute is optional, and works the same way as the native tracing features on Confident AI.
Logging prompts
If you are managing prompts on Confident AI and wish to log them, use next_llm_span to associate a Prompt with the next LLM span before invoking your agent.
Be sure to pull the prompt before logging it, otherwise the prompt will not be visible on Confident AI.
Using with tools
The integration captures tool spans automatically. Define tools with the @tool decorator and pass them to your Agent as usual.
Each tool invocation produces a tool span with the tool name and input parameters captured automatically.
Using with observe
When instrument_strands is called inside an active deepeval @observe / with trace(...) context, Strands’ OTel spans are stitched into the enclosing deepeval trace. update_current_span(...) and update_current_trace(...) work anywhere in the call stack.
Evals Usage
Online evals
You can run online evals on your Strands agent, which will run evaluations on all incoming traces on Confident AI’s servers. This approach is recommended if your agent is in production.
Create metric collection
Create a metric collection on Confident AI with the metrics you wish to use to evaluate your Strands agent.
Your metric collection must only contain metrics that evaluate the input and actual output of the component it is assigned to.
Run evals
Pass the metric_collection parameter to instrument_strands to run online evals at the trace level. For span-level evals, use update_current_span(metric_collection=...) inside your agent code.
We recommend creating separate metric collections for each component (trace, agent span, LLM span, tool span), since each requires its own evaluation criteria and metrics.
All incoming traces will now be evaluated using metrics from your metric collection.
You can view evals on Confident AI by clicking on the link in the output printed in the console.