Skip to main content

LocalAgent

Struct LocalAgent 

Source
#[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

Source

pub fn id(&self) -> &str

The agent’s unique id.

Source

pub fn name(&self) -> &str

The agent’s name.

Source

pub fn description(&self) -> Option<&str>

What the agent does.

Source

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.

Source

pub fn app_state(&self) -> &StateStore

App state shared with tools and application code.

Source

pub fn model_state(&self) -> &StateStore

The model provider’s runtime state, such as response ids of server-side conversations.

Source

pub fn messages(&self) -> &[Message]

The conversation history.

Source

pub fn messages_mut(&mut self) -> &mut Vec<Message>

The conversation history, to edit.

Source

pub fn system_prompt(&self) -> Option<&SystemPrompt>

The system prompt.

Source

pub fn set_system_prompt(&mut self, system_prompt: Option<SystemPrompt>)

Replaces or clears the system prompt.

Source

pub fn model(&self) -> &Arc<dyn Model> ⓘ

The model the agent calls.

Source

pub fn aux_model(&self) -> &Arc<dyn Model> ⓘ

The model for auxiliary side calls (summaries, classification); the agent’s model unless one was configured.

Source

pub fn agent_metadata(&self) -> Option<&AgentMetadata>

The metadata the agent passes to its model.

Source

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.

Source

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.

Source

pub fn tool_registry(&self) -> &ToolRegistry

The agent’s tools.

Source

pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry

The agent’s tools, to add or remove some.

Source

pub fn cancel_signal(&self) -> CancelSignal

The cancellation signal of the current invocation.

Source

pub fn cancel(&self, options: CancelOptions)

Cancels the current invocation (cancel); does nothing when the agent is idle.

Source

pub fn metrics(&self) -> AgentMetrics

Aggregated loop metrics of the agent: cycles, token usage and tool statistics.

Source

pub fn add_hook<K: HookEvent>( &self, callback: impl IntoSyncHook<K>, ) -> HookCleanup

Registers a hook closure; see HookRegistry::add_hook.

Source

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.

Source

pub fn add_async_hook<K: HookEvent>( &self, callback: impl IntoAsyncHook<K>, ) -> HookCleanup

Registers an async hook closure; see HookRegistry::add_async_hook.

Source

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.

Source

pub fn add_hook_impl<K: HookEvent>( &self, hook: impl IntoHookImpl<K>, ) -> HookCleanup

Registers a Hook implementation; see HookRegistry::add_hook_impl.

Source

pub fn add_hook_impl_with<K: HookEvent>( &self, hook: impl IntoHookImpl<K>, options: HookCallbackOptions, ) -> HookCleanup

Registers a Hook implementation with options.

Source

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

Source

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.

Source

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§

Source§

impl Debug for LocalAgent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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 LocalAgent
where 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 LocalAgent
where 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 LocalAgent
where *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 LocalAgent
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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