Async Sqlite for Agent

Kern supports using Sqlite asynchronously as a storage backend for Agents, with the AsyncSqliteDb class.

Usage

1"""
2Run `uv pip install openai sqlalchemy aiosqlite` to install dependencies.
3"""
4import asyncio
5
6from kern.agent import Agent
7from kern.db.sqlite import AsyncSqliteDb
8from kern.tools.hackernews import HackerNewsTools
9
10# Initialize AsyncSqliteDb
11db = AsyncSqliteDb(db_file="agent_storage.db")
12
13agent = Agent(
14 db=db,
15 tools=[HackerNewsTools()],
16 add_history_to_context=True,
17 add_datetime_to_context=True,
18)
19
20asyncio.run(agent.aprint_response("How many people live in Canada?"))
21asyncio.run(agent.aprint_response("What is their national anthem called?"))

Params

ParameterTypeDefaultDescription
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.