Skip to main content

AgentSession

Struct AgentSession 

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

Workspace-bound session. All LLM and tool operations happen here.

History is automatically accumulated after each send() call. Use history() to retrieve the current conversation log.

Implementations§

Source§

impl AgentSession

Source

pub fn command_registry(&self) -> &CommandRegistry

Get a reference to the slash command registry.

Source

pub fn register_command(&mut self, cmd: Arc<dyn SlashCommand>)

Register a custom slash command.

Source

pub async fn send( &self, prompt: &str, history: Option<&[Message]>, ) -> Result<AgentResult>

Send a prompt and wait for the complete response.

When history is None, uses (and auto-updates) the session’s internal conversation history. When Some, uses the provided history instead (the internal history is not modified).

If the prompt starts with /, it is dispatched as a slash command and the result is returned without calling the LLM.

Source

pub async fn send_with_attachments( &self, prompt: &str, attachments: &[Attachment], history: Option<&[Message]>, ) -> Result<AgentResult>

Send a prompt with image attachments and wait for the complete response.

Images are included as multi-modal content blocks in the user message. Requires a vision-capable model (e.g., Claude Sonnet, GPT-4o).

Source

pub async fn stream_with_attachments( &self, prompt: &str, attachments: &[Attachment], history: Option<&[Message]>, ) -> Result<(Receiver<AgentEvent>, JoinHandle<()>)>

Stream a prompt with image attachments.

Images are included as multi-modal content blocks in the user message. Requires a vision-capable model (e.g., Claude Sonnet, GPT-4o).

Source

pub async fn stream( &self, prompt: &str, history: Option<&[Message]>, ) -> Result<(Receiver<AgentEvent>, JoinHandle<()>)>

Send a prompt and stream events back.

When history is None, uses the session’s internal history (note: streaming does not auto-update internal history since the result is consumed asynchronously via the channel). When Some, uses the provided history instead.

If the prompt starts with /, it is dispatched as a slash command and the result is emitted as a single TextDelta + End event.

Source

pub fn history(&self) -> Vec<Message>

Return a snapshot of the session’s conversation history.

Source

pub fn memory(&self) -> Option<&Arc<AgentMemory>>

Return a reference to the session’s memory, if configured.

Source

pub fn id(&self) -> &str

Return the session ID.

Source

pub fn workspace(&self) -> &Path

Return the session workspace path.

Source

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

Return any deferred init warning (e.g. memory store failed to initialize).

Source

pub fn session_id(&self) -> &str

Return the session ID.

Source

pub fn register_hook(&self, hook: Hook)

Register a hook for lifecycle event interception.

Source

pub fn unregister_hook(&self, hook_id: &str) -> Option<Hook>

Unregister a hook by ID.

Source

pub fn register_hook_handler( &self, hook_id: &str, handler: Arc<dyn HookHandler>, )

Register a handler for a specific hook.

Source

pub fn unregister_hook_handler(&self, hook_id: &str)

Unregister a hook handler by hook ID.

Source

pub fn hook_count(&self) -> usize

Get the number of registered hooks.

Source

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

Save the session to the configured store.

Returns Ok(()) if saved successfully, or if no store is configured (no-op).

Source

pub async fn read_file(&self, path: &str) -> Result<String>

Read a file from the workspace.

Source

pub async fn bash(&self, command: &str) -> Result<String>

Execute a bash command in the workspace.

When a sandbox is configured via SessionOptions::with_sandbox(), the command is routed through the A3S Box sandbox.

Source

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

Search for files matching a glob pattern.

Source

pub async fn grep(&self, pattern: &str) -> Result<String>

Search file contents with a regex pattern.

Source

pub async fn tool(&self, name: &str, args: Value) -> Result<ToolCallResult>

Execute a tool by name, bypassing the LLM.

Source

pub fn has_queue(&self) -> bool

Returns whether this session has a lane queue configured.

Source

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

Configure a lane’s handler mode (Internal/External/Hybrid).

Only effective when a queue is configured via SessionOptions::with_queue_config.

Source

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

Complete an external task by ID.

Returns true if the task was found and completed, false if not found.

Source

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

Get pending external tasks awaiting completion by an external handler.

Source

pub async fn queue_stats(&self) -> SessionQueueStats

Get queue statistics (pending, active, external counts per lane).

Source

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

Get a metrics snapshot from the queue (if metrics are enabled).

Source

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

Get dead letters from the queue’s DLQ (if DLQ is enabled).

Trait Implementations§

Source§

impl Debug for AgentSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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