> ## 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.

# xAI Reasoning Agent

> Combine ReasoningTools and YFinance on Grok 4.3 to write a stock report with visible reasoning.

Use ReasoningTools and YFinance with an explicit Grok 4.3 model to produce a TSLA report.

<Warning>
  xAI now resolves the pinned `grok-3-beta` alias to `grok-4.3`, so its pricing and behavior follow Grok 4.3 rather than the original beta. Use the explicit current model ID before running. See [Grok 4.3](https://docs.x.ai/developers/models/grok-4.3).
</Warning>

```python reasoning_agent.py theme={null}
"""
Xai Reasoning Agent
===================

Cookbook example for `xai/reasoning_agent.py`.
"""

from agno.agent import Agent
from agno.models.xai import xAI
from agno.tools.reasoning import ReasoningTools
from agno.tools.yfinance import YFinanceTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

reasoning_agent = Agent(
    model=xAI(id="grok-3-beta"),
    tools=[
        ReasoningTools(add_instructions=True, add_few_shot=True),
        YFinanceTools(),
    ],
    instructions=[
        "Use tables to display data",
        "Only output the report, no other text",
    ],
    markdown=True,
)
reasoning_agent.print_response(
    "Write a report on TSLA",
    stream=True,
    show_full_reasoning=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass
```

## Run the Example

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

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

  <Step title="Export your xAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export XAI_API_KEY="your_xai_api_key_here"
      ```

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

  <Step title="Use the explicit Grok model">
    Replace `xAI(id="grok-3-beta")` with `xAI(id="grok-4.3")` in the saved file.
  </Step>

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

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

Full source: [cookbook/90\_models/xai/reasoning\_agent.py](https://github.com/agno-agi/agno/blob/v2.7.4/cookbook/90_models/xai/reasoning_agent.py)
