Skip to main content
Database persistence keeps conversation history and state across restarts — pick a backend for your scale.
from praisonaiagents import Agent, db

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    db=db(database_url="sqlite:///conversations.db"),
    session_id="my-session",
)
agent.start("Hello — saved automatically")
The user returns later; the configured backend restores conversation history and agent state.

Quick Start

1

Simple Usage

from praisonaiagents import Agent, db

agent = Agent(
    name="Assistant",
    db=db(database_url="sqlite:///conversations.db"),
    session_id="session-1",
)
agent.start("Hello!")
2

With Configuration

Hybrid setup — SQL for conversations, Redis for state:
import os
from praisonaiagents import Agent, db

agent = Agent(
    name="Assistant",
    db=db(
        database_url=os.getenv("PRAISON_CONVERSATION_URL", "sqlite:///conversations.db"),
        state_url=os.getenv("PRAISON_STATE_URL", "redis://localhost:6379"),
    ),
    session_id="hybrid-session",
)
agent.start("Conversations in SQL, state in Redis")

How It Works

ComponentPurposeExample backends
ConversationStoreMessages, sessions, metadataSQLite, PostgreSQL, MySQL
StateStoreApplication state, key-value dataRedis, MongoDB
DefaultSessionStoreFile-based sessionsJSON files on disk

Storage Backend Options

The registry supports 12 conversation, 9 state, and 20 knowledge backends — configure each store by URL scheme.
BackendAliasesBest for
sqliteLocal development, single instance
sync_sqlitesqlite_syncSynchronous file access
async_sqliteaiosqlite, sqlite_asyncAsync file access
postgresneon, cockroachdb, crdb, cockroach, xataProduction SQL
async_postgresasyncpg, postgres_asyncAsync Postgres
mysqlExisting MySQL infrastructure
async_mysqlaiomysql, mysql_asyncAsync MySQL
tursolibsqlServerless SQLite over the network
supabaseManaged Postgres platform
singlestoreDistributed SQL
surrealdbMulti-model database
jsonZero-dependency file storage
Dedicated guides exist for the most common backends:

SQLite

Local file database for development and single-instance apps

PostgreSQL

Production SQL with JSONB and connection pooling

MySQL

Popular SQL database with broad tooling support

Redis

Fast in-memory state store

MongoDB

Flexible document store for complex state

ClickHouse

Analytics database for large-scale data

JSON Files

Simple file-based storage with cross-platform locking
The registry is the authoritative list, not the docs. Call list_available_backends() at runtime to discover the current set:
from praisonai.persistence.config import list_available_backends

print(list_available_backends())
# {"conversation": [...], "state": [...], "knowledge": [...]}

Backend Aliases

Configure with either name — the registry resolves aliases before instantiating the factory (PraisonAI PR #2669).
AliasResolves toStore
neon, xata, cockroachdb, crdb, cockroachpostgresConversation
asyncpg, postgres_asyncasync_postgresConversation
aiomysql, mysql_asyncasync_mysqlConversation
sqlite_syncsync_sqliteConversation
aiosqlite, sqlite_asyncasync_sqliteConversation
libsqltursoConversation
motor, mongodb_asyncasync_mongodbState
mongodb_atlas, mongo_vectormongodb_vectorKnowledge
chromadbchromaKnowledge
cosmos, azure_cosmos, cosmosdb_vectorcosmosdbKnowledge
llama_index, llamaindex_adapterllamaindexKnowledge
langchain_adapterlangchainKnowledge
PersistenceConfig(state_store="motor").validate() now succeeds and resolves to AsyncMongoDBStateStore. Unknown names still fail loudly, listing the current registry backends.

Configuration Options

ParameterDescription
database_urlConversation store URL
state_urlState / run history store
knowledge_urlVector or knowledge store
import os
from praisonaiagents import Agent, MemoryConfig, db

agent = Agent(
    name="Researcher",
    memory=MemoryConfig(
        db=db(
            database_url=os.getenv("PRAISON_CONVERSATION_URL"),
            state_url=os.getenv("PRAISON_STATE_URL"),
        ),
        session_id="research-42",
    ),
)
agent.start("Continue our research thread")
Database backends require the praisonai wrapper (pip install praisonai). The core SDK defines DbAdapter; implementations live in praisonai.persistence.

Best Practices

SQLite for development; PostgreSQL or MySQL for multi-user production; Redis for fast state; JSON files for minimal dependencies.
Set session_id="user-123" so conversations resume reliably across restarts.
Never hardcode database URLs — use os.getenv("PRAISON_CONVERSATION_URL").
Conversation history, run traces, and vectors scale differently — configure each URL independently.

Database Persistence (Advanced)

MemoryConfig, CLI commands, and Docker setup

Session Persistence

JSON file sessions without a database