OpenAI Agents
Auto-instrument OpenAI Agents SDK.
Risicare automatically instruments the OpenAI Agents SDK.
Python only
Installation
pip install risicare[openai-agents]
# or
pip install risicare openai-agentsVersion Compatibility
Requires openai-agents >= 0.1.0.
Auto-Instrumentation
import risicare
from agents import Agent, Runner
risicare.init()
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant."
)
# Automatically traced (async)
result = await Runner.run(agent, "Hello!")
# Or use run_sync for synchronous usage
# result = Runner.run_sync(agent, "Hello!")What's Captured
The integration patches Runner.run / Runner.run_sync and emits one openai_agents.run/{agent} span per run. Tools, handoffs, model, and step count are recorded as attributes on that span — not as separate child spans.
| Feature | Description |
|---|---|
| Agent Execution | The full Runner.run as a single openai_agents.run/{agent} span |
| Tools | Tool names recorded in the framework.openai_agents.tools attribute (not per-tool spans) |
| Handoffs | Recorded in the framework.openai_agents.handoffs and framework.openai_agents.final_agent attributes (not per-handoff spans) |
| LLM Calls | Underlying OpenAI API calls, traced as child spans by provider instrumentation |
| Step Count | Number of agent loop steps, in framework.openai_agents.step_count |
Span Hierarchy
openai_agents.run/{agent_name} (AGENT kind)
├── openai.chat.completions.create (provider span)
├── openai.chat.completions.create (provider span)
└── openai.chat.completions.create (provider span)
Provider Spans
OpenAI Agents SDK instrumentation creates agent/framework-level spans. Underlying LLM calls (e.g., OpenAI) are traced separately by provider instrumentation, giving you both framework-level and LLM-level visibility.
Multi-Agent Handoffs
Agent handoffs are recorded on the run span:
from agents import Agent, Runner
triage_agent = Agent(
name="Triage",
instructions="Route to the appropriate specialist.",
handoffs=["sales_agent", "support_agent"]
)
sales_agent = Agent(
name="Sales",
instructions="Handle sales inquiries."
)
support_agent = Agent(
name="Support",
instructions="Handle support requests."
)
# Handoffs are recorded in the framework.openai_agents.handoffs attribute,
# and the agent that finished the run in framework.openai_agents.final_agent —
# not as separate child spans.
result = await Runner.run(triage_agent, "I want to buy something")Tools
Tool names are recorded as a span attribute:
def get_weather(location: str) -> str:
"""Get weather for a location."""
return f"Weather in {location}: Sunny, 72°F"
agent = Agent(
name="Weather Assistant",
tools=[get_weather]
)
# The tool names are recorded in framework.openai_agents.tools on the run span.
# Per-tool child spans (with inputs/outputs) are not currently emitted; if a tool
# calls an LLM, that call is captured by provider instrumentation.
result = await Runner.run(agent, "What's the weather in Paris?")Context Variables
from agents import Agent, Runner
agent = Agent(
name="Personalized Assistant",
instructions="Greet the user by name. User name: {user_name}"
)
result = await Runner.run(
agent,
"Hello!",
context={"user_name": "Alice"}
)
# Context variables are captured in the spanStreaming
Not Instrumented
run_streamed is NOT currently instrumented. Use Runner.run() for full trace capture.
result = Runner.run_streamed(agent, "Write a story")
async for event in result.stream_events():
if event.type == "content":
print(event.content, end="")