Azure OpenAI Basic Reasoning Stream
Adapt the archived GPT-4.1 stage to a native Azure OpenAI reasoning deployment.
"""
Basic Reasoning Stream
======================
Demonstrates this reasoning cookbook example.
"""
import asyncio
from agno.agent import Agent
from agno.models.azure.openai_chat import AzureOpenAI
from agno.run.agent import RunEvent # noqa
# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
def run_example() -> None:
async def streaming_reasoning():
"""Test streaming reasoning with a Azure OpenAI model."""
# Create an agent with reasoning enabled
agent = Agent(
reasoning_model=AzureOpenAI(id="gpt-4.1"),
instructions="Think step by step about the problem.",
)
prompt = "What is 25 * 37? Show your reasoning."
await agent.aprint_response(prompt, stream=True, stream_events=True)
# Use manual event loop to see all events
# async for run_output_event in agent.arun(
# prompt,
# stream=True,
# stream_events=True,
# ):
# if run_output_event.event == RunEvent.run_started:
# print(f"\nEVENT: {run_output_event.event}")
# elif run_output_event.event == RunEvent.reasoning_started:
# print(f"\nEVENT: {run_output_event.event}")
# print("Reasoning started...\n")
# elif run_output_event.event == RunEvent.reasoning_content_delta:
# # This is the NEW streaming event for reasoning content
# print(run_output_event.reasoning_content, end="", flush=True)
# elif run_output_event.event == RunEvent.reasoning_step:
# print(f"\nEVENT: {run_output_event.event}")
# elif run_output_event.event == RunEvent.reasoning_completed:
# print(f"\n\nEVENT: {run_output_event.event}")
# elif run_output_event.event == RunEvent.run_content:
# if run_output_event.content:
# print(run_output_event.content, end="", flush=True)
# elif run_output_event.event == RunEvent.run_completed:
# print(f"\n\nEVENT: {run_output_event.event}")
if __name__ == "__main__":
asyncio.run(streaming_reasoning())
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
run_example()Select a native reasoning deployment
The archived AzureOpenAI(id="gpt-4.1") is not recognized as a native reasoning model. Agno can skip that stage and still produce a final answer. Deploy GPT-5.2 in your Azure resource, then replace the reasoning_model value with:
AzureOpenAI(id="gpt-5.2", azure_deployment="your-reasoning-deployment")Replace the deployment placeholder with the name from your resource. Keep the underlying model ID in id so Agno can recognize its reasoning capability. AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT identify the resource; they do not create the deployment.
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.
This program omits the final model, so the final answer uses Agno's default OpenAI model and still needs OPENAI_API_KEY separately from the Azure credentials.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport environment variables
export AZURE_OPENAI_API_KEY="your_azure_openai_api_key_here"
export AZURE_OPENAI_ENDPOINT="your_azure_openai_endpoint_here"
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as basic_reasoning_stream.py, then run:
python basic_reasoning_stream.pyFull source: cookbook/10_reasoning/models/azure_openai/basic_reasoning_stream.py