Reasoning Agent

Code

1from kern.agent import Agent
2from kern.models.xai import xAI
3from kern.tools.reasoning import ReasoningTools
4from kern.tools.yfinance import YFinanceTools
5
6reasoning_agent = Agent(
7 model=xAI(id="grok-3-beta"),
8 tools=[
9 ReasoningTools(add_instructions=True, add_few_shot=True),
10 YFinanceTools(
11 stock_price=True,
12 analyst_recommendations=True,
13 company_info=True,
14 company_news=True,
15 ),
16 ],
17 instructions=[
18 "Use tables to display data",
19 "Only output the report, no other text",
20 ],
21 markdown=True,
22)
23reasoning_agent.print_response(
24 "Write a report on TSLA",
25 stream=True,
26 show_full_reasoning=True,
27)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export XAI_API_KEY=xxx

Install dependencies

1uv pip install -U xai yfinance kern-ai

Run Agent

1python cookbook/11_models/xai/reasoning_agent.py