Agent with Storage

Code

1from kern.agent import Agent
2from kern.db.postgres import PostgresDb
3from kern.models.vllm import VLLM
4from kern.tools.hackernews import HackerNewsTools
5
6# Setup the database
7db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
8db = PostgresDb(db_url=db_url)
9
10agent = Agent(
11 model=VLLM(id="Qwen/Qwen2.5-7B-Instruct"),
12 db=db,
13 tools=[HackerNewsTools()],
14 add_history_to_context=True,
15)
16
17agent.print_response("How many people live in Canada?")
18agent.print_response("What is their national anthem called?")
Note

Ensure Postgres database is running.

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 sqlalchemy psycopg

Start Postgres database

1./cookbook/scripts/run_pgvector.sh

Start vLLM server

1vllm serve Qwen/Qwen2.5-7B-Instruct \
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/db.py