SQLite Persistence

Local file database persistence for development and single-instance applications

SQLite saves agent conversations to a local .db file — no external database required.

python
from praisonaiagents import Agent, MemoryConfig
from praisonaiagents import db

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    memory=MemoryConfig(
        db=db(database_url="sqlite:///conversations.db"),
        session_id="dev-session",
    ))
agent.start("Hello — saved to SQLite")

The user develops locally; SQLite writes conversations to a single file on disk.

Diagram

🤖 Agent

💬 Conversation Store

📄 SQLite File

💾 Local Disk

Quick Start

  1. Simple Usage
    python
    from praisonaiagents import Agent, MemoryConfig
    from praisonaiagents import db
    
    agent = Agent(
        name="Assistant",
        memory=MemoryConfig(
            db=db(database_url="sqlite:///conversations.db"),
            session_id="session-1",
        ))
    agent.start("Remember my favourite colour is blue")
  2. With Configuration

    Choose sync or async when using the factory directly:

    python
    from praisonai.persistence.factory import create_conversation_store
    
    # Sync — scripts and multi-threaded agents
    store = create_conversation_store(
        "sqlite",
        path="./conversations.db",
        mode="sync",
    )
    
    # Async — FastAPI / asyncio apps
    store = create_conversation_store(
        "sqlite",
        path="./conversations.db",
        mode="async",
    )

How It Works

Diagram
.db FileSQLite StoreAgent.db FileSQLite StoreAgentsave messageINSERTload historyprior messages
TablePurpose
sessionsSession metadata
messagesUser and agent messages
runsAgent execution runs
tool_callsTool usage records

Sync vs Async

Diagram

Sync / multi-thread

FastAPI / asyncio

Not sure

Plain Python script
or multi-agent?

mode=’sync’

mode=’async’

mode=’auto’
legacy behaviour


Configuration Options

OptionTypeDefaultDescription
mode`”sync” \“async” \“auto”`"auto"Backend variant; invalid values raise ValueError
pathstr"praisonai_conversations.db"SQLite file path (sync store)
table_prefixstr"praison_"Table name prefix (alphanumeric only)

URL formats

python
db(database_url="sqlite:///conversations.db")          # relative path
db(database_url="sqlite:////absolute/path/to/db.db") # absolute path
db(database_url="sqlite:///:memory:")                # in-memory (temporary)

Best Practices

Use sync mode for multi-agent scripts

The sync_sqlite backend (mode="sync") uses per-call connection locking for multi-threaded agents.

Use absolute paths in production

Set the database path via environment variables and use absolute paths for deployments.

WAL is applied automatically

Every core SQLite store applies WAL through the hardened sqlite_connect factory, with a safe DELETE fallback on network and container filesystems — you no longer run PRAGMA journal_mode=WAL yourself.

Migrate to PostgreSQL at scale

SQLite handles thousands of conversations; move to PostgreSQL for multi-instance deployments.


Related