On this page
Persistence
Save and resume agent sessions
Learn how to persist agent state and resume interrupted sessions.
from praisonaiagents import Agent, Session
session = Session(session_id="demo", persistence="sqlite")
agent = Agent(name="Assistant", session=session)
agent.start("Continue our conversation.")The user opens a persistence guide, wires a session store, then resumes work without losing context.
graph LR
subgraph "Persistence"
U[๐ State] --> A[๐พ Store]
A --> O[โ
Resumed]
end
classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
classDef output fill:#10B981,stroke:#7C90A0,color:#fff
class U input
class A process
class O outputQuick Start#
- Simple Usage
Attach a session to the agent so its state survives a restart.
python from praisonaiagents import Agent, Session session = Session(session_id="demo", persistence="sqlite") agent = Agent(name="Assistant", session=session) agent.start("Continue our conversation.") - With Configuration
Reopen the same session ID later to pick up exactly where you left off.
python from praisonaiagents import Agent, Session session = Session(session_id="demo", persistence="sqlite") agent = Agent(name="Assistant", session=session) agent.resume()
How It Works#
sequenceDiagram
participant User
participant Agent
participant Session
User->>Agent: Start work
Agent->>Session: Save state
Note over Session: App restarts
User->>Agent: Reconnect
Agent->>Session: Load state
Agent-->>User: Continue where you left offGuides#
Persistence concepts
Database SetupConfigure database backends
Session ResumeResume interrupted sessions
Best Practices#
Choose a backend before you scale
SQLite is perfect for a single process; move to PostgreSQL or Redis once several instances need to share the same sessions.
Treat session_id as the resume key
The same session_id reconnects to the same history. Generate it per user or per task, and store it where you can look it up later.
Checkpoint long-running work
Set checkpoint_interval so a crash mid-task resumes from the last checkpoint instead of the beginning.