Documentation Index
Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Strands Agent SDK is a Python framework for building AI agents. Braintrust traces Strands agents using OpenTelemetry to capture agent invocations, tool calls, and multi-step interactions.
Setup
This integration uses Braintrust’s Python SDK OpenTelemetry configuration.
Install the Strands Agent SDK with OpenTelemetry instrumentation:
pip install "braintrust[otel]" strands-agents-tools strands-agents[openai]
Configure your environment variables:
BRAINTRUST_API_KEY="<your Braintrust API key>"
BRAINTRUST_PARENT="project_name:<your Braintrust Project Name>"
OPENAI_API_KEY="<your OpenAI API key>"
# For organizations on the EU data plane, use https://api-eu.braintrust.dev
# For self-hosted deployments, use your data plane URL
# BRAINTRUST_API_URL=<your-braintrust-api-url>
Trace with Strands Agent SDK
Configure OpenTelemetry with Braintrust’s span processor and Strands telemetry.
This example adapts the Weather Forecaster Strands example:
# Load packages to form the Strands agent using an OpenAI model
# Load packages to execute the agent
import asyncio
import os
from braintrust.otel import BraintrustSpanProcessor
from dotenv import load_dotenv
# Load OpenTelemetry assets and Braintrust span processor added to the project from the braintrust[otel] library
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from strands import Agent
from strands.models.openai import OpenAIModel
from strands.telemetry import StrandsTelemetry
from strands_tools import http_request
load_dotenv()
# Define a weather-focused system prompt
WEATHER_SYSTEM_PROMPT = """You are a weather assistant with HTTP capabilities. You can:
1. Make HTTP requests to the National Weather Service API
2. Process and display weather forecast data
3. Provide weather information for locations in the United States
When retrieving weather information:
1. First get the coordinates or grid information using https://api.weather.gov/points/{latitude},{longitude} or https://api.weather.gov/points/{zipcode}
2. Then use the returned forecast URL to get the actual forecast
When displaying responses:
- Format weather data in a human-readable way
- Highlight important information like temperature, precipitation, and alerts
- Handle errors appropriately
- Convert technical terms to user-friendly language
Always explain the weather conditions clearly and provide context for the forecast.
"""
# Configure the global OTel tracer provider
provider = TracerProvider()
trace.set_tracer_provider(provider)
# Add the Braintrust span processor to the tracer provider and configure Strands telemetry
provider.add_span_processor(BraintrustSpanProcessor())
telemetry = StrandsTelemetry(provider)
# Configure the OpenAI model to be used by the Strands agent
model = OpenAIModel(
client_args={
"api_key": os.getenv("OPENAI_API_KEY"),
},
# **model_config
model_id="gpt-4o-mini",
)
# Create an agent with HTTP tool call capabilities and the OpenAI model
weather_agent = Agent(
system_prompt=WEATHER_SYSTEM_PROMPT,
tools=[http_request], # Explicitly enable http_request tool
model=model,
)
# Create an async function to run the agent
async def main():
result = await weather_agent.invoke_async(prompt="What is the weather in San Francisco?")
print(result)
if __name__ == "__main__":
asyncio.run(main())
Resources