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
- export
- import
Python API Reference
The same surface exists on the store and as thin gateway helpers.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.SessionData.to_dict() shape, so SessionData.from_dict() reconstructs it verbatim on import.
Concurrency & no-clobber guarantee
Concurrent importers racing on the samesession_id are safe: one wins, the other is reported β never silently overwritten.
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.Best Practices
Keep reset_live_fields=True unless you know why not
Keep reset_live_fields=True unless you know why not
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.Cap ingest for untrusted payloads
Cap ingest for untrusted payloads
--max-sessions (default 10_000) bounds how many sessions land. The remainder is skipped and reported β never silently truncated.Always inspect ImportReport.skipped
Always inspect ImportReport.skipped
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.Prefer --out over stdout redirection
Prefer --out over stdout redirection
--out writes atomically via a temp file + os.replace, so a crashed export never leaves a half-written backup.Mind payload version compatibility
Mind payload version compatibility
PORTABLE_VERSION = 1. Older/unversioned payloads are accepted best-effort; a payload with a newer version is rejected wholesale rather than partially applied.Troubleshooting
import error: ... unexpected keyword argument 'overwrite'
import error: ... unexpected keyword argument 'overwrite'
Fixed in PraisonAI PR #5631. Upgrade
praisonaiagents and re-run the import; SqliteSessionStore now accepts and honours the overwrite flag end-to-end.Related
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.

