Expand description
Session persistence for LLM conversation histories.
A session is an append-only log of SessionEntry records — finalized
chat Messages and non-destructive SessionEntry::Compaction markers
— identified by a SessionMeta header. Two SessionStore
implementations are provided: InMemorySessionStore (non-persistent)
and JsonlSessionStore (one JSONL file per session on disk).
build_context converts a stored entry log into the message list to
send to an LLM, honoring the most recent compaction.
§Ownership and lifetime
A SessionStore is owned by the component that creates it — typically a
single agent instance — and lives exactly as long as its owner. There is
no global registry and no static state; dropping the owner drops the
store (persisted JSONL files of course remain on disk).
§Invariants
- Only finalized messages reach the store. Callers must append only
messages with
streaming == false; partial streaming emissions and their id-based dedup/replacement stay in the caller’s memory. - The store API is append-only. No delete, update, or overwrite operations exist. Compaction is recorded as a new entry that changes how the context is built, never by rewriting history. A crash can lose at most the single in-flight entry (appends flush immediately).
Structs§
- InMemory
Session Store - Non-persistent
SessionStoreholding all sessions in memory. - Jsonl
Session Store - Persistent
SessionStorewriting one JSONL file per session. - Session
Meta - Header metadata identifying one session.
Enums§
- Session
Entry - One record in a session’s append-only log.
Traits§
- Session
Store - Append-only storage for session logs.
Functions§
- build_
context - Builds the LLM context from a session’s entry log.