-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Describe the bug
RealtimeAgent sessions do not create trace spans, resulting in empty traces on the OpenAI dashboard. While trace IDs are generated and exported, no span data (AgentSpanData, GenerationSpanData, etc.) is recorded during RealtimeRunner execution.
Debug information
- Agents SDK version: v0.3.2
- Python version: 3.12.3
Repro steps
- Create a RealtimeAgent with tracing enabled:
from agents import enable_verbose_stdout_logging, set_tracing_export_api_key, trace
from agents.realtime import RealtimeAgent, RealtimeRunner
import os
enable_verbose_stdout_logging()
set_tracing_export_api_key(os.environ.get("OPENAI_API_KEY"))
with trace("RealtimeAgent Test"):
agent = RealtimeAgent(
name="TestAgent",
instructions="You are a helpful assistant.",
)
runner = RealtimeRunner(
starting_agent=agent,
config={
"model_settings": {
"model_name": "gpt-realtime",
"voice": "ash",
"modalities": ["text", "audio"],
}
},
)
session = await runner.run()
async with session:
await asyncio.sleep(2)
- Check the OpenAI dashboard for the generated trace
Expected behavior
- Trace should contain spans similar to normal Agent runs
- AgentSpanData and other span types should be visible in the trace
- Tool calls, handoffs, and other operations should be tracked
Actual behavior
- Trace ID is created and exported successfully
- No spans are found in the trace ("No spans found" message in dashboard)
- Only the trace shell exists without any execution details
Comparison with normal Agent
Normal Agent (Runner.run) - Works correctly:
from agents import Agent, Runner, trace
with trace("Normal Agent Test"):
agent = Agent(
name="NormalAgent",
instructions="You are a helpful assistant.",
model="gpt-4o-2024-08-06",
)
result = await Runner.run(agent, "Say hello")
Result: Trace contains AgentSpanData and GenerationSpanData ✅
RealtimeAgent (RealtimeRunner) - Missing spans:
Result: Trace exists but contains no spans ❌
Root cause analysis
After investigating the source code:
-
Normal Runner (
agents/run.py:521, 886
):current_span = agent_span( name=current_agent.name, handoffs=handoff_names, output_type=output_type_name, ) current_span.start(mark_as_current=True)
-
RealtimeRunner (
agents/realtime/runner.py
):- No calls to
agent_span()
- No calls to
generation_span()
- Span creation logic is completely missing
- No calls to
The RealtimeRunner architecture differs from the standard Runner, and the tracing instrumentation was not integrated.
Impact
- Unable to debug RealtimeAgent interactions via traces
- Cannot monitor tool calls, handoffs, or generation details
- Traces dashboard shows incomplete data
Related issues
- Briefly mentioned in Tool Call Results are not Appearing in Realtime API and Tool Calls are Not Showing Up in Tracing #1156 but not addressed
- This appears to be a systematic issue with RealtimeAgent tracing architecture
Suggested fix
Integrate span creation into RealtimeRunner similar to the standard Runner:
- Add AgentSpanData creation when agents start
- Add GenerationSpanData for model calls
- Add FunctionSpanData for tool executions
- Add HandoffSpanData for agent handoffs