Persistence

Save and resume agent sessions

Next

Learn how to persist agent state and resume interrupted sessions.

python
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.

Diagram

Persistence

📋 State

💾 Store

✅ Resumed

Quick Start

  1. 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.")
  2. 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

Diagram
SessionAgentUserSessionAgentUserApp restartsStart workSave stateReconnectLoad stateContinue where you left off

Guides


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.