Skip to main content
Export gateway conversations to a portable JSON file so you can back them up, move them between hosts, or restore them after disaster.

Quick Start

1

Back up and restore from the CLI

Export every session to one file, then restore it on any host.
2

Do it from Python

The gateway helpers wrap the same store the gateway runs on.

How It Works

Export reads live sessions into a versioned payload; import writes them back and resets live routing fields so restored state stays inert until the gateway re-binds it.

Choosing the right options

Pick a scope, decide on lineage, and choose whether to overwrite.

CLI Reference


Python API Reference

The same surface exists on the store and as thin gateway helpers.
Gateway helpers target the store the gateway actually runs on:
DefaultSessionStore and SqliteSessionStore both implement PortableSessionStoreProtocol.
Not to be confused with PraisonAIDB.export_session / aexport_session / import_session / aimport_session. Those live on the DB adapter (conversation-store layer, one session at a time) β€” see Async Conversation Store. The methods on this page are the store-level portability API (include_lineage= / reset_live_fields= / export_all), a different surface for whole-store backup and migration.
ImportReport is JSON-serialisable via as_dict():

Payload format

The envelope is versioned and symmetric across the built-in stores.
Each session dict is the SessionData.to_dict() shape, so SessionData.from_dict() reconstructs it verbatim on import.

Concurrency & no-clobber guarantee

Concurrent importers racing on the same session_id are safe: one wins, the other is reported β€” never silently overwritten.
Both DefaultSessionStore and SqliteSessionStore enforce this guarantee identically. overwrite=False is checked twice. The import loop first scans with session_exists, then _save_imported_session rechecks os.path.exists inside the per-file write lock β€” so a peer that creates the same session between the two checks still cannot be clobbered. The loser lands in ImportReport.skipped as {"session_id": "shared", "reason": "already exists (use overwrite)"}. As of PraisonAI PR #5631, SqliteSessionStore honours overwrite end-to-end, so this protection holds identically whether the destination is JSON-on-disk or the SQLite-indexed store.

Common Patterns

Daily backup β€” schedule a cron job that writes one dated file per day.
Staging β†’ production migration β€” export from staging, then overwrite only the ids being cut over.
Move one user’s conversation between hosts β€” export a single lineage-aware session, plain-import on the new host.
Restore after disaster β€” import a backup; live fields reset by default, so sessions stay inert until the gateway re-binds them.

Best Practices

Resetting clears gateway_session_id and agent_id (top-level and inside metadata) so a restored session cannot masquerade as an active connection. Only opt out with --keep-live-fields when re-importing onto the exact same live gateway.
--max-sessions (default 10_000) bounds how many sessions land. The remainder is skipped and reported β€” never silently truncated.
A skipped record β€” already-exists, malformed, or over the cap β€” is listed with a reason, never dropped in silence. Read skipped before assuming a clean restore.
--out writes atomically via a temp file + os.replace, so a crashed export never leaves a half-written backup.
PORTABLE_VERSION = 1. Older/unversioned payloads are accepted best-effort; a payload with a newer version is rejected wholesale rather than partially applied.

Troubleshooting

Fixed in PraisonAI PR #5631. Upgrade praisonaiagents and re-run the import; SqliteSessionStore now accepts and honours the overwrite flag end-to-end.

Session Persistence

Durability across restarts on the same host.

Session Continuity

Survive disconnects without losing in-flight state.

Session Store

Where and how gateway sessions are stored.

Session Protocol

The pluggable store contract, including portability.