Skip to main content

Module session_mgr

Module session_mgr 

Source
Expand description

§Conversation Session Manager

Manages multi-turn conversation sessions with full CRUD, context windowing, and automatic summarisation when token budgets are exceeded.

§Overview

SessionManager stores sessions in a lock-free [DashMap], assigning each a unique u64 ID. Each Session holds an ordered list of Messages with per-message token counts. Context retrieval trims the oldest non-system messages to stay within a caller-supplied token budget.

§Example

use tokio_prompt_orchestrator::session_mgr::{SessionManager, Role};

let mgr = SessionManager::default();
let id = mgr.create(Some("You are a helpful assistant.".into()));
mgr.append(id, Role::User, "Hello!".into()).unwrap();
let ctx = mgr.get_context(id, 4096).unwrap();
assert_eq!(ctx.len(), 2); // system + user

Structs§

Message
A single message within a Session.
Session
A conversation session holding an ordered sequence of Messages.
SessionManager
Concurrent, lock-free store of Sessions keyed by u64 ID.
SessionStats
Aggregate statistics across all sessions in a SessionManager.

Enums§

Role
The speaker role of a conversation message.
SessionError
Errors produced by SessionManager operations.