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 asyncio56from kern.agent import Agent7from kern.db.sqlite import AsyncSqliteDb8from kern.tools.hackernews import HackerNewsTools910# Initialize AsyncSqliteDb11db = AsyncSqliteDb(db_file="agent_storage.db")1213agent = Agent(14 db=db,15 tools=[HackerNewsTools()],16 add_history_to_context=True,17 add_datetime_to_context=True,18)1920asyncio.run(agent.aprint_response("How many people live in Canada?"))21asyncio.run(agent.aprint_response("What is their national anthem called?"))Params
| Parameter | Type | Default | Description |
|---|---|---|---|
db_engine | Optional[Engine] | - | The SQLAlchemy database engine to use. |
db_url | Optional[str] | - | The database URL to connect to. |
db_file | Optional[str] | - | The database file to connect to. |
session_table | Optional[str] | - | Name of the table to store Agent, Team and Workflow sessions. |
memory_table | Optional[str] | - | Name of the table to store user memories. |
metrics_table | Optional[str] | - | Name of the table to store metrics. |
eval_table | Optional[str] | - | Name of the table to store evaluation runs data. |
knowledge_table | Optional[str] | - | Name of the table to store knowledge documents data. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |