Skip to main content
Wrap an existing agent so every chat is saved and can be resumed, without changing how you build the agent.

Quick Start

1

Simple Usage

2

Resume on Next Run


Which Entry Point?

Pick the style that matches how much control you need.

How It Works

Each entry point drives the same orchestrator lifecycle.

Entry Points

wrap_agent_with_persistence

Patches chat (and achat, if the agent has it) on the agent you pass in, and returns that same agent. Helpers added to the agent:

PersistentAgent

Wraps the agent without patching it. Same options and helpers as above, plus a session_id property. Other attributes pass through to the wrapped agent.
await agent.achat(...) works even if the wrapped agent has no achat β€” it runs chat in a worker thread.

create_persistent_session

A with block for logging messages by hand.
Sessions support the sync with statement only. There is no async with.

Common Patterns


Best Practices

Use MemoryConfig(db=PraisonAIDB(...)) unless you already have a PersistenceOrchestrator. Use PersistentAgent over wrap_agent_with_persistence when you’d rather not modify the agent object.
Resume only works when you reuse the same session_id. Derive it from your user or conversation ID. Omit it only for throwaway sessions.
Call end_session() when a conversation finishes, and close the agent when you’re done. See Agent Lifecycle Cleanup.
On the first chat, resumed history replaces agent.chat_history. Set auto_resume=False if the agent has history you want to keep.

Persistence Overview

Both entry points and who owns the store writes

Async DB Hooks

Sync and async store dispatch

Managed Agent Persistence

The recommended MemoryConfig(db=PraisonAIDB(...)) path

Agent Lifecycle Cleanup

Closing agents and their resources