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.
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.
graph LR
Agent[🤖 Agent] --> Store[💬 Conversation Store]
Store --> File[📄 SQLite File]
File --> Disk[💾 Local Disk]
classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
classDef store fill:#189AB4,stroke:#7C90A0,color:#fff
classDef disk fill:#10B981,stroke:#7C90A0,color:#fff
class Agent agent
class Store store
class File,Disk diskQuick Start
- 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") - 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
sequenceDiagram
participant Agent
participant SQLite as SQLite Store
participant File as .db File
Agent->>SQLite: save message
SQLite->>File: INSERT
Agent->>SQLite: load history
File-->>Agent: prior messages| Table | Purpose |
|---|---|
sessions | Session metadata |
messages | User and agent messages |
runs | Agent execution runs |
tool_calls | Tool usage records |
Sync vs Async
graph TB
Q1{Plain Python script<br/>or multi-agent?} -->|Sync / multi-thread| SYNC[mode="sync"]
Q1 -->|FastAPI / asyncio| ASYNC[mode="async"]
Q1 -->|Not sure| AUTO[mode="auto"<br/>legacy behaviour]
classDef sync fill:#10B981,stroke:#7C90A0,color:#fff
classDef async fill:#189AB4,stroke:#7C90A0,color:#fff
classDef auto fill:#F59E0B,stroke:#7C90A0,color:#fff
class SYNC sync
class ASYNC async
class AUTO autoConfiguration Options
| Option | Type | Default | Description | ||
|---|---|---|---|---|---|
mode | `”sync” \ | “async” \ | “auto”` | "auto" | Backend variant; invalid values raise ValueError |
path | str | "praisonai_conversations.db" | SQLite file path (sync store) | ||
table_prefix | str | "praison_" | Table name prefix (alphanumeric only) |
URL formats
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)File Path Options
from praisonaiagents import Agent
# Current directory
agent = Agent(name="Bot", memory={"db": "mydata.db"})
# Absolute path
agent = Agent(name="Bot", memory={"db": "/home/user/data/conversations.db"})
# Subdirectory
agent = Agent(name="Bot", memory={"db": "./data/conversations.db"})Environment Variables
export PRAISON_CONVERSATION_URL="mydata.db"import os
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
memory={"db": os.getenv("PRAISON_CONVERSATION_URL")}
)CLI
# Validate connection
praisonai persistence doctor --conversation-url "mydata.db"
# Run with persistence
praisonai persistence run \
--conversation-url "mydata.db" \
--session-id "local-session" \
"Hello!"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.