Persistence Overview

Understanding agent state persistence

Persist agent state to resume sessions and maintain context across runs.

python
from praisonaiagents import Agent, Session

session = Session(session_id="my-session", persistence="sqlite")
agent = Agent(name="Assistant", session=session)

agent.start("Pick up where we left off.")

The user runs the agent again; stored memory and checkpoints avoid repeating earlier steps.

Diagram

Input

Agent

Output

What Gets Persisted

  • Memory: Conversation history and context
  • Session State: Current task progress
  • Checkpoints: Intermediate results
  • Configuration: Agent settings

Quick Start

  1. Simple Usage
    python
    from praisonaiagents import Agent, Session
    
    # Create session with persistence
    session = Session(
        session_id="my-session",
        persistence="sqlite"
    )
    
    agent = Agent(
        name="Assistant",
        session=session
    )
    
    # Run agent
    agent.start("Hello!")
    
    # Later, resume the same session
    session = Session(session_id="my-session", persistence="sqlite")
    agent = Agent(name="Assistant", session=session)
    agent.start("What did we talk about?")  # Remembers previous context
  2. With Configuration
    python
    from praisonaiagents import Agent, Session
    
    session = Session(session_id="prod-session", persistence="postgresql")
    agent = Agent(name="Assistant", session=session, llm="gpt-4o-mini")
    agent.start("Continue from where we left off.")

Persistence Backends

BackendUse CaseSetup
SQLiteLocal developmentpersistence="sqlite"
PostgreSQLProductionpersistence="postgresql"
RedisHigh-performancepersistence="redis"
MongoDBDocument storagepersistence="mongodb"

CLI Session Resume

praisonai session resume <id> is a first-class restore — it brings back chat history, model, and agent name. Use a follow-up prompt to continue immediately:

bash
praisonai session resume my-session "What did we discuss?"

See Session Command for the full reference including --transcript and cross-store lookup behaviour.

Related