Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager { /* private fields */ }
Expand description

Session manager handles multiple concurrent sessions

Implementations§

Source§

impl SessionManager

Source

pub fn new( llm_client: Option<Arc<dyn LlmClient>>, tool_executor: Arc<ToolExecutor>, ) -> Self

Create a new session manager without persistence

Source

pub async fn with_persistence<P: AsRef<Path>>( llm_client: Option<Arc<dyn LlmClient>>, tool_executor: Arc<ToolExecutor>, sessions_dir: P, ) -> Result<Self>

Create a session manager with file-based persistence

Sessions will be automatically saved to disk and restored on startup.

Source

pub fn with_store( llm_client: Option<Arc<dyn LlmClient>>, tool_executor: Arc<ToolExecutor>, store: Arc<dyn SessionStore>, backend: StorageBackend, ) -> Self

Create a session manager with a custom store

The backend parameter determines which StorageBackend key the store is registered under. Sessions created with a matching storage_type will use this store.

Source

pub async fn restore_session_by_id(&self, session_id: &str) -> Result<()>

Restore a single session by ID from the store

Searches all registered stores for the given session ID and restores it into the in-memory session map. Returns an error if not found.

Source

pub async fn load_all_sessions(&mut self) -> Result<usize>

Load all sessions from all registered stores

Source

pub async fn create_session( &self, id: String, config: SessionConfig, ) -> Result<String>

Create a new session

Source

pub async fn destroy_session(&self, id: &str) -> Result<()>

Destroy a session

Source

pub async fn get_session(&self, id: &str) -> Result<Arc<RwLock<Session>>>

Get a session by ID

Source

pub async fn create_child_session( &self, parent_id: &str, child_id: String, config: SessionConfig, ) -> Result<String>

Create a child session for a subagent

Child sessions inherit the parent’s LLM client but have their own permission policy and configuration.

Source

pub async fn get_child_sessions(&self, parent_id: &str) -> Vec<String>

Get all child sessions for a parent session

Source

pub async fn is_child_session(&self, session_id: &str) -> Result<bool>

Check if a session is a child session

Source

pub async fn generate( &self, session_id: &str, prompt: &str, ) -> Result<AgentResult>

Generate response for a prompt

Source

pub async fn generate_streaming( &self, session_id: &str, prompt: &str, ) -> Result<(Receiver<AgentEvent>, JoinHandle<Result<AgentResult>>)>

Generate response with streaming events

Source

pub async fn context_usage(&self, session_id: &str) -> Result<ContextUsage>

Get context usage for a session

Source

pub async fn history(&self, session_id: &str) -> Result<Vec<Message>>

Get conversation history for a session

Source

pub async fn clear(&self, session_id: &str) -> Result<()>

Clear session history

Source

pub async fn compact(&self, session_id: &str) -> Result<()>

Compact session context

Source

pub async fn maybe_auto_compact(&self, session_id: &str) -> Result<bool>

Check if auto-compaction should be triggered and perform it if needed.

Called after generate() / generate_streaming() updates session usage. Triggers compaction when:

  • auto_compact is enabled in session config
  • context_usage.percent exceeds auto_compact_threshold
Source

pub async fn get_llm_for_session( &self, session_id: &str, ) -> Result<Option<Arc<dyn LlmClient>>>

Resolve the LLM client for a session (session-level -> default fallback)

Returns None if no LLM client is configured at either level.

Source

pub async fn configure( &self, session_id: &str, thinking: Option<bool>, budget: Option<usize>, model_config: Option<LlmConfig>, ) -> Result<()>

Configure session

Source

pub async fn session_count(&self) -> usize

Get session count

Source

pub async fn store_health(&self) -> Vec<(String, Result<()>)>

Check health of all registered stores

Source

pub fn list_tools(&self) -> Vec<ToolDefinition>

List all loaded tools (built-in tools)

Source

pub async fn pause_session(&self, session_id: &str) -> Result<bool>

