MySQLDb
Store AgentOS sessions, memory, knowledge, evals, and traces in MySQL.
MySQLDb implements the Db interface with MySQL tables for Agent, Team, and Workflow sessions, runs, memories, knowledge, metrics, evals, traces, spans, and schema versions.
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | None | Database ID. Derived from the connection and schema when omitted. |
db_engine | Optional[Engine] | None | SQLAlchemy database engine. Provide this or db_url. |
db_schema | Optional[str] | None | Database schema. Uses "ai" when omitted. |
db_url | Optional[str] | None | Database URL. Provide this or db_engine. |
session_table | Optional[str] | None | Table for Agent, Team, and Workflow sessions. Uses "agno_sessions" when omitted. |
runs_table | Optional[str] | None | Table for session runs. Uses "agno_runs" with the default session table, or <session_table>_runs when session_table is customized. |
memory_table | Optional[str] | None | Table for memories. Uses "agno_memories" when omitted. |
metrics_table | Optional[str] | None | Table for metrics. Uses "agno_metrics" when omitted. |
eval_table | Optional[str] | None | Table for evaluation run data. Uses "agno_eval_runs" when omitted. |
knowledge_table | Optional[str] | None | Table for knowledge content. Uses "agno_knowledge" when omitted. |
traces_table | Optional[str] | None | Table for traces. Uses "agno_traces" when omitted. |
spans_table | Optional[str] | None | Table for spans. Uses "agno_spans" when omitted. |
versions_table | Optional[str] | None | Table for schema versions. Uses "agno_schema_versions" when omitted. |
create_schema | bool | True | Create the database schema when it does not exist. Set to False when migrations manage it. |
Methods
upsert_sessions
Upsert multiple sessions in one method call.
Parameters:
sessions(List[Session]): List of sessions to upsertdeserialize(Optional[bool]): Whether to deserialize the sessions. Defaults toTruepreserve_updated_at(bool): Request preservation of the sessions' existingupdated_attimestamps; see adapter limitations below. Defaults toFalse
Returns: List[Union[Session, Dict[str, Any]]]
upsert_memories
Upsert multiple memories in one method call.
Parameters:
memories(List[UserMemory]): List of memories to upsertdeserialize(Optional[bool]): Whether to deserialize the memories. Defaults toTruepreserve_updated_at(bool): Request preservation of the memories' existingupdated_attimestamps; see adapter limitations below. Defaults toFalse
Returns: List[Union[UserMemory, Dict[str, Any]]]
Timestamp preservation by adapter
JsonDb, GcsJsonDb, FirestoreDb, RedisDb, DynamoDb, and InMemoryDb accept preserve_updated_at but do not forward it to their individual upserts. Their bulk methods replace timestamps even when it is True.
PostgresDb, SingleStoreDb, and ValkeyDb honor the flag. MySQLDb, SqliteDb, and MongoDb honor it on their optimized bulk path; their per-record fallback paths do not forward it. Verify timestamps when a migration depends on preserving them.