Tool Use
Code
1"""Build a Web Search Agent using xAI."""23from kern.agent import Agent4from kern.models.xai import xAI5from kern.tools.hackernews import HackerNewsTools67agent = Agent(8 model=xAI(id="grok-2"),9 tools=[HackerNewsTools()],10 markdown=True,11)12agent.print_response("Whats happening in France?")Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet your API key
1export XAI_API_KEY=xxxInstall dependencies
1uv pip install -U xai kern-aiRun Agent
1python cookbook/11_models/xai/tool_use.py