Purpose
Enable the agent to restore state across requests, process restarts, and multi-user scenarios. Session persistence is owned by the agent runtime itself: conversation progress is appended to a native session journal — a lossless, hash-chained sequence of structured events. The journal is never compacted or rewritten; compaction only shrinks the in-context window.- Native session journal — the complete history: messages, tool calls with full inputs/outputs, and reasoning events, stored as atomic commits
- Read-time projections —
agent.sessionTranscript(ctx)and thesession_search/session_listtools project the journal into flat views on demand; no duplicate conversation files are written
Trigger Points
Key Logic
Storage Layout
- Journal:
JournalSessionLogwrites ordered, hash-chained commits of structuredSessionEvents with full payloads, so tool inputs/outputs and reasoning content are preserved verbatim. Compaction summaries are ordinary events; earlier events are never dropped. - Backends: the default
LocalFilesystemstores journal objects under the workspace’s.agentscope-runtime/directory; a SQLite backend is used on Windows, and larger deployments can plugSessionLogStore/AtomicSessionStorageimplementations (e.g. a remote store). - Reading:
agent.sessionTranscript(ctx)projects committed events into a flatMsgview;session_search/session_listquery the same journal.
How RuntimeContext Routes the Journal
RuntimeContext decides which journal a call reads and writes:
- Key derivation:
(agentId, userId, sessionId)maps to the journal directoryagents/<agentId>/sessions/<userId>/<sessionId>/. - Isolation: different
userId/sessionIdvalues hit different journal directories; there is no shared mutable state between them. - Restore: committed events are replayed for that identity before the turn runs, so state survives restarts.
- Reading from application code:
agent.sessionTranscript(ctx)(flat view) oragent.sessionLog(ctx)(raw journal) never starts inference.
Default vs Custom Storage
Multi-User Isolation
- Journal level:
userId+sessionIddetermine the journal directory; sessions of different users live in disjoint namespaces. - File level:
userId+NamespaceFactorydetermines the file operation path prefix (the defaultLocalFilesystemWithShellreads the per-call identity).
Listing Sessions
session_list / session_search read the journal store directly — there is no separate index file to keep in sync. The store discovers sessions by scanning agents/<agentId>/sessions/ for session headers, so anything committed through the runtime is automatically visible to both tools.
Related Pages
- Tool —
session_search/session_list/session_historyparameters - Memory — how memory flush interacts with compaction and feeds
memory_search - Filesystem —
userIdRef+NamespaceFactorymulti-tenant path isolation - Session log — journal internals: backends, physical layout, custom stores and exports