Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }

Implementations§

Source§

impl Agent

Source

pub fn new( provider: Box<dyn Provider>, registry: Registry, approver: Arc<dyn Approver>, ctx: ToolCtx, cfg: AgentConfig, model: Option<String>, ) -> Result<Self>

Source

pub fn context(&self) -> &Arc<RunContext>

The context a bare Agent::run will use.

Source

pub fn ctx(&self) -> &ToolCtx

Source

pub fn ctx_mut(&mut self) -> &mut ToolCtx

Adjust the default context in place. Copy-on-write, so any run already holding a clone of the old context is unaffected.

Source

pub fn with_pricing(self, pricing: Option<Pricing>) -> Self

Attach per-million-token prices so cost budgets and reporting work.

Source

pub fn with_homeostat(self) -> Self

Sample run conditions on this agent’s own context.

Reaches every front-end that calls Agent::run, and deliberately not eval, batch or the replay probes — each of those supplies its own RunContext per case or per item, which leaves the snapshot off. That is the same boundary those paths already draw for MCP, hooks, learned rules and the outbox, and for the same reason: a measurement that varies with how busy the machine was is not a measurement.

Source

pub fn with_context_window(self, window: Option<u64>) -> Self

Source

pub fn context_window(&self) -> Option<u64>

Source

pub fn model(&self) -> &str

Source

pub fn registry(&self) -> &Registry

Source

pub fn registry_mut(&mut self) -> &mut Registry

Add a tool after the agent is built.

For tools that need something only the front-end has — ask_user needs somebody to ask, and core must not assume a terminal exists.

Source

pub fn provider_id(&self) -> &str

The provider’s own id (anthropic, local, …), for display.

Source

pub fn vision(&self) -> bool

Whether this agent’s provider will put an image in front of the model.

For a front-end deciding what to do with a file somebody attached: an image goes into the turn when the model can see, and is named as a path when it cannot. Asked here rather than answered by the encoders alone because the difference is whether a megabyte gets read, resized, base64’d and written into an append-only transcript for a model that will only ever be shown its filename.

Source

pub fn set_hooks(&mut self, hooks: Arc<HookSet>)

Install lifecycle hooks on the agent’s own context. Copy-on-write like Agent::set_approver, and for the same reason.

Source

pub fn set_outbox(&mut self, route: Arc<OutboxRoute>)

Route the configured tools through the outbox on the agent’s own context. Copy-on-write, like Agent::set_hooks.

Source

pub fn set_mailbox(&mut self, route: Arc<MailboxRoute>)

Deliver inter-agent mail to runs on the agent’s own context. Attaching this is the inbound accept decision — see crate::mailbox. Copy-on-write, like Agent::set_hooks.

Source

pub fn set_cache_contended(&mut self)

Declare that this agent’s requests interleave with other conversations on the same server, so prefix-cache eviction is expected rather than a regression. Set by drivers that build several agents over one provider (the gossip ensemble); everywhere else the sharp warning stays, because there a drop really does mean an invariant failed.

Source

pub fn set_approver(&mut self, approver: Arc<dyn Approver>)

Swap the approver the agent’s own context uses.

Copy-on-write, like Agent::ctx_mut: a run already holding a clone of the old context keeps the permissions it started under. Changing what a tool call is allowed to do while that call is in flight would be a worse surprise than waiting for the turn to end.

Source

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

The resolved system prompt actually being sent — not the config’s system_prompt, which may name a file rather than hold the text.

Source

pub fn config(&self) -> &AgentConfig

Source

pub async fn run( &self, convo: &mut Conversation, events: Option<UnboundedSender<AgentEvent>>, ) -> Result<RunOutcome>

Run until the model stops calling tools.

messages is the live conversation: it is appended to in place, so a REPL can call this repeatedly and keep the history.

Source

pub async fn run_in( &self, cx: &RunContext, convo: &mut Conversation, events: Option<UnboundedSender<AgentEvent>>, ) -> Result<RunOutcome>

Run against a caller-supplied context instead of the agent’s own.

The same agent — same provider connection, same registry, same prompt cache — can then serve concurrent runs that are jailed to different directories under different permissions.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Freeze for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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, <T as TryFrom<U>>::Error>

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