Async MySQL

Use MySQL asynchronously for agent session storage.

Kern supports using MySQL asynchronously, with the AsyncMySQLDb class.

Usage

1from kern.agent import Agent
2from kern.db.mysql import AsyncMySQLDb
3
4# Replace with your own connection string, and notice the `async_` prefix
5db_url = "mysql+aiomysql://ai:ai@localhost:3306/ai"
6
7# Setup your Database
8db = AsyncMySQLDb(db_url=db_url)
9
10# Setup your Agent with the Database
11agent = Agent(db=db)

Run MySQL

Install docker desktop and run MySQL on port 3306 using:

1docker run -d \
2 --name mysql \
3 -e MYSQL_ROOT_PASSWORD=ai \
4 -e MYSQL_DATABASE=ai \
5 -e MYSQL_USER=ai \
6 -e MYSQL_PASSWORD=ai \
7 -p 3306:3306 \
8 -d mysql:8

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_urlOptional[str]-The database URL to connect to.
db_engineOptional[AsyncEngine]-The SQLAlchemy asyncdatabase engine to use.
db_schemaOptional[str]-The database schema to use.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
memory_tableOptional[str]-Name of the table to store 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 content.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.