> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Reasoning Model Stream DeepSeek

> Stream reasoning events from a DeepSeek-R1 reasoning model on Azure AI Foundry.

```python reasoning_model_stream_deepseek.py theme={null}
"""
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 the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno aiohttp azure-ai-inference openai
```

**2. Export environment variables**

```bash Mac/Linux theme={null}
export AZURE_API_KEY="your_azure_api_key_here"
export AZURE_ENDPOINT="your_azure_endpoint_here"
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:AZURE_API_KEY="your_azure_api_key_here"
$Env:AZURE_ENDPOINT="your_azure_endpoint_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run the example**

Save the code above as `reasoning_model_stream_deepseek.py`, then run:

```bash theme={null}
python reasoning_model_stream_deepseek.py
```

Full source: [cookbook/10\_reasoning/models/azure\_ai\_foundry/reasoning\_model\_stream\_deepseek.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/10_reasoning/models/azure_ai_foundry/reasoning_model_stream_deepseek.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.