xAI Reasoning Agent
Use ReasoningTools and explicit financial data tools with Grok 4.3 for a stock report.
Use ReasoningTools and YFinance with an explicit Grok 4.3 model to produce a TSLA report.
The preserved source uses grok-3-beta. Select the explicit Grok 4.3 ID using the run step below.
ReasoningTools exposes model-selected think and analyze calls. Displaying their results does not guarantee access to a model's private native reasoning.
"""
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__":
passRun the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openai yfinanceExport your xAI API key
export XAI_API_KEY="your_xai_api_key_here"Use the explicit Grok model
Replace xAI(id="grok-3-beta") with xAI(id="grok-4.3") in the saved file.
Enable the financial data tools
Replace YFinanceTools() with YFinanceTools(enable_company_info=True, enable_stock_fundamentals=True, enable_analyst_recommendations=True, enable_company_news=True) in the saved file. The default toolkit enables only the current-price tool; these flags supply the additional data requested by the report.
Run the example
Save the code above as reasoning_agent.py, then run:
python reasoning_agent.pyFull source: cookbook/90_models/xai/reasoning_agent.py