Skip to main content
GitHub

OpenAI Agents

Auto-instrument OpenAI Agents SDK.

Risicare automatically instruments the OpenAI Agents SDK.

Installation

pip install risicare[openai-agents]
# or
pip install risicare openai-agents

Version 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

FeatureDescription
Agent ExecutionFull agent run with all turns
Tool CallsFunction/tool executions
HandoffsAgent-to-agent transfers
LLM CallsUnderlying OpenAI API calls
Context VariablesShared context state

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 fully traced:

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 appear as child spans
result = await Runner.run(triage_agent, "I want to buy something")

Tools

Tool executions are captured:

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]
)
 
# Tool calls appear as spans with inputs/outputs
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_variables={"user_name": "Alice"}
)
 
# Context variables are captured in the span

Streaming

Not Instrumented

run_streamed is NOT currently instrumented. Use Runner.run() for full trace capture.

async for event in Runner.run_streamed(agent, "Write a story"):
    if event.type == "content":
        print(event.content, end="")

Next Steps