Agent with Tools

Code

1"""Build a Web Search Agent using xAI."""
2
3from kern.agent import Agent
4from kern.models.vllm import VLLM
5from kern.tools.hackernews import HackerNewsTools
6
7agent = Agent(
8 model=VLLM(
9 id="NousResearch/Nous-Hermes-2-Mistral-7B-DPO", top_k=20, enable_thinking=False
10 ),
11 tools=[HackerNewsTools()],
12 markdown=True,
13)
14agent.print_response("Whats happening in France?")

Usage

Set up your virtual environment

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

Install Libraries

1uv pip install -U kern-ai openai vllm

Start vLLM server

1vllm serve NousResearch/Nous-Hermes-2-Mistral-7B-DPO \
2 --enable-auto-tool-choice \
3 --tool-call-parser hermes \
4 --dtype float16 \
5 --max-model-len 8192 \
6 --gpu-memory-utilization 0.9

Run Agent

1python cookbook/11_models/vllm/tool_use.py