Skip to main content
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

1

Simple Usage

Store sessions in a local SQLite file — no setup required.
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.")
2

With Configuration

Point the same session at PostgreSQL for multi-instance deployments.
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-binary
from 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 redis
from praisonaiagents import Session

session = Session(
    session_id="my-session",
    persistence="redis",
    redis_url="redis://localhost:6379/0"
)

MongoDB

pip install pymongo
from praisonaiagents import Session

session = Session(
    session_id="my-session",
    persistence="mongodb",
    mongodb_url="mongodb://localhost:27017/praisonai"
)

Best Practices

persistence="sqlite" needs no server and stores everything in a single file. Switch to a networked backend only when multiple instances share sessions.
PostgreSQL, Redis, and MongoDB accept a URL. Keep credentials in DATABASE_URL rather than hard-coding them in the Session call.
Redis suits short-lived, high-throughput sessions; PostgreSQL suits durable, queryable history; MongoDB suits flexible document state.
The session_id is the key that ties writes together. Pass the same ID on reconnect to continue the earlier conversation.

Persistence Overview

Persistence concepts

Session Resume

Resume saved sessions