pub struct Session {Show 25 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<dyn ConfirmationProvider>,
pub permission_checker: Arc<dyn PermissionChecker>,
pub context_providers: Vec<Arc<dyn ContextProvider>>,
pub tasks: Vec<Task>,
pub parent_id: Option<String>,
pub memory: Option<Arc<RwLock<AgentMemory>>>,
pub current_plan: Arc<RwLock<Option<ExecutionPlan>>>,
pub security_provider: Option<Arc<dyn SecurityProvider>>,
pub tool_metrics: Arc<RwLock<ToolMetrics>>,
pub cost_records: Vec<LlmCostRecord>,
/* private fields */
}Fields§
§id: String§config: SessionConfig§state: SessionState§messages: Vec<Message>§context_usage: ContextUsage§total_usage: TokenUsage§total_cost: f64Cumulative 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: i64Creation timestamp (Unix epoch seconds)
updated_at: i64Last update timestamp (Unix epoch seconds)
command_queue: SessionLaneQueuePer-session command queue (a3s-lane backed)
confirmation_manager: Arc<dyn ConfirmationProvider>HITL confirmation manager
permission_checker: Arc<dyn PermissionChecker>Permission checker 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: Option<Arc<RwLock<AgentMemory>>>Agent memory system for this session (externally injected)
current_plan: Arc<RwLock<Option<ExecutionPlan>>>Current execution plan (if any)
security_provider: Option<Arc<dyn SecurityProvider>>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
Implementations§
Source§impl Session
impl Session
Sourcepub async fn new(
id: String,
config: SessionConfig,
tools: Vec<ToolDefinition>,
) -> Result<Self>
pub async fn new( id: String, config: SessionConfig, tools: Vec<ToolDefinition>, ) -> Result<Self>
Create a new session (async due to SessionLaneQueue initialization)
Sourcepub fn is_child_session(&self) -> bool
pub fn is_child_session(&self) -> bool
Check if this is a child session (has a parent)
Sourcepub fn parent_session_id(&self) -> Option<&str>
pub fn parent_session_id(&self) -> Option<&str>
Get the parent session ID if this is a child session
Sourcepub fn subscribe_events(&self) -> Receiver<AgentEvent>
pub fn subscribe_events(&self) -> Receiver<AgentEvent>
Get a receiver for session events
Sourcepub fn event_tx(&self) -> Sender<AgentEvent>
pub fn event_tx(&self) -> Sender<AgentEvent>
Get the event broadcaster
Sourcepub async fn set_confirmation_policy(&self, policy: ConfirmationPolicy)
pub async fn set_confirmation_policy(&self, policy: ConfirmationPolicy)
Update the confirmation policy
Sourcepub fn set_permission_policy(&mut self, policy: PermissionPolicy)
pub fn set_permission_policy(&mut self, policy: PermissionPolicy)
Update the permission policy used for tool execution checks.
Sourcepub async fn confirmation_policy(&self) -> ConfirmationPolicy
pub async fn confirmation_policy(&self) -> ConfirmationPolicy
Get the current confirmation policy
Sourcepub fn check_permission(
&self,
tool_name: &str,
args: &Value,
) -> PermissionDecision
pub fn check_permission( &self, tool_name: &str, args: &Value, ) -> PermissionDecision
Check permission for a tool invocation
Sourcepub fn add_context_provider(&mut self, provider: Arc<dyn ContextProvider>)
pub fn add_context_provider(&mut self, provider: Arc<dyn ContextProvider>)
Add a context provider to the session
Sourcepub fn remove_context_provider(&mut self, name: &str) -> bool
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.
Sourcepub fn context_provider_names(&self) -> Vec<String>
pub fn context_provider_names(&self) -> Vec<String>
Get the names of all registered context providers
Sourcepub fn set_tasks(&mut self, tasks: Vec<Task>)
pub fn set_tasks(&mut self, tasks: Vec<Task>)
Set the task list (replaces entire list)
Broadcasts a TaskUpdated event after updating.
Sourcepub fn active_task_count(&self) -> usize
pub fn active_task_count(&self) -> usize
Get count of active (non-completed, non-cancelled) tasks
Sourcepub async fn set_lane_handler(
&self,
lane: SessionLane,
config: LaneHandlerConfig,
)
pub async fn set_lane_handler( &self, lane: SessionLane, config: LaneHandlerConfig, )
Set handler mode for a lane
Sourcepub async fn get_lane_handler(&self, lane: SessionLane) -> LaneHandlerConfig
pub async fn get_lane_handler(&self, lane: SessionLane) -> LaneHandlerConfig
Get handler config for a lane
Sourcepub async fn complete_external_task(
&self,
task_id: &str,
result: ExternalTaskResult,
) -> bool
pub async fn complete_external_task( &self, task_id: &str, result: ExternalTaskResult, ) -> bool
Complete an external task
Sourcepub async fn pending_external_tasks(&self) -> Vec<ExternalTask>
pub async fn pending_external_tasks(&self) -> Vec<ExternalTask>
Get pending external tasks
Sourcepub async fn dead_letters(&self) -> Vec<DeadLetter>
pub async fn dead_letters(&self) -> Vec<DeadLetter>
Get dead letters from the queue’s DLQ
Sourcepub async fn queue_metrics(&self) -> Option<MetricsSnapshot>
pub async fn queue_metrics(&self) -> Option<MetricsSnapshot>
Get queue metrics snapshot
Sourcepub async fn queue_stats(&self) -> SessionQueueStats
pub async fn queue_stats(&self) -> SessionQueueStats
Get queue statistics
Sourcepub async fn start_queue(&self) -> Result<()>
pub async fn start_queue(&self) -> Result<()>
Start the command queue scheduler
Sourcepub async fn stop_queue(&self)
pub async fn stop_queue(&self)
Stop the command queue scheduler
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Add a message to history
Sourcepub fn update_usage(&mut self, usage: &TokenUsage)
pub fn update_usage(&mut self, usage: &TokenUsage)
Update context usage after a response
Sourcepub async fn compact(&mut self, llm_client: &Arc<dyn LlmClient>) -> Result<()>
pub async fn compact(&mut self, llm_client: &Arc<dyn LlmClient>) -> Result<()>
Compact context by summarizing old messages
Sourcepub fn set_completed(&mut self)
pub fn set_completed(&mut self)
Set session state to completed
Sourcepub fn to_session_data(&self, llm_config: Option<LlmConfigData>) -> SessionData
pub fn to_session_data(&self, llm_config: Option<LlmConfigData>) -> SessionData
Convert to serializable SessionData for persistence
Sourcepub fn restore_from_data(&mut self, data: &SessionData)
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§
impl Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more