Skip to main content

Module session

Module session 

Source
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

  1. 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.
  2. 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§

InMemorySessionStore
Non-persistent SessionStore holding all sessions in memory.
JsonlSessionStore
Persistent SessionStore writing one JSONL file per session.
SessionMeta
Header metadata identifying one session.

Enums§

SessionEntry
One record in a session’s append-only log.

Traits§

SessionStore
Append-only storage for session logs.

Functions§

build_context
Builds the LLM context from a session’s entry log.