Session Resume

Continue conversations across sessions

Session Resume

PraisonAI automatically resumes conversations when you use the same session_id.

When SessionConfig.mirror_runtime_state=True, persisted sessions also restore runtime_state alongside messages — useful for replaying tool call IDs when handing off between native and plugin runtimes. See Session Runtime State.

How It Works

python
from praisonaiagents import Agent

# First run - agent with memory and session
agent = Agent(
    name="Bot",
    memory={
        "db": "postgresql://postgres:praison123@localhost/praisonai",
        "session_id": "session-001"
    }
)
response = agent.start("My favorite color is blue")
print(response)

# Later run (same session_id) - automatically resumes
agent2 = Agent(
    name="Bot",
    memory={
        "db": "postgresql://postgres:praison123@localhost/praisonai",
        "session_id": "session-001"
    }
)
response = agent2.start("What's my favorite color?")
# Agent remembers: "Your favorite color is blue"
print(response)

Session ID Strategies

User-Based Sessions

python
from praisonaiagents import Agent

user_id = "user123"
agent = Agent(
    name="Assistant",
    memory={
        "db": "mydata.db",
        "session_id": f"user-{user_id}-main"
    }
)

Conversation-Based Sessions

python
from praisonaiagents import Agent
import uuid

agent = Agent(
    name="Assistant",
    memory={
        "db": "conversations.db",
        "session_id": f"conv-{uuid.uuid4().hex[:8]}"
    }
)

Auto-Generated (Default)

If you don’t provide a session_id, one is auto-generated:

python
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={"db": "mydata.db"}  # session_id auto-generated
)

CLI Resume

bash
# Show history
praisonai persistence resume \
    --session-id "my-session" \
    --conversation-url "postgresql://localhost/mydb" \
    --show-history

# Continue conversation
praisonai persistence resume \
    --session-id "my-session" \
    --conversation-url "postgresql://localhost/mydb" \
    --continue "What did we discuss?"

Concurrent Writes

Multiple bot workers writing to the same session_id are safe — history saves use a single locked atomic write under the hood, so no worker sees an empty history mid-update.

This applies to:

  • Messaging bots (praisonai bot telegram, discord, slack, whatsapp)
  • Multi-process deployments resuming the same session key
  • Managed agents streaming chunks back to the user

You do not need to add a custom lock around agent.start().

Visual Replay on /continue

In interactive praisonai code, typing /continue visually replays the restored conversation through the live renderer — you see the earlier user / assistant turns and tool activity, not a one-line “Restored N messages” summary. This lands with PraisonAI PR #3965.

bash
# First run — creates a session
praisonai code

> Help me refactor auth.py

# Later, from the same directory
praisonai code
> /continue

# Interactive terminal renders:
#   … 12 earlier turns
#   [you]        Help me refactor auth.py
#   [assistant]  Here's what I'd change: …
#   (ready for your next prompt)
Diagram
Storepraisonai codeUserStorepraisonai codeUserloop[last K turns]/continueload full history for this projectN stored turns“… <N-K> earlier turns”render user + assistant + tool activitynew prompt (full context in scrollback)