Pause a session

Source

pub async fn resume_session(&self, session_id: &str) -> Result<bool>

Resume a session

Source

pub async fn cancel_operation(&self, session_id: &str) -> Result<bool>

Cancel an ongoing operation for a session

Returns true if an operation was cancelled, false if no operation was running.

Source

pub async fn get_all_sessions(&self) -> Vec<Arc<RwLock<Session>>>

Get all sessions (returns session locks for iteration)

Source

pub fn tool_executor(&self) -> &Arc<ToolExecutor>

Get tool executor reference

Source

pub async fn confirm_tool( &self, session_id: &str, tool_id: &str, approved: bool, reason: Option<String>, ) -> Result<bool>

Confirm a tool execution (HITL)

Source

pub async fn set_confirmation_policy( &self, session_id: &str, policy: ConfirmationPolicy, ) -> Result<ConfirmationPolicy>

Set confirmation policy for a session (HITL)

Source

pub async fn get_confirmation_policy( &self, session_id: &str, ) -> Result<ConfirmationPolicy>

Get confirmation policy for a session (HITL)

Source

pub async fn set_permission_policy( &self, session_id: &str, policy: PermissionPolicy, ) -> Result<PermissionPolicy>

Set permission policy for a session

Source

pub async fn get_permission_policy( &self, session_id: &str, ) -> Result<PermissionPolicy>

Get permission policy for a session

Source

pub async fn check_permission( &self, session_id: &str, tool_name: &str, args: &Value, ) -> Result<PermissionDecision>

Check permission for a tool invocation

Source

pub async fn add_permission_rule( &self, session_id: &str, rule_type: &str, rule: &str, ) -> Result<()>

Add a permission rule

Source

pub async fn add_context_provider( &self, session_id: &str, provider: Arc<dyn ContextProvider>, ) -> Result<()>

Add a context provider to a session

Source

pub async fn remove_context_provider( &self, session_id: &str, name: &str, ) -> Result<bool>

Remove a context provider from a session by name

Source

pub async fn list_context_providers( &self, session_id: &str, ) -> Result<Vec<String>>

List context provider names for a session

Source

pub async fn set_lane_handler( &self, session_id: &str, lane: SessionLane, config: LaneHandlerConfig, ) -> Result<()>

Set lane handler configuration

Source

pub async fn get_lane_handler( &self, session_id: &str, lane: SessionLane, ) -> Result<LaneHandlerConfig>

Get lane handler configuration

Source

pub async fn complete_external_task( &self, session_id: &str, task_id: &str, result: ExternalTaskResult, ) -> Result<bool>

Complete an external task

Source

pub async fn pending_external_tasks( &self, session_id: &str, ) -> Result<Vec<ExternalTask>>

Get pending external tasks for a session

Source

pub async fn get_tasks(&self, session_id: &str) -> Result<Vec<Task>>

Get tasks for a session

Source

pub async fn set_tasks( &self, session_id: &str, tasks: Vec<Task>, ) -> Result<Vec<Task>>

Set tasks for a session

Source

pub async fn fork_session( &self, source_id: &str, new_id: String, new_name: Option<String>, ) -> Result<String>

Fork a session, creating a new session with copied history and configuration

The forked session gets:

  • A new unique ID
  • Copied conversation history (messages)
  • Copied configuration (with optional name override)
  • Copied usage statistics and cost
  • Copied tasks
  • parent_id set to the source session ID
  • Fresh timestamps (created_at = now)

Non-serializable state (queue, HITL, permissions) is freshly initialized.

Source

pub async fn generate_title(&self, session_id: &str) -> Result<Option<String>>

Generate a short title for a session based on its conversation content

Uses the session’s LLM client (or default) to generate a concise title from the first few messages. The title is automatically set on the session.

Returns the generated title, or None if no LLM client is available or the session has no messages.

Trait Implementations§

Source§

impl Clone for SessionManager

Source§

fn clone(&self) -> SessionManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more