Sqlite for Team

Kern supports using Sqlite as a storage backend for Teams using the SqliteDb class.

Usage

You need to provide either db_url, db_file or db_engine. The following example uses db_file.

1"""
2Run: `uv pip install openai newspaper4k lxml_html_clean kern-ai` to install the dependencies
3"""
4from typing import List
5
6from kern.agent import Agent
7from kern.db.sqlite import SqliteDb
8from kern.models.openai import OpenAIResponses
9from kern.team import Team
10from kern.tools.hackernews import HackerNewsTools
11from kern.tools.hackernews import HackerNewsTools
12from pydantic import BaseModel
13
14db = SqliteDb(db_file="tmp/data.db")
15
16class Article(BaseModel):
17 title: str
18 summary: str
19 reference_links: List[str]
20
21hn_researcher = Agent(
22 name="HackerNews Researcher",
23 model=OpenAIResponses(id="gpt-5.2"),
24 role="Gets top stories from hackernews.",
25 tools=[HackerNewsTools()],
26)
27
28web_searcher = Agent(
29 name="Web Searcher",
30 model=OpenAIResponses(id="gpt-5.2"),
31 role="Searches the web for information on a topic",
32 tools=[HackerNewsTools()],
33 add_datetime_to_context=True,
34)
35
36hn_team = Team(
37 name="HackerNews Team",
38 model=OpenAIResponses(id="gpt-5.2"),
39 members=[hn_researcher, web_searcher],
40 db=db,
41 instructions=[
42 "First, search hackernews for what the user is asking about.",
43 "Then, ask the web searcher to search for each story to get more information.",
44 "Finally, provide a thoughtful and engaging summary.",
45 ],
46 output_schema=Article,
47 markdown=True,
48 show_members_responses=True,
49)
50
51hn_team.print_response("Write an article about the top 2 stories on hackernews")

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_engineOptional[Engine]-The SQLAlchemy database engine to use.
db_urlOptional[str]-The database URL to connect to.
db_fileOptional[str]-The database file to connect to.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
memory_tableOptional[str]-Name of the table to store user memories.
metrics_tableOptional[str]-Name of the table to store metrics.
eval_tableOptional[str]-Name of the table to store evaluation runs data.
knowledge_tableOptional[str]-Name of the table to store knowledge documents data.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.