#[non_exhaustive]pub struct LocalAgent { /* private fields */ }Expand description
The agent as sequential hook events and plugins see it (LocalAgent).
It holds everything those callbacks may change: the conversation, the system prompt, the
tools and the state, plus the agent’s identity, models and hooks. Hook events lend it out as
&mut LocalAgent while the loop is paused at the event.
Implementations§
Source§impl LocalAgent
impl LocalAgent
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
What the agent does.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
A stable id for the current conversation session: the session manager’s id when one is attached, otherwise a random 8-character hex id generated once per agent.
Sourcepub fn app_state(&self) -> &StateStore
pub fn app_state(&self) -> &StateStore
App state shared with tools and application code.
Sourcepub fn model_state(&self) -> &StateStore
pub fn model_state(&self) -> &StateStore
The model provider’s runtime state, such as response ids of server-side conversations.
Sourcepub fn messages_mut(&mut self) -> &mut Vec<Message>
pub fn messages_mut(&mut self) -> &mut Vec<Message>
The conversation history, to edit.
Sourcepub fn system_prompt(&self) -> Option<&SystemPrompt>
pub fn system_prompt(&self) -> Option<&SystemPrompt>
The system prompt.
Sourcepub fn set_system_prompt(&mut self, system_prompt: Option<SystemPrompt>)
pub fn set_system_prompt(&mut self, system_prompt: Option<SystemPrompt>)
Replaces or clears the system prompt.
Sourcepub fn aux_model(&self) -> &Arc<dyn Model> ⓘ
pub fn aux_model(&self) -> &Arc<dyn Model> ⓘ
The model for auxiliary side calls (summaries, classification); the agent’s model unless one was configured.
Sourcepub fn agent_metadata(&self) -> Option<&AgentMetadata>
pub fn agent_metadata(&self) -> Option<&AgentMetadata>
The metadata the agent passes to its model.
Sourcepub fn sandbox(&self) -> &Arc<dyn Sandbox> ⓘ
pub fn sandbox(&self) -> &Arc<dyn Sandbox> ⓘ
Where the agent’s tools run commands and touch files (sandbox): the configured sandbox,
or the shared NotASandboxLocalEnvironment
when none is configured.
Sourcepub fn storage(&self) -> Option<&Arc<dyn Storage>>
pub fn storage(&self) -> Option<&Arc<dyn Storage>>
The default storage backend for agent subsystems (storage): subsystems without their own
storage, such as the session manager, resolve from it under their own namespace.
Sourcepub fn tool_registry(&self) -> &ToolRegistry
pub fn tool_registry(&self) -> &ToolRegistry
The agent’s tools.
Sourcepub fn tool_registry_mut(&mut self) -> &mut ToolRegistry
pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry
The agent’s tools, to add or remove some.
Sourcepub fn cancel_signal(&self) -> CancelSignal
pub fn cancel_signal(&self) -> CancelSignal
The cancellation signal of the current invocation.
Sourcepub fn cancel(&self, options: CancelOptions)
pub fn cancel(&self, options: CancelOptions)
Cancels the current invocation (cancel); does nothing when the agent is idle.
Sourcepub fn metrics(&self) -> AgentMetrics
pub fn metrics(&self) -> AgentMetrics
Aggregated loop metrics of the agent: cycles, token usage and tool statistics.
Sourcepub fn add_hook<K: HookEvent>(
&self,
callback: impl IntoSyncHook<K>,
) -> HookCleanup
pub fn add_hook<K: HookEvent>( &self, callback: impl IntoSyncHook<K>, ) -> HookCleanup
Registers a hook closure; see HookRegistry::add_hook.
Sourcepub fn add_hook_with<K: HookEvent>(
&self,
callback: impl IntoSyncHook<K>,
options: HookCallbackOptions,
) -> HookCleanup
pub fn add_hook_with<K: HookEvent>( &self, callback: impl IntoSyncHook<K>, options: HookCallbackOptions, ) -> HookCleanup
Registers a hook closure with options; see HookRegistry::add_hook_with.
Sourcepub fn add_async_hook<K: HookEvent>(
&self,
callback: impl IntoAsyncHook<K>,
) -> HookCleanup
pub fn add_async_hook<K: HookEvent>( &self, callback: impl IntoAsyncHook<K>, ) -> HookCleanup
Registers an async hook closure; see HookRegistry::add_async_hook.
Sourcepub fn add_async_hook_with<K: HookEvent>(
&self,
callback: impl IntoAsyncHook<K>,
options: HookCallbackOptions,
) -> HookCleanup
pub fn add_async_hook_with<K: HookEvent>( &self, callback: impl IntoAsyncHook<K>, options: HookCallbackOptions, ) -> HookCleanup
Registers an async hook closure with options; see HookRegistry::add_async_hook_with.
Sourcepub fn add_hook_impl<K: HookEvent>(
&self,
hook: impl IntoHookImpl<K>,
) -> HookCleanup
pub fn add_hook_impl<K: HookEvent>( &self, hook: impl IntoHookImpl<K>, ) -> HookCleanup
Registers a Hook implementation; see HookRegistry::add_hook_impl.
Sourcepub fn add_hook_impl_with<K: HookEvent>(
&self,
hook: impl IntoHookImpl<K>,
options: HookCallbackOptions,
) -> HookCleanup
pub fn add_hook_impl_with<K: HookEvent>( &self, hook: impl IntoHookImpl<K>, options: HookCallbackOptions, ) -> HookCleanup
Registers a Hook implementation with options.
Sourcepub fn add_middleware<S: MiddlewareStage>(
&self,
middleware: Middleware<S>,
) -> MiddlewareCleanup
pub fn add_middleware<S: MiddlewareStage>( &self, middleware: Middleware<S>, ) -> MiddlewareCleanup
Registers a middleware handler for its stage and phase; see
middleware. Handlers registered while an invocation runs apply from
the next stage call.
Source§impl LocalAgent
impl LocalAgent
Sourcepub fn take_snapshot(
&self,
options: impl Into<TakeSnapshotOptions>,
) -> Result<Snapshot>
pub fn take_snapshot( &self, options: impl Into<TakeSnapshotOptions>, ) -> Result<Snapshot>
Captures a point-in-time snapshot of the agent’s state.
§Errors
When the options select no field, or a value fails to serialize.
Sourcepub fn load_snapshot(&mut self, snapshot: &Snapshot) -> Result<()>
pub fn load_snapshot(&mut self, snapshot: &Snapshot) -> Result<()>
Restores the agent’s state from a snapshot. Only the fields present in
snapshot.data are restored; the others stay as they are. Once the agent is initialized,
its background tasks refuse the load while they track tasks, and reload theirs from a
restored state, as Agent::load_snapshot does.
§Errors
A snapshot of another scope or schema version, data that does not decode, or background tasks still tracked. Nothing is restored when an error is returned.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LocalAgent
impl !RefUnwindSafe for LocalAgent
impl !UnwindSafe for LocalAgent
impl Forget for LocalAgent
impl Move for LocalAgent
impl Send for LocalAgentwhere
RawVecInner: Send,
OnceLock<String>: Send,
Arc<RwLock<Map<String, Value>>>: Send,
RawTable<usize>: Send,
Arc<dyn Error + Send + Sync>: Send,
Arc<dyn Model>: Send,
Arc<dyn Tool>: Send,
Arc<Shared>: Send,
Arc<[Source]>: Send,
Arc<Mutex<Meter>>: Send,
Arc<Tracer>: Send,
Arc<HookRegistry>: Send,
Arc<MiddlewareRegistry>: Send,
Arc<Mutex<InterruptStateData>>: Send,
Arc<BackgroundTasks>: Send,
Arc<dyn Sandbox>: Send,
Arc<dyn Storage>: Send,
Arc<[Arc<dyn ContextStrategy>]>: Send,
Arc<Mutex<Option<AgentArchive>>>: Send,
Arc<Inner>: Send,
Arc<Mutex<Option<CallTools>>>: Send,
Arc<[Arc<dyn InterventionHandler>]>: Send,
impl Sync for LocalAgentwhere
RawVecInner: Sync,
OnceLock<String>: Sync,
Arc<RwLock<Map<String, Value>>>: Sync,
RawTable<usize>: Sync,
Arc<dyn Error + Send + Sync>: Sync,
Arc<dyn Model>: Sync,
Arc<dyn Tool>: Sync,
Arc<Shared>: Sync,
Arc<[Source]>: Sync,
Arc<Mutex<Meter>>: Sync,
Arc<Tracer>: Sync,
Arc<HookRegistry>: Sync,
Arc<MiddlewareRegistry>: Sync,
Arc<Mutex<InterruptStateData>>: Sync,
Arc<BackgroundTasks>: Sync,
Arc<dyn Sandbox>: Sync,
Arc<dyn Storage>: Sync,
Arc<[Arc<dyn ContextStrategy>]>: Sync,
Arc<Mutex<Option<AgentArchive>>>: Sync,
Arc<Inner>: Sync,
Arc<Mutex<Option<CallTools>>>: Sync,
Arc<[Arc<dyn InterventionHandler>]>: Sync,
impl Unpin for LocalAgentwhere
*const u8 is !null: Unpin,
Align4<u32>: Unpin,
Arc<RwLock<Map<String, Value>>>: Unpin,
Arc<dyn Error + Send + Sync>: Unpin,
Arc<dyn Model>: Unpin,
Arc<dyn Tool>: Unpin,
Arc<Shared>: Unpin,
Arc<[Source]>: Unpin,
Arc<Mutex<Meter>>: Unpin,
Arc<Tracer>: Unpin,
Arc<HookRegistry>: Unpin,
Arc<MiddlewareRegistry>: Unpin,
Arc<Mutex<InterruptStateData>>: Unpin,
Arc<BackgroundTasks>: Unpin,
Arc<dyn Sandbox>: Unpin,
Arc<dyn Storage>: Unpin,
Arc<[Arc<dyn ContextStrategy>]>: Unpin,
Arc<Mutex<Option<AgentArchive>>>: Unpin,
Arc<Inner>: Unpin,
Arc<Mutex<Option<CallTools>>>: Unpin,
Arc<[Arc<dyn InterventionHandler>]>: Unpin,
impl UnsafeUnpin for LocalAgentwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Align4<u32>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
*const ArcInner<RwLock<Map<String, Value>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<Map<String, Value>>>>: UnsafeUnpin,
PhantomData<Message>: UnsafeUnpin,
PhantomData<SystemContentBlock>: UnsafeUnpin,
*const ArcInner<dyn Model> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Model>>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, Arc<dyn Tool>>>: UnsafeUnpin,
*const ArcInner<Shared> is !null: UnsafeUnpin,
PhantomData<ArcInner<Shared>>: UnsafeUnpin,
*const ArcInner<[Source]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[Source]>>: UnsafeUnpin,
*const ArcInner<Mutex<Meter>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Meter>>>: UnsafeUnpin,
*const ArcInner<Tracer> is !null: UnsafeUnpin,
PhantomData<ArcInner<Tracer>>: UnsafeUnpin,
*const ArcInner<HookRegistry> is !null: UnsafeUnpin,
PhantomData<ArcInner<HookRegistry>>: UnsafeUnpin,
*const ArcInner<MiddlewareRegistry> is !null: UnsafeUnpin,
PhantomData<ArcInner<MiddlewareRegistry>>: UnsafeUnpin,
*const ArcInner<Mutex<InterruptStateData>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<InterruptStateData>>>: UnsafeUnpin,
*const ArcInner<BackgroundTasks> is !null: UnsafeUnpin,
PhantomData<ArcInner<BackgroundTasks>>: UnsafeUnpin,
*const ArcInner<dyn Sandbox> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Sandbox>>: UnsafeUnpin,
*const ArcInner<dyn Storage> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Storage>>: UnsafeUnpin,
*const ArcInner<[Arc<dyn ContextStrategy>]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[Arc<dyn ContextStrategy>]>>: UnsafeUnpin,
*const ArcInner<Mutex<Option<AgentArchive>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<AgentArchive>>>>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
*const ArcInner<Mutex<Option<CallTools>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<CallTools>>>>: UnsafeUnpin,
*const ArcInner<[Arc<dyn InterventionHandler>]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[Arc<dyn InterventionHandler>]>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<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