Reasoning Model Stream DeepSeek

Historical Foundry DeepSeek-R1 recipe with a current Azure OpenAI reasoning alternative.

reasoning_model_stream_deepseek.py
"""
Reasoning Model Stream Deepseek
===============================

Demonstrates this reasoning cookbook example.
"""

import asyncio
import os

from agno.agent import Agent
from agno.models.azure import AzureAIFoundry
from agno.run.agent import RunEvent  # noqa


# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
def run_example() -> None:
    async def streaming_reasoning():
        """Test streaming reasoning with a Azure AI Foundry DeepSeek model."""
        # Create an agent with reasoning enabled
        agent = Agent(
            reasoning_model=AzureAIFoundry(
                id="DeepSeek-R1",
                azure_endpoint=os.getenv("AZURE_ENDPOINT"),
                api_key=os.getenv("AZURE_API_KEY"),
            ),
            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()

Run a current alternative

The archived program uses DeepSeek-R1 on Foundry, which Microsoft retired on August 13, 2026. Its azure-ai-inference SDK was retired on August 26, 2026. A new integration needs a current model and adapter.

This alternative uses two Azure OpenAI deployments and Agno's native reasoning support. Deploy GPT-5.2 for reasoning and GPT-5.6 Luna for the final answer in the same resource, using Azure deployment setup. Save this as azure_reasoning.py and replace the two deployment-name placeholders:

azure_reasoning.py
import asyncio

from agno.agent import Agent
from agno.models.azure.openai_chat import AzureOpenAI


async def main() -> None:
    agent = Agent(
        model=AzureOpenAI(
            id="gpt-5.6-luna",
            azure_deployment="your-answer-deployment",
        ),
        reasoning_model=AzureOpenAI(
            id="gpt-5.2",
            azure_deployment="your-reasoning-deployment",
        ),
    )
    await agent.aprint_response(
        "What is 25 * 37? Explain your answer.",
        stream=True,
        stream_events=True,
        show_full_reasoning=True,
    )


if __name__ == "__main__":
    asyncio.run(main())

Install uv pip install "agno[openai]" in an activated Python environment, then configure the Azure resource:

export AZURE_OPENAI_API_KEY="your_resource_key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"

Run python azure_reasoning.py. Both model calls now use Azure; no native OpenAI API key is needed for this replacement. The underlying id identifies the model for Agno's reasoning detector, while azure_deployment selects your resource's deployment. This is a different provider/model composition from the preserved DeepSeek example.

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.

Full source: cookbook/10_reasoning/models/azure_ai_foundry/reasoning_model_stream_deepseek.py