Skip to main content

AgentSessionHandle

Struct AgentSessionHandle 

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

Lightweight handle for programmatic embedding.

This wraps AgentSession and exposes high-level request methods while still allowing access to the underlying session when needed.

Session-level event listeners can be registered via Self::subscribe or by providing callbacks on SessionOptions. These fire for every prompt, in addition to the per-prompt on_event callback.

Implementations§

Source§

impl AgentSessionHandle

Source

pub const fn from_session_with_listeners( session: AgentSession, listeners: EventListeners, ) -> Self

Create a handle from a pre-built AgentSession with custom listeners.

This is useful for tests and advanced embedding scenarios where the full create_agent_session() flow is not needed.

Source

pub async fn prompt( &mut self, input: impl Into<String>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>

Send one user prompt through the agent loop.

The on_event callback receives events for this prompt only. Session-level listeners registered via Self::subscribe or SessionOptions callbacks also fire for every event.

Source

pub async fn prompt_with_abort( &mut self, input: impl Into<String>, abort_signal: AbortSignal, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>

Send one user prompt through the agent loop with an explicit abort signal.

Source

pub fn new_abort_handle() -> (AbortHandle, AbortSignal)

Create a new abort handle/signal pair for prompt cancellation.

Source

pub fn subscribe( &self, listener: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> SubscriptionId

Register a session-level event listener.

The listener fires for every AgentEvent across all future prompts until removed via Self::unsubscribe.

Returns a SubscriptionId that can be used to remove the listener.

Source

pub fn unsubscribe(&self, id: SubscriptionId) -> bool

Remove a previously registered event listener.

Returns true if the listener was found and removed.

Source

pub const fn listeners(&self) -> &EventListeners

Access the session-level event listeners.

Source

pub const fn listeners_mut(&mut self) -> &mut EventListeners

Mutable access to session-level event listeners.

Allows updating typed hooks (on_tool_start, on_tool_end, on_stream_event) after session creation.

Source

pub const fn has_extensions(&self) -> bool

Whether this session has extensions loaded.

Source

pub fn extension_manager(&self) -> Option<&ExtensionManager>

Return a reference to the extension manager (if extensions are loaded).

Source

pub const fn extension_region(&self) -> Option<&ExtensionRegion>

Return a reference to the extension region (if extensions are loaded).

The region wraps the extension manager with lifecycle management.

Source

pub fn model(&self) -> (String, String)

Return the active provider/model pair.

Source

pub async fn set_model(&mut self, provider: &str, model_id: &str) -> Result<()>

Update the active provider/model pair and persist it to session metadata.

Source

pub const fn thinking_level(&self) -> Option<ThinkingLevel>

Return the currently configured thinking level.

Source

pub const fn thinking(&self) -> Option<ThinkingLevel>

Alias for thinking level access, matching the SDK naming style.

Source

pub async fn set_thinking_level(&mut self, level: ThinkingLevel) -> Result<()>

Update thinking level and persist it to session metadata.

Source

pub async fn messages(&self) -> Result<Vec<Message>>

Return all model messages for the current session path.

Source

pub async fn state(&self) -> Result<AgentSessionState>

Return a lightweight state snapshot.

Source

pub async fn compact( &mut self, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<()>

Trigger an immediate compaction pass (if compaction is enabled).

Source

pub const fn session(&self) -> &AgentSession

Access the underlying AgentSession.

Source

pub const fn session_mut(&mut self) -> &mut AgentSession

Mutable access to the underlying AgentSession.

Source

pub fn into_inner(self) -> AgentSession

Consume the handle and return the inner AgentSession.

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> 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
Source§

impl<T> ParallelSend for T

Source§

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

Source§

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