Database Setup
Configure database backends for persistence
Configure different database backends for agent persistence.
from praisonaiagents import Agent, Session
session = Session(session_id="my-session", persistence="sqlite", db_path="./data/sessions.db")
agent = Agent(name="Assistant", session=session)
agent.start("Remember this preference for next time.")The user saves sessions to a database so the same person can reconnect after a restart.
Quick Start
- Simple Usage
Store sessions in a local SQLite file — no setup required.
python from praisonaiagents import Agent, Session session = Session(session_id="my-session", persistence="sqlite", db_path="./data/sessions.db") agent = Agent(name="Assistant", session=session) agent.start("Remember this preference for next time.") - With Configuration
Point the same session at PostgreSQL for multi-instance deployments.
python import os from praisonaiagents import Session session = Session( session_id="my-session", persistence="postgresql", connection_string=os.environ["DATABASE_URL"], )
How It Works
SQLite (Default)
from praisonaiagents import Session
session = Session(
session_id="my-session",
persistence="sqlite",
db_path="./data/sessions.db"
)PostgreSQL
pip install psycopg2-binaryfrom praisonaiagents import Session
session = Session(
session_id="my-session",
persistence="postgresql",
connection_string="postgresql://user:pass@localhost:5432/praisonai"
)Or via environment variable:
export DATABASE_URL="postgresql://user:pass@localhost:5432/praisonai"Redis
pip install redisfrom praisonaiagents import Session
session = Session(
session_id="my-session",
persistence="redis",
redis_url="redis://localhost:6379/0"
)MongoDB
pip install pymongofrom praisonaiagents import Session
session = Session(
session_id="my-session",
persistence="mongodb",
mongodb_url="mongodb://localhost:27017/praisonai"
)Best Practices
Start with SQLite in development
persistence="sqlite" needs no server and stores everything in a single file. Switch to a networked backend only when multiple instances share sessions.
Use a connection string for shared backends
PostgreSQL, Redis, and MongoDB accept a URL. Keep credentials in DATABASE_URL rather than hard-coding them in the Session call.
Match the backend to the access pattern
Redis suits short-lived, high-throughput sessions; PostgreSQL suits durable, queryable history; MongoDB suits flexible document state.
Reuse one session_id to resume
The session_id is the key that ties writes together. Pass the same ID on reconnect to continue the earlier conversation.