Launch Week 02 wrapped — explore all five launches

Strands Agents

Use Confident AI for LLM observability and evals for 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

  1. Install Dependencies

    Run the following command to install the required packages:

    pip install -U deepeval strands-agents opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
  2. 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.

    main.py
    from strands import Agent
    from deepeval.integrations.strands import instrument_strands
    
    instrument_strands()
    
    agent = Agent(model="us.amazon.nova-lite-v1:0")
    result = agent("Explain OpenTelemetry in one sentence.")
    print(result.message)
  3. Run your agent

    Execute the script to send traces to Confident AI:

    python main.py

    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:

Span TypeData Captured
AgentAgent name, input message, output message, tool calls made
LLMModel name, provider, input/output messages, token counts (input + output)
ToolTool name, input parameters, output

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.

main.py
from strands import Agent
from deepeval.integrations.strands import instrument_strands

instrument_strands(
    thread_id="conversation-abc123",
    user_id="user_1",
)

agent = Agent(model="us.amazon.nova-lite-v1:0")
result = agent("What's the capital of France?")
print(result.message)

Trace attributes

All trace-level attributes are optional and apply to every trace produced while the instrumentation is active.

main.py
from strands import Agent
from deepeval.integrations.strands import instrument_strands

instrument_strands(
    name="My Strands Agent",
    tags=["production", "v2"],
    metadata={"region": "us-east-1"},
    user_id="user_1",
    thread_id="conversation-abc123",
    environment="production",
)

agent = Agent(model="us.amazon.nova-lite-v1:0")
result = agent("Summarize the latest AI news.")
print(result.message)
View Trace Attributes

api_keystr

Your Confident AI API key. Defaults to the CONFIDENT_API_KEY environment variable when omitted.

namestr

The name of the trace. Learn more.

tagsList[str]

Tags are string labels that help you group related traces. Learn more.

metadataDict

Attach any metadata to the trace. Learn more.

thread_idstr

Supply the thread or conversation ID to view and evaluate conversations. Learn more.

user_idstr

Supply the user ID to enable user analytics. Learn more.

turn_idstr

The turn ID for multi-turn conversations.

test_case_idstr

Associate this trace with a specific test case ID.

metric_collectionstr

The name of the metric collection to use for online evals at the trace level.

environmentstr

The deployment environment. Accepted values: "production", "staging", "development", "testing". Defaults to "development".

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.

main.py
from strands import Agent
from deepeval.prompt import Prompt
from deepeval.tracing import next_llm_span
from deepeval.integrations.strands import instrument_strands

instrument_strands(environment="production")

agent = Agent(model="us.amazon.nova-lite-v1:0")

prompt = Prompt(alias="<prompt-alias>")
prompt.pull(version="00.00.01")

with next_llm_span(prompt=prompt):
    result = agent(prompt.interpolate())
print(result.message)

Using with tools

The integration captures tool spans automatically. Define tools with the @tool decorator and pass them to your Agent as usual.

main.py
from strands import Agent
from strands.tools import tool
from deepeval.integrations.strands import instrument_strands

instrument_strands(environment="production")

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"The weather in {city} is sunny and 22°C."

agent = Agent(
    model="us.amazon.nova-lite-v1:0",
    tools=[get_weather],
)

result = agent("What's the weather like in Paris?")
print(result.message)

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.

main.py
from strands import Agent
from deepeval import observe
from deepeval.integrations.strands import instrument_strands

instrument_strands()

agent = Agent(model="us.amazon.nova-lite-v1:0")

@observe(name="my-app")
def run_pipeline(prompt: str) -> str:
    # Strands spans are stitched into this @observe trace automatically
    result = agent(prompt)
    return result.message

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.

  1. Create metric collection

    Create a metric collection on Confident AI with the metrics you wish to use to evaluate your Strands agent.

    Create metric collection
  2. 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.

    main.py
    from strands import Agent
    from deepeval.integrations.strands import instrument_strands
    
    instrument_strands(
        metric_collection="my-trace-collection",
        environment="production",
    )
    
    agent = Agent(model="us.amazon.nova-lite-v1:0")
    result = agent("Summarize the latest AI news.")
    print(result.message)

You can view evals on Confident AI by clicking on the link in the output printed in the console.

Need help wiring this into your stack?Bring traces and evals into the tools your team already usesTalk to an expert
Built byConfident AI