Module session

Module session 

Source
Expand description

Session typestate for compile-time safety of stateful LLM session lifecycle.

Uses the typestate pattern to make invalid state transitions uncompilable. Sessions track stateful LLM connections where only deltas (new messages) are sent after the initial context, avoiding the “Groundhog Day” problem of re-sending full context every tool call.

§State Transition Diagram

Session::new() → Created ── activate() ──→ Active ── close() ──→ Closed (terminal)
                                             │
                                        record_delta() ↺
                                             │
                                        expire() ──→ Expired (terminal)

Modules§

private 🔒

Structs§

Active
Session is active and accepting deltas.
Closed
Session was closed normally (terminal).
Created
Session has been created but not yet activated.
Session
A stateful LLM session with compile-time state tracking.
SessionExpired
Session expired due to TTL (terminal).
SessionRecord
Internal data storage for a session, independent of typestate. This is what gets persisted to the database.
StoredSession
A session as stored in the database (status-agnostic).

Enums§

LoadedSession
Enum representing all possible runtime states of a session. Use this when you need to handle sessions loaded from the database.
SessionStateError
Errors when transitioning session states.
SessionStatus
Status of a stateful LLM session.

Traits§

SessionState
Marker trait for session states.