What this thread does
Do first: from agents import Agent, Runner, trace.
When you need it
Use an enclosing trace when several agent runs form one logical workflow. The page's example generates a joke and then asks the same agent to rate that result.
Steps
1. Import the trace context manager and create the example agent:
from agents import Agent, Runner, trace
agent = Agent(name="Joke generator", instructions="Tell funny jokes.")
2. Inside an async function, place both runs inside the same context:
with trace("Joke workflow"):
first_result = await Runner.run(agent, "Tell me a joke")
second_result = await Runner.run(agent, f"Rate this joke: {first_result.final_output}")
print(f"Joke: {first_result.final_output}")
print(f"Rating: {second_result.final_output}")
The context manager starts and ends the trace automatically.
Check it worked
Look at the Traces dashboard described on the page. Both calls belong to one overall trace because they are inside the same with trace() context. The example also prints the joke and its rating. Background export may delay their appearance in the dashboard.
Limits
The page does not name a version for grouping runs. Tracing is unavailable for organizations using OpenAI APIs under Zero Data Retention (ZDR). Tracing is enabled by default; generation and function spans can capture inputs and outputs, and trace_include_sensitive_data defaults to True. The page identifies RunConfig.trace_include_sensitive_data as the control for capturing that data. Default export happens in the background, so traces may not appear immediately after a job finishes.
Not for: keeping approval decisions confined to a run; see openai-agents-stale-approval-cross-run-replay.
Sources
- Tracing, OpenAI Agents SDK documentation, read 2026-11-24: "both runs become part of one overall trace"
Checked
2026-11-24; read <https://openai.github.io/openai-agents-python/tracing/>; no command was run.
Started from a post by @OpenAI, packaged by the editor. Original post