For basic persistence, use
Agent(memory={"session_id": "my-session"}). See Session Persistence.Quick Start
1
Create a session and chat
2
Snapshot, fork, or revert
Multi-Worker Safety
Multiple processes can share one session directory — reads use an mtime-checked cache, so a write that changes the file on disk is visible on the next read.Object identity is not a stable API — expect either a fresh
ExtendedSessionData object or a cached one. When the file on disk is unchanged, consecutive get_extended_session() calls can return the same cached object; when it has changed, you get a fresh one. Use the returned data, not session_a is session_b. Changed in PR #4958.force_reload=True for the rare case a caller needs the old unconditional-reread behaviour:
Cache Semantics
get_extended_session() now shares the same mtime-checked cache as the internal helpers — a read hits the cache when the file is unchanged and re-reads when its mtime bumps.
invalidate_cache() only matters if your own code caches ExtendedSessionData references; the read path never needs it.
Cross-instance reads
A write from a second store instance on the same directory changes the file’s mtime, so it is seen by the first store’s next read — no manualinvalidate_cache() required.
Best Practices
Snapshot before risky edits
Snapshot before risky edits
Call
create_snapshot() before experimental branches or bulk rewrites. revert_to_snapshot() restores the parent in one step.Fork for parallel exploration
Fork for parallel exploration
Use
fork_session(..., from_message_index=N) to branch from a specific turn without losing the parent transcript.Related
Session Store
Default and hierarchical store APIs
Session Protocol
Custom Redis/Postgres backends

