Async Tool Use

Code

1"""Run `uv pip install` to install dependencies."""
2
3import asyncio
4
5from kern.agent import Agent
6from kern.models.xai import xAI
7from kern.tools.hackernews import HackerNewsTools
8
9agent = Agent(
10 model=xAI(id="grok-2"),
11 tools=[HackerNewsTools()],
12 markdown=True,
13)
14asyncio.run(agent.aprint_response("Whats happening in France?", stream=True))

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/async_tool_use.py