Agent Storage

Store sessions, memory, knowledge, traces in any database backend.

Agents can persist every data point they generate and use in a database, set by the db param. We can store sessions, memory, knowledge, traces, schedules, approvals, learnings and even usage metrics.

The primitives (agents, teams, workflows) and the AgentOS accept a db param. Pick from JSON files (local or cloud), embedded (SQLite), relational (Postgres, MySQL), document (MongoDB), key-value (Redis, DynamoDB, Firestore), or distributed (SingleStore).

1from kern.db.postgres import PostgresDb
2from kern.os import AgentOS
3
4db = PostgresDb(db_url="postgresql://user:pass@host:5432/kern")
5
6agent_os = AgentOS(agents=[agent], db=db)

When we set the db param, AgentOS creates the tables and indexes on first boot.

What gets stored

TableHolds
agno_sessionsConversation history per (user_id, session_id)
agno_memoriesUser memories the agent decides to keep
agno_knowledgeEmbeddings
agno_traces, agno_spansOpenTelemetry traces
agno_approvalsPending and resolved HITL requests
agno_schedules, agno_schedule_runsCron jobs
agno_metrics, agno_eval_runsMetrics and eval results
  • Backend-specific names may vary.
  • Schema changes are generally additive.

Pick a backend

PostgresDb is the default for most tutorials and the recommended production database. It pairs well with PgVector to keep relational data and embeddings on the same engine.

BackendWhen to use
PostgresDbProduction. Vector + relational on one box.
SqliteDbLocal dev, single-user demos, edge deployments
MongoDbAlready on Mongo
MySQLDbAlready on MySQL
SingleStoreDbVector + analytics on one engine, high-throughput
RedisDbCache-friendly, ephemeral sessions
DynamoDbAWS-native, serverless
FirestoreDbGCP-native, serverless
GCSJsonDbCheap cold storage, knowledge as JSON in Cloud Storage
InMemoryDbTests, ephemeral demos

Postgres-compatible managed services like Neon and Supabase work with PostgresDb directly. Point db_url at the managed instance. Async variants (AsyncPostgresDb, AsyncSqliteDb, AsyncMongoDb, AsyncMySQLDb) are documented under Database.

Vector storage

Knowledge needs a vector store and kern supports every vector database out of the box.

1from kern.knowledge import Knowledge
2from kern.vectordb.pgvector import PgVector
3
4agent = Agent(
5 db=db,
6 knowledge=Knowledge(
7 vector_db=PgVector(
8 table_name="my_kb",
9 db_url=DB_URL,
10 search_type="hybrid", # vector + BM25
11 ),
12 ),
13)

Other options: LanceDB, Qdrant, Weaviate, Pinecone, Chroma, MongoDB Atlas, Cosmos, Cassandra, ClickHouse, SurrealDB, Milvus. See Vector Stores.

For most production AgentOS deployments, PgVector + PostgresDb on the same Postgres is the right default. One database, hybrid search, transactional reads, no extra service to operate.

Splitting concerns across databases

Every agent, team, and workflow can take its own db, overriding the AgentOS default.

Use the AgentOS db for shared state and hand individual components a separate database when they need isolation:

1shared_db = PostgresDb(db_url="postgresql://shared/...")
2tenant_db = PostgresDb(db_url="postgresql://tenant-a/...")
3
4tenant_agent = Agent(name="tenant-a-support", db=tenant_db, ...)
5internal_agent = Agent(name="ops", db=shared_db, ...)
6
7agent_os = AgentOS(
8 agents=[tenant_agent, internal_agent],
9 db=shared_db,
10)

Common splits: per-tenant DBs for strict isolation, a high-traffic agent on its own engine, or routing one workflow's session history to a cheaper backend.

File and blob storage

For media that doesn't belong in the relational store (generated images, audio, large PDFs), store them in object storage and reference paths in agno_knowledge or agno_sessions.