pub struct ImpSession { /* private fields */ }Expand description
A fully wired agent session.
Manages the lifecycle of a single agent: config resolution, model selection, session persistence, and the event/command channels.
Implementations§
Source§impl ImpSession
impl ImpSession
Sourcepub async fn create(options: SessionOptions) -> Result<Self>
pub async fn create(options: SessionOptions) -> Result<Self>
Create a new session by resolving config, auth, model, and tools.
This is the main factory — mirrors pi’s createAgentSession().
Sourcepub async fn prompt(&mut self, text: &str) -> Result<()>
pub async fn prompt(&mut self, text: &str) -> Result<()>
Send a prompt and run the agent loop.
The agent runs on a background task. Use [recv_event] to consume
events, and [steer] / [follow_up] / [cancel] to control it.
Returns an error if the agent is already running.
Sourcepub async fn prompt_and_wait(&mut self, text: &str) -> Result<()>
pub async fn prompt_and_wait(&mut self, text: &str) -> Result<()>
Send a prompt and block until the agent finishes.
Events are still emitted via [recv_event], but this method
does not return until the agent loop completes.
Sourcepub async fn steer(&self, text: &str) -> Result<()>
pub async fn steer(&self, text: &str) -> Result<()>
Interrupt the agent: delivered after the current tool finishes, remaining queued tools are skipped.
Sourcepub async fn follow_up(&self, text: &str) -> Result<()>
pub async fn follow_up(&self, text: &str) -> Result<()>
Follow-up: delivered only after the agent finishes all current work.
Sourcepub fn abort(&mut self)
pub fn abort(&mut self)
Force-abort the current agent task when graceful cancellation does not finish.
Sourcepub async fn recv_event(&mut self) -> Option<AgentEvent>
pub async fn recv_event(&mut self) -> Option<AgentEvent>
Receive the next event from the agent.
Returns None when the agent has finished and all events have
been consumed.
Sourcepub fn event_rx(&mut self) -> &mut Receiver<AgentEvent>
pub fn event_rx(&mut self) -> &mut Receiver<AgentEvent>
Get mutable access to the raw event receiver.
Use this when you need select! or other channel combinators.
Sourcepub async fn set_model(&mut self, hint: &str) -> Result<()>
pub async fn set_model(&mut self, hint: &str) -> Result<()>
Switch the model for subsequent prompts.
The change takes effect on the next prompt() call.
Sourcepub fn set_thinking(&mut self, level: ThinkingLevel)
pub fn set_thinking(&mut self, level: ThinkingLevel)
Set the thinking level for subsequent prompts.
Sourcepub fn session_manager(&self) -> &SessionManager
pub fn session_manager(&self) -> &SessionManager
The session manager (tree, entries, persistence).
Sourcepub fn session_manager_mut(&mut self) -> &mut SessionManager
pub fn session_manager_mut(&mut self) -> &mut SessionManager
Mutable access to the session manager.
Sourcepub fn auth_store(&self) -> &AuthStore
pub fn auth_store(&self) -> &AuthStore
The auth store (for checking credentials, OAuth status, etc).
Sourcepub fn auth_store_mut(&mut self) -> &mut AuthStore
pub fn auth_store_mut(&mut self) -> &mut AuthStore
Mutable access to the auth store.
Sourcepub fn model_registry(&self) -> &ModelRegistry
pub fn model_registry(&self) -> &ModelRegistry
The model registry.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the agent is currently running a prompt.
Sourcepub fn command_tx(&self) -> &Sender<AgentCommand>
pub fn command_tx(&self) -> &Sender<AgentCommand>
Get the raw command sender for advanced use cases.
Auto Trait Implementations§
impl Freeze for ImpSession
impl !RefUnwindSafe for ImpSession
impl Send for ImpSession
impl Sync for ImpSession
impl Unpin for ImpSession
impl UnsafeUnpin for ImpSession
impl !UnwindSafe for ImpSession
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> 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