Live Search Agent

Code

1from kern.agent import Agent
2from kern.models.xai.xai import xAI
3
4agent = Agent(
5 model=xAI(
6 id="grok-3",
7 search_parameters={
8 "mode": "on",
9 "max_search_results": 20,
10 "return_citations": True,
11 },
12 ),
13 markdown=True,
14)
15agent.print_response("Provide me a digest of world news in the last 24 hours.")

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 kern-ai

Run Agent

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