xAI Grok 3 Mini

Add the following code to your Python file

1from kern.agent import Agent
2from kern.models.xai import xAI
3from kern.tools.yfinance import YFinanceTools
4
5agent = Agent(
6 model=xAI(id="grok-3-mini-fast", reasoning_effort="high"),
7 tools=[
8 YFinanceTools(
9 stock_price=True,
10 analyst_recommendations=True,
11 company_info=True,
12 company_news=True,
13 )
14 ],
15 instructions="Use tables to display data.",
16 markdown=True,
17)
18agent.print_response("Write a report comparing NVDA to TSLA", stream=True)

Set up your virtual environment

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

Install dependencies

1uv pip install -U kern-ai openai

Export your xAI API key

1export XAI_API_KEY="your_xai_api_key_here"
1$Env:XAI_API_KEY="your_xai_api_key_here"

Run Agent

1python xai.py