OpenAI Agents SDK
OpenAI Agents SDK is OpenAI’s framework for building AI agents. SideSeat captures traces via Logfire’s OpenTelemetry instrumentation.
Prerequisites
Section titled “Prerequisites”- SideSeat running locally (
sideseat) - Python 3.9+
- OpenAI API credentials configured
Quick Start
Section titled “Quick Start”-
Install dependencies
Terminal window pip install openai-agents "sideseat[openai-agents]"# oruv add openai-agents "sideseat[openai-agents]" -
Add telemetry
from sideseat import SideSeat, FrameworksSideSeat(framework=Frameworks.OpenAIAgents)from agents import Agent, Runneragent = Agent(name="Assistant",instructions="You are a helpful assistant.")result = Runner.run_sync(agent, "Hello!")print(result.final_output)
Without SideSeat SDK
Section titled “Without SideSeat SDK”Use Logfire’s instrumentation with a manual OTLP exporter:
import logfirefrom opentelemetry import tracefrom opentelemetry.sdk.trace.export import BatchSpanProcessorfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
logfire.configure( service_name="my-agent", send_to_logfire=False, console=False)
logfire.instrument_openai_agents()
provider = trace.get_tracer_provider()if hasattr(provider, "add_span_processor"): provider.add_span_processor( BatchSpanProcessor( OTLPSpanExporter(endpoint="http://localhost:5388/otel/default/v1/traces") ) )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 from Logfire |
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