OpenAI Agents SDK
OpenAI Agents SDK is OpenAI’s framework for building AI agents. SideSeat captures full agent-level traces including tool calls, handoffs, and LLM calls.
Prerequisites
Section titled “Prerequisites”- SideSeat running locally (
sideseat) - Python 3.9+
- OpenAI API credentials configured
Quick Start
Section titled “Quick Start”-
Start SideSeat
Terminal window npx sideseat -
Install dependencies
Terminal window pip install openai-agents "sideseat[openai-agents]"Terminal window uv add openai-agents "sideseat[openai-agents]" -
Add telemetry
from sideseat import SideSeat, Frameworksfrom agents import Agent, RunnerSideSeat(framework=Frameworks.OpenAIAgents)agent = Agent(name="Assistant",instructions="You are a helpful assistant.")result = Runner.run_sync(agent, "Hello!")print(result.final_output) -
View runs
Open http://localhost:5388 to see your runs.
Without SideSeat SDK
Section titled “Without SideSeat SDK”Use logfire to instrument the OpenAI Agents SDK via its official hook:
-
Start SideSeat
Terminal window npx sideseat -
Set the endpoint
Terminal window export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:5388/otel/default -
Install dependencies
Terminal window pip install openai-agents "logfire>=4.29.0" opentelemetry-exporter-otlpTerminal window uv add openai-agents "logfire>=4.29.0" opentelemetry-exporter-otlp -
Add telemetry
import logfirefrom opentelemetry import tracefrom opentelemetry.sdk.trace.export import BatchSpanProcessorfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterlogfire.configure(send_to_logfire=False, console=False)logfire.instrument_openai_agents()provider = trace.get_tracer_provider()provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter())) -
View runs
Open http://localhost:5388 to see your runs.
Define tools using the @function_tool decorator:
from agents import Agent, Runner, function_tool
@function_tooldef get_weather(city: str) -> str: """Get weather for a city.""" return f"Sunny in {city}"
agent = Agent( name="WeatherAssistant", instructions="Use get_weather to provide forecasts.", tools=[get_weather])
result = Runner.run_sync(agent, "What's the weather in Paris?")SideSeat shows:
- Parent span for the agent run
- Child spans for each OpenAI call
- Child spans for each tool execution
Session Tracking
Section titled “Session Tracking”Add session context with manual spans:
from opentelemetry import trace
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span( "openai_agents.session", attributes={ "session.id": "session-123", "user.id": "user-456" }): result = Runner.run_sync(agent, "Hello!")Extracted Attributes
Section titled “Extracted Attributes”| Attribute | Description |
|---|---|
gen_ai.system | openai |
gen_ai.request.model | OpenAI model ID |
gen_ai.usage.input_tokens | Input token count |
gen_ai.usage.output_tokens | Output token count |
logfire.span_type | Span type (present when using SideSeat SDK) |
Async Usage
Section titled “Async Usage”The SDK supports async execution:
import asynciofrom agents import Agent, Runner
agent = Agent( name="Assistant", instructions="You are a helpful assistant.")
async def main(): result = await Runner.run(agent, "Hello!") print(result.final_output)
asyncio.run(main())Next Steps
Section titled “Next Steps”- OpenAI — provider details
- Python SDK — SDK reference
- Core Concepts — understanding runs, steps, and messages