Skip to main content

Session

Struct Session 

Source
pub struct Session {
Show 26 fields pub id: String, pub config: SessionConfig, pub state: SessionState, pub messages: Vec<Message>, pub context_usage: ContextUsage, pub total_usage: TokenUsage, pub total_cost: f64, pub model_name: Option<String>, pub tools: Vec<ToolDefinition>, pub thinking_enabled: bool, pub thinking_budget: Option<usize>, pub llm_client: Option<Arc<dyn LlmClient>>, pub created_at: i64, pub updated_at: i64, pub command_queue: SessionLaneQueue, pub confirmation_manager: Arc<ConfirmationManager>, pub permission_policy: Arc<RwLock<PermissionPolicy>>, pub context_providers: Vec<Arc<dyn ContextProvider>>, pub tasks: Vec<Task>, pub parent_id: Option<String>, pub memory: Arc<RwLock<AgentMemory>>, pub current_plan: Arc<RwLock<Option<ExecutionPlan>>>, pub security_guard: Option<Arc<SecurityGuard>>, pub tool_metrics: Arc<RwLock<ToolMetrics>>, pub cost_records: Vec<LlmCostRecord>, pub loaded_skills: Vec<Skill>, /* private fields */
}

Fields§

§id: String§config: SessionConfig§state: SessionState§messages: Vec<Message>§context_usage: ContextUsage§total_usage: TokenUsage§total_cost: f64

Cumulative dollar cost for this session

§model_name: Option<String>

Model name for cost calculation

§tools: Vec<ToolDefinition>§thinking_enabled: bool§thinking_budget: Option<usize>§llm_client: Option<Arc<dyn LlmClient>>

Per-session LLM client (overrides default if set)

§created_at: i64

Creation timestamp (Unix epoch seconds)

§updated_at: i64

Last update timestamp (Unix epoch seconds)

§command_queue: SessionLaneQueue

Per-session command queue (a3s-lane backed)

§confirmation_manager: Arc<ConfirmationManager>

HITL confirmation manager

§permission_policy: Arc<RwLock<PermissionPolicy>>

Permission policy for tool execution

§context_providers: Vec<Arc<dyn ContextProvider>>

Context providers for augmenting prompts with external context

§tasks: Vec<Task>

Task list for tracking

§parent_id: Option<String>

Parent session ID (for subagent sessions)

§memory: Arc<RwLock<AgentMemory>>

Agent memory system for this session

§current_plan: Arc<RwLock<Option<ExecutionPlan>>>

Current execution plan (if any)

§security_guard: Option<Arc<SecurityGuard>>

Security guard (if enabled)

§tool_metrics: Arc<RwLock<ToolMetrics>>

Per-session tool execution metrics

§cost_records: Vec<LlmCostRecord>

Per-call LLM cost records for cross-session aggregation

§loaded_skills: Vec<Skill>

Loaded skills for tool filter enforcement in the agent loop

Implementations§

Source§

impl Session

Source

pub async fn new( id: String, config: SessionConfig, tools: Vec<ToolDefinition>, ) -> Result<Self>

Create a new session (async due to SessionLaneQueue initialization)

Source

pub fn is_child_session(&self) -> bool

Check if this is a child session (has a parent)

Source

pub fn parent_session_id(&self) -> Option<&str>

Get the parent session ID if this is a child session

Source

pub fn subscribe_events(&self) -> Receiver<AgentEvent>

Get a receiver for session events

Source

pub fn event_tx(&self) -> Sender<AgentEvent>

Get the event broadcaster

Source

pub async fn set_confirmation_policy(&self, policy: ConfirmationPolicy)

Update the confirmation policy

Source

pub async fn confirmation_policy(&self) -> ConfirmationPolicy

Get the current confirmation policy

Source

pub async fn set_permission_policy(&self, policy: PermissionPolicy)

Update the permission policy

Source

pub async fn permission_policy(&self) -> PermissionPolicy

Get the current permission policy

Source

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

Check permission for a tool invocation

Source

pub async fn add_allow_rule(&self, rule: &str)

Add an allow rule to the permission policy

Source

pub async fn add_deny_rule(&self, rule: &str)

Add a deny rule to the permission policy

Source

pub async fn add_ask_rule(&self, rule: &str)

Add an ask rule to the permission policy

Source

pub fn add_context_provider(&mut self, provider: Arc<dyn ContextProvider>)

Add a context provider to the session

Source

pub fn remove_context_provider(&mut self, name: &str) -> bool

Remove a context provider by name

Returns true if a provider was removed, false otherwise.

Source

pub fn context_provider_names(&self) -> Vec<String>

Get the names of all registered context providers

Source

pub fn get_tasks(&self) -> &[Task]

Get the current task list

Source

pub fn set_tasks(&mut self, tasks: Vec<Task>)

Set the task list (replaces entire list)

Broadcasts a TaskUpdated event after updating.

Source

pub fn active_task_count(&self) -> usize

Get count of active (non-completed, non-cancelled) tasks

Source

pub async fn set_lane_handler( &self, lane: SessionLane, config: LaneHandlerConfig, )

Set handler mode for a lane

Source

pub async fn get_lane_handler(&self, lane: SessionLane) -> LaneHandlerConfig

Get handler config for a lane

Source

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

Complete an external task

Source

pub async fn pending_external_tasks(&self) -> Vec<ExternalTask>

Get pending external tasks

Source

pub async fn dead_letters(&self) -> Vec<DeadLetter>

Get dead letters from the queue’s DLQ

Source

pub async fn queue_metrics(&self) -> Option<MetricsSnapshot>

Get queue metrics snapshot

Source

pub async fn queue_stats(&self) -> SessionQueueStats

Get queue statistics

Source

pub async fn start_queue(&self) -> Result<()>

Start the command queue scheduler

Source

pub async fn stop_queue(&self)

Stop the command queue scheduler

Source

pub fn system(&self) -> Option<&str>

Get the system prompt from config

Source

pub fn history(&self) -> &[Message]

Get conversation history

Source

pub fn add_message(&mut self, message: Message)

Add a message to history

Source

pub fn update_usage(&mut self, usage: &TokenUsage)

Update context usage after a response

Source

pub fn clear(&mut self)

Clear conversation history

Source

pub async fn compact(&mut self, llm_client: &Arc<dyn LlmClient>) -> Result<()>

Compact context by summarizing old messages

Source

pub fn pause(&mut self) -> bool

Pause the session

Source

pub fn resume(&mut self) -> bool

Resume the session

Source

pub fn set_error(&mut self)

Set session state to error

Source

pub fn set_completed(&mut self)

Set session state to completed

Source

pub fn to_session_data(&self, llm_config: Option<LlmConfigData>) -> SessionData

Convert to serializable SessionData for persistence

Source

pub fn restore_from_data(&mut self, data: &SessionData)

Restore session state from SessionData

Note: This only restores serializable fields. Non-serializable fields (event_tx, command_queue, confirmation_manager) are already initialized in Session::new().

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> 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, 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