Stream Reasoning Events over AG-UI
Stream available reasoning events from a separate native reasoning stage over AG-UI.
"""
Stream Reasoning Events over AG-UI
==================================
Enable Agno's reasoning loop and translate its reasoning lifecycle into
AG-UI REASONING_START, content, and end events before the final answer.
Prerequisites: OPENAI_API_KEY
Run: .venvs/demo/bin/python cookbook/05_agent_os/16_agui/reasoning_agent.py
Try: POST a multi-step logic problem to http://localhost:7777/reasoning/agui
"""
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS
from agno.os.interfaces.agui import AGUI
# ---------------------------------------------------------------------------
# Create Reasoning Agent
# ---------------------------------------------------------------------------
db = SqliteDb(
id="agui-reasoning-db",
db_file="tmp/agui_reasoning.db",
)
reasoning_agent = Agent(
id="agui-reasoning-agent",
name="AG-UI Reasoning Agent",
model=OpenAIResponses(id="gpt-5.6"),
db=db,
reasoning_model=OpenAIResponses(id="o3-mini"),
instructions="Solve the problem carefully, then give a concise final answer.",
)
agent_os = AgentOS(
id="agui-reasoning-os",
description="AgentOS translating Agno reasoning events to AG-UI.",
agents=[reasoning_agent],
interfaces=[AGUI(agent=reasoning_agent, prefix="/reasoning")],
)
app = agent_os.get_app()
# ---------------------------------------------------------------------------
# Run Reasoning Server
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent_os.serve(app=app)An explicit reasoning_model runs as a separate, tool-free reasoning stage before the main model response. show_full_reasoning=True displays the reasoning data Agno receives; it cannot reveal a provider's private internal trace. Some adapters use the reasoning stage's answer text when separate reasoning content is unavailable. A failed reasoning stage can still be followed by a main-model answer, so a completed run alone does not prove the reasoning stage succeeded.
OpenAI schedules o3-mini and o4-mini for shutdown on October 23, 2026. The provider lifecycle notice lists their replacements. Check the selected replacement's reasoning and service-tier support before changing the source model ID.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[agui,os]" openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as reasoning_agent.py, then run:
python reasoning_agent.pySend a request
With the server running in another terminal:
Save this complete AG-UI request as agui-input.json. Replace content with the prompt for this example. Use a fresh runId for each run; keep threadId only when continuing the same session.
{
"threadId": "example-thread-1",
"runId": "example-run-1",
"state": {},
"messages": [
{"id": "example-message-1", "role": "user", "content": "Hello"}
],
"tools": [],
"context": [],
"forwardedProps": {}
}The endpoint accepts this object, rather than a JSON string or the REST run endpoint's message form field. The response is an SSE stream whose data values are AG-UI event objects. Inspect RUN_ERROR and RUN_FINISHED events; an HTTP 200 only establishes that the stream opened.
curl --no-buffer -H "Content-Type: application/json" --data-binary @agui-input.json http://localhost:7777/reasoning/aguiFull source: cookbook/05_agent_os/16_agui/reasoning_agent.py