Reasoning Agent Events
Capture lifecycle and content-delta events from a separate reasoning stage.
Capture reasoning events during streaming.
"""
Reasoning Agent Events
=============================
Demonstrates how to capture reasoning events during streaming.
"""
import asyncio
from agno.agent import RunEvent
from agno.agent.agent import Agent
from agno.models.openai import OpenAIResponses
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
finance_agent = Agent(
model=OpenAIResponses(id="gpt-5.6"),
reasoning_model=OpenAIResponses(id="o3-mini"),
)
async def run_agent_with_events(prompt: str):
content_started = False
async for run_output_event in finance_agent.arun(
prompt,
stream=True,
stream_events=True,
):
if run_output_event.event in [RunEvent.run_started, RunEvent.run_completed]:
print(f"\nEVENT: {run_output_event.event}")
if run_output_event.event in [RunEvent.reasoning_started]:
print(f"\nEVENT: {run_output_event.event}")
if run_output_event.event in [RunEvent.reasoning_step]:
print(f"\nEVENT: {run_output_event.event}")
print(f"REASONING CONTENT: {run_output_event.reasoning_content}") # type: ignore
if run_output_event.event in [RunEvent.reasoning_completed]:
print(f"\nEVENT: {run_output_event.event}")
if run_output_event.event in [RunEvent.run_content]:
if not content_started:
print("\nCONTENT:")
content_started = True
else:
print(run_output_event.content, end="")
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
task = (
"Analyze the key factors that led to the signing of the Treaty of Versailles in 1919. "
"Discuss the political, economic, and social impacts of the treaty on Germany and how it "
"contributed to the onset of World War II. Provide a nuanced assessment that includes "
"multiple historical perspectives."
)
asyncio.run(
run_agent_with_events(
task,
)
)Handle native reasoning content
The configured native reasoning stage emits ReasoningContentDelta; ReasoningStep belongs to a different structured reasoning path. Replace run_agent_with_events in the saved script with this consumer:
async def run_agent_with_events(prompt: str):
content_started = False
async for event in finance_agent.arun(prompt, stream=True, stream_events=True):
if event.event in (
RunEvent.run_started, RunEvent.run_completed,
RunEvent.reasoning_started, RunEvent.reasoning_completed,
):
print(f"\nEVENT: {event.event}")
elif event.event == RunEvent.reasoning_content_delta:
print(event.reasoning_content, end="", flush=True)
elif event.event == RunEvent.reasoning_step:
print(event.reasoning_content, end="", flush=True)
elif event.event == RunEvent.run_content and event.content:
if not content_started:
print("\nCONTENT:")
content_started = True
print(event.content, end="", flush=True)
elif event.event == RunEvent.run_error:
print(f"\nERROR: {event.content}")The intermediate text can be the separate reasoning model's answer. It is not guaranteed access to a model's private chain of thought. As of September 7, 2026, OpenAI schedules o3-mini retirement for October 23, 2026; check the deprecation table before selecting that model for a new deployment.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as reasoning_agent_events.py, then run:
python reasoning_agent_events.pyFull source: cookbook/02_agents/14_advanced/reasoning_agent_events.py