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

# Reasoning Stream

> Stream reasoning events from o3-mini on a history essay with stream_events enabled.

```python reasoning_stream.py theme={null}
"""
Reasoning Stream
================

Demonstrates this reasoning cookbook example.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.run.agent import RunEvent  # noqa


# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
def run_example() -> None:
    # Create an agent with reasoning enabled
    agent = Agent(
        reasoning_model=OpenAIResponses(
            id="o3-mini",
            reasoning_effort="low",
        ),
        reasoning=True,
        instructions="Think step by step about the problem.",
    )

    prompt = "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."

    agent.print_response(prompt, stream=True, stream_events=True)

    # Use manual event loop to see all events
    # for run_output_event in agent.run(
    #     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}")


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    run_example()
```

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `reasoning_stream.py`, then run:

    ```bash theme={null}
    python reasoning_stream.py
    ```
  </Step>
</Steps>

Full source: [cookbook/10\_reasoning/models/openai/reasoning\_stream.py](https://github.com/agno-agi/agno/blob/v2.7.4/cookbook/10_reasoning/models/openai/reasoning_stream.py)
