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 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).

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.

Source

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

Return a snapshot of the session’s conversation history.

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.

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