Sqlite for Agent
Kern supports using Sqlite as a storage backend for Agents using the SqliteDb class.
Usage
You need to provide either db_url, db_file or db_engine. The following example uses db_file.
1from kern.agent import Agent2from kern.db.sqlite import SqliteDb3from kern.tools.hackernews import HackerNewsTools45# Setup the SQLite database6db = SqliteDb(db_file="tmp/data.db")78# Setup a basic agent with the SQLite database9agent = Agent(10 db=db,11 tools=[HackerNewsTools()],12 add_history_to_context=True,13 add_datetime_to_context=True,14)1516# The Agent sessions and runs will now be stored in SQLite17agent.print_response("How many people live in Canada?")18agent.print_response("What is their national anthem?")19agent.print_response("List my messages one by one")Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
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. |