Sessions, checkpoints, and state replay
Create and restore named checkpoints with FileMemory
When an agent explores a risky multi-step plan or a user says 'undo the last change', checkpoints let you snapshot memory state and roll back cleanly without losing earlier work.
Example
import tempfile
from praisonai.memory import FileMemory
with tempfile.TemporaryDirectory() as tmp:
mem = FileMemory(user_id='dev_1', base_path=tmp)
mem.store_long_term('Decision 1: use FastAPI for API layer.')
cp_id = mem.create_checkpoint('before_experiment')
mem.store_long_term('Experimental idea: rewrite everything in assembly.')
print('Before restore:', len(mem.get_all_memories()), 'memories')
mem.restore_checkpoint(cp_id)
print('Checkpoints saved:', len(mem.list_checkpoints()))
print('After restore :', len(mem.get_all_memories()), 'memory restored')Example explained
- mem.create_checkpoint('before_experiment') — Saves a clean snapshot of current memory state before risky edits.
- mem.restore_checkpoint(cp_id) — Rewinds memory deterministically back to the checkpoint.
Use Session for multi-run persistence across script restarts
Wrap agents in Session(session_id='…', user_id='…') to resume conversations across process restarts with built-in history persistence.
Example
from praisonai import Session
sess = Session(session_id='onboarding-42', user_id='alice')
print('Session active:', sess.session_id, '| user:', sess.user_id)Example explained
- Session(session_id=…, user_id=…) — Groups multi-run conversations under stable user and session identifiers.
Common pitfall: never checkpointing before bulk memory imports
Always create a checkpoint before migrating or importing bulk user memories so a bad script can be rolled back in one line.
Reference: documentation