Agent with Storage

Code

1from kern.agent import Agent
2from kern.db.postgres import PostgresDb
3from kern.models.cerebras import Cerebras
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=Cerebras(id="llama-4-scout-17b-16e-instruct"),
12 db=db,
13 tools=[HackerNewsTools()],
14 add_history_to_context=True,
15)
16agent.print_response("How many people live in Canada?")
17agent.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 CEREBRAS_API_KEY=xxx

Install dependencies

1uv pip install -U sqlalchemy cerebras_cloud_sdk kern-ai

Start your Postgres server

Ensure your Postgres server is running and accessible at the connection string used in db_url.

Run Agent

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