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
The samples on this page use await at the top level, as in a notebook. In a script, put the code in an async def main() and call asyncio.run(main()). For a sample that does not stream, you can call Runner.run_sync() instead.
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 | In 0.6.0, traced as child spans only when the Agents SDK uses the Chat Completions API — see the notice below |
| Step Count | Number of agent loop steps, in framework.openai_agents.step_count |
In 0.6.0, the model calls of an agent run are not traced
The OpenAI Agents SDK calls the OpenAI Responses API by default. Python 0.6.0 traces the Chat Completions API and the Embeddings API, and it does not trace the Responses API. So an agent run sends one openai_agents.run/{agent} span and no LLM-call span, and the run has no token counts and no cost. If you call set_default_openai_api("chat_completions") (from agents), the Agents SDK uses the Chat Completions API, and the LLM calls arrive as child spans, as in the hierarchy below.
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
sales_agent = Agent(
name="Sales",
instructions="Handle sales inquiries."
)
support_agent = Agent(
name="Support",
instructions="Handle support requests."
)
# Define the specialists first, and pass the Agent objects.
# A list of names makes no handoff.
triage_agent = Agent(
name="Triage",
instructions="Route to the appropriate specialist.",
handoffs=[sales_agent, support_agent]
)
# 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:
from agents import Agent, Runner, function_tool
@function_tool
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
Not captured in this release. The integration does not record the context that
you pass to Runner.run().
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"}
)
# The context is not recorded on the span in this releaseStreaming
Not Instrumented
run_streamed is NOT currently instrumented. Use Runner.run() for full trace capture.
from openai.types.responses import ResponseTextDeltaEvent
result = Runner.run_streamed(agent, "Write a story")
async for event in result.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="", flush=True)