> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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](/docs/features/session-runtime-state).

<Note>
  **Tool calls are preserved on resume.** The default (zero-config) JSON session store persists assistant tool-call turns and `role="tool"` result turns as of PraisonAI PR [#3099](https://github.com/MervinPraison/PraisonAI/pull/3099). Resuming with the same `session_id` (or via `praisonai run --continue` / `--session <id>` / `session resume <id>`) reconstructs the exact message list the model saw before — including tool calls. Old text-only session files stay compatible; the new `tool_calls` / `tool_call_id` fields are only written when a message actually has them.
</Note>

<Note>
  **Resume works for team runs launched from a YAML file too.** `praisonai run agents.yaml --continue` / `--session <id>` restores per-agent chat history and shared team state, so each agent replays its earlier context before the new prompt. See [YAML / Team Session Continuity](/docs/features/yaml-session-continuity).
</Note>

<Note>
  **The model is preserved across resumes.** With no explicit `--model`, resume runs on the model the session was recorded with — not your current default. See [Session Resume — Model Restoration](/docs/cli/session-resume#model-restoration).
</Note>

<Note>
  **Interactive resume redraws your conversation on screen.** In `praisonai code`, `/continue` and `session resume` replay the last 20 turns through the same renderer live turns use — including tool-call surfaces — so scrollback shows what was actually said. See [Session Visual Replay](/docs/features/session-visual-replay).
</Note>

## How It Works

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

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

## CLI Resume

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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](https://github.com/MervinPraison/PraisonAI/pull/3965).

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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)
```

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant CLI as praisonai code
    participant Store

    User->>CLI: /continue
    CLI->>Store: load full history for this project
    Store-->>CLI: N stored turns
    CLI-->>User: "… <N-K> earlier turns"
    loop last K turns
        CLI-->>User: render user + assistant + tool activity
    end
    User->>CLI: new prompt (full context in scrollback)
```

<Note>
  Replay is **bounded to the last N turns** — older content is summarised as `… <N> earlier turns` so a long history doesn't flood the terminal. `/continue` loads the full stored history (not a 50-message tail), so the "earlier turns" count reflects the true total.
</Note>

<Note>
  `/continue` clears the on-screen message list before replay, so **repeated `/continue` calls no longer duplicate or retain stale turns**. The default `_run_simple` fallback (no `prompt_toolkit`) also renders restored user + assistant turns, not just system lines.
</Note>

## Best Practices

1. **Consistent session\_ids** - Same ID = same conversation thread
2. **User isolation** - Include user\_id in session\_id for multi-user apps
3. **Persistent storage** - Use PostgreSQL for production, SQLite for development
