pub struct AgentSession {
pub agent: Agent,
pub session: Arc<Mutex<Session>>,
pub extensions: Option<ExtensionRegion>,
/* private fields */
}Fields§
§agent: Agent§session: Arc<Mutex<Session>>§extensions: Option<ExtensionRegion>Extension lifecycle region — ensures the JS runtime thread is shut down when the session ends.
Implementations§
Source§impl AgentSession
impl AgentSession
pub const fn runtime_repair_mode_from_policy_mode( mode: RepairPolicyMode, ) -> RepairMode
pub fn new( agent: Agent, session: Arc<Mutex<Session>>, save_enabled: bool, compaction_settings: ResolvedCompactionSettings, ) -> Self
pub const fn set_input_source(&mut self, source: InputSource)
pub fn with_runtime_handle(self, runtime_handle: RuntimeHandle) -> Self
pub fn with_model_registry(self, registry: ModelRegistry) -> Self
pub fn with_auth_storage(self, auth: AuthStorage) -> Self
pub fn set_model_registry(&mut self, registry: ModelRegistry)
pub fn set_auth_storage(&mut self, auth: AuthStorage)
pub fn with_api_key_override(self, api_key: Option<String>) -> Self
pub fn set_api_key_override(&mut self, api_key: Option<String>)
pub fn refresh_extension_completion_host_state(&self)
pub fn set_semantic_context_bundle( &mut self, injection: Option<SemanticContextBundleInjection>, )
pub const fn semantic_context_bundle( &self, ) -> Option<&SemanticContextBundleInjection>
pub fn set_queue_modes( &mut self, steering_mode: QueueMode, follow_up_mode: QueueMode, )
pub const fn set_compaction_context_window( &mut self, context_window_tokens: u32, )
pub async fn set_provider_model( &mut self, provider_id: &str, model_id: &str, ) -> Result<()>
Sourcepub async fn set_thinking_level(&mut self, level: ThinkingLevel) -> Result<()>
pub async fn set_thinking_level(&mut self, level: ThinkingLevel) -> Result<()>
Update the thinking/reasoning level for this session at runtime.
Clamps the requested level to what the active model supports (e.g. a
non-reasoning model is forced to Off), records a thinking-level change
in session history when it actually changes, and persists the session.
Mirrors crate::sdk::AgentSessionHandle::set_thinking_level but is
callable directly on an AgentSession (e.g. from the ACP transport,
which holds an AgentSession rather than an SDK handle).
pub const fn save_enabled(&self) -> bool
Sourcepub async fn compact_now(
&mut self,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<()>
pub async fn compact_now( &mut self, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<()>
Force-run compaction synchronously (used by /compact slash command).
pub async fn execute_extension_command( &mut self, command_name: &str, args: &str, timeout_ms: u64, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<Value>
pub async fn execute_extension_command_with_abort( &mut self, command_name: &str, args: &str, timeout_ms: u64, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<Value>
pub async fn enable_extensions( &mut self, enabled_tools: &[&str], cwd: &Path, config: Option<&Config>, extension_entries: &[PathBuf], ) -> Result<()>
pub async fn enable_extensions_with_policy( &mut self, enabled_tools: &[&str], cwd: &Path, config: Option<&Config>, extension_entries: &[PathBuf], policy: Option<ExtensionPolicy>, repair_policy: Option<RepairPolicyMode>, pre_warmed: Option<PreWarmedExtensionRuntime>, ) -> Result<()>
pub async fn save_and_index(&mut self) -> Result<()>
pub async fn persist_session(&mut self) -> Result<()>
pub async fn run_text( &mut self, input: String, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
pub async fn run_text_with_abort( &mut self, input: String, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
pub async fn run_with_content( &mut self, content: Vec<ContentBlock>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
pub async fn run_with_content_with_abort( &mut self, content: Vec<ContentBlock>, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
pub async fn revert_last_user_message(&mut self) -> Result<bool>
Sourcepub async fn revert_incomplete_response(&mut self) -> Result<bool>
pub async fn revert_incomplete_response(&mut self) -> Result<bool>
Revert only the incomplete trailing assistant output of a failed request
(the partial/error message from a transient connection drop), preserving
the user prompt and every completed tool cycle. Used before a retry that
resumes the turn (run_continue_with_abort) rather than replaying it
from the user message (pi_agent_rust#125). Syncs the agent’s in-memory
transcript to the reverted session path so a subsequent resume streams
from the last completed state.
Sourcepub async fn run_continue_with_abort(
&mut self,
abort: Option<AbortSignal>,
on_event: impl Fn(AgentEvent) + Send + Sync + 'static,
) -> Result<AssistantMessage>
pub async fn run_continue_with_abort( &mut self, abort: Option<AbortSignal>, on_event: impl Fn(AgentEvent) + Send + Sync + 'static, ) -> Result<AssistantMessage>
Resume the current turn after a transient failure WITHOUT adding a new user message: the agent loop continues from the last completed state (the user prompt plus any already-completed tool cycles that are still on the session path), so a retry re-issues only the failed provider request instead of replaying the whole turn. This is what makes auto-retry idempotent — no tool re-execution, no re-billing of prior work (pi_agent_rust#125).
Callers should strip the failed request’s incomplete output first via
Self::revert_incomplete_response so the resume streams from a clean
tail (no dangling error/partial assistant, no orphaned tool call).
Auto Trait Implementations§
impl !Freeze for AgentSession
impl !RefUnwindSafe for AgentSession
impl !UnwindSafe for AgentSession
impl Send for AgentSession
impl Sync for AgentSession
impl Unpin for AgentSession
impl UnsafeUnpin for AgentSession
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