Agent with Storage

Code

1from kern.agent import Agent
2from kern.models.litellm import LiteLLM
3from kern.db.sqlite import SqliteDb
4from kern.tools.hackernews import HackerNewsTools
5
6# Setup the database
7db = SqliteDb(
8 db_file="tmp/data.db",
9)
10
11# Add storage to the Agent
12agent = Agent(
13 model=LiteLLM(id="gpt-5-mini"),
14 db=db,
15 tools=[HackerNewsTools()],
16 add_history_to_context=True,
17)
18
19agent.print_response("How many people live in Canada?")
20agent.print_response("What is their national anthem called?")

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 LITELLM_API_KEY=xxx

Install dependencies

1uv pip install -U litellm openai kern-ai

Run Agent

1python cookbook/11_models/litellm/db.py