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
impl AgentSessionHandle
Sourcepub const fn from_session_with_listeners(
session: AgentSession,
listeners: EventListeners,
) -> Self
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.
Sourcepub async fn prompt(
&mut self,
input: impl Into<String>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
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.
Sourcepub async fn prompt_with_abort(
&mut self,
input: impl Into<String>,
abort_signal: AbortSignal,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
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.
Sourcepub fn new_abort_handle() -> (AbortHandle, AbortSignal)
pub fn new_abort_handle() -> (AbortHandle, AbortSignal)
Create a new abort handle/signal pair for prompt cancellation.
Sourcepub fn subscribe(
&self,
listener: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> SubscriptionId
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.
Sourcepub fn unsubscribe(&self, id: SubscriptionId) -> bool
pub fn unsubscribe(&self, id: SubscriptionId) -> bool
Remove a previously registered event listener.
Returns true if the listener was found and removed.
Sourcepub const fn listeners(&self) -> &EventListeners
pub const fn listeners(&self) -> &EventListeners
Access the session-level event listeners.
Sourcepub const fn listeners_mut(&mut self) -> &mut EventListeners
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.
Sourcepub const fn has_extensions(&self) -> bool
pub const fn has_extensions(&self) -> bool
Whether this session has extensions loaded.
Sourcepub fn extension_manager(&self) -> Option<&ExtensionManager>
pub fn extension_manager(&self) -> Option<&ExtensionManager>
Return a reference to the extension manager (if extensions are loaded).
Sourcepub const fn extension_region(&self) -> Option<&ExtensionRegion>
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.
Sourcepub async fn set_model(&mut self, provider: &str, model_id: &str) -> Result<()>
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.
Sourcepub const fn thinking_level(&self) -> Option<ThinkingLevel>
pub const fn thinking_level(&self) -> Option<ThinkingLevel>
Return the currently configured thinking level.
Sourcepub const fn thinking(&self) -> Option<ThinkingLevel>
pub const fn thinking(&self) -> Option<ThinkingLevel>
Alias for thinking level access, matching the SDK naming style.
Sourcepub async fn set_thinking_level(&mut self, level: ThinkingLevel) -> Result<()>
pub async fn set_thinking_level(&mut self, level: ThinkingLevel) -> Result<()>
Update thinking level and persist it to session metadata.
Sourcepub async fn messages(&self) -> Result<Vec<Message>>
pub async fn messages(&self) -> Result<Vec<Message>>
Return all model messages for the current session path.
Sourcepub async fn state(&self) -> Result<AgentSessionState>
pub async fn state(&self) -> Result<AgentSessionState>
Return a lightweight state snapshot.
Sourcepub async fn compact(
&mut self,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<()>
pub async fn compact( &mut self, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<()>
Trigger an immediate compaction pass (if compaction is enabled).
Sourcepub const fn session(&self) -> &AgentSession
pub const fn session(&self) -> &AgentSession
Access the underlying AgentSession.
Sourcepub const fn session_mut(&mut self) -> &mut AgentSession
pub const fn session_mut(&mut self) -> &mut AgentSession
Mutable access to the underlying AgentSession.
Sourcepub fn into_inner(self) -> AgentSession
pub fn into_inner(self) -> AgentSession
Consume the handle and return the inner AgentSession.
Auto Trait Implementations§
impl !Freeze for AgentSessionHandle
impl !RefUnwindSafe for AgentSessionHandle
impl Send for AgentSessionHandle
impl Sync for AgentSessionHandle
impl Unpin for AgentSessionHandle
impl UnsafeUnpin for AgentSessionHandle
impl !UnwindSafe for AgentSessionHandle
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> 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