pub struct Agent { /* private fields */ }Implementations§
Source§impl Agent
impl Agent
pub fn new( provider: Box<dyn Provider>, registry: Registry, approver: Arc<dyn Approver>, ctx: ToolCtx, cfg: AgentConfig, model: Option<String>, ) -> Result<Self>
Sourcepub fn context(&self) -> &Arc<RunContext> ⓘ
pub fn context(&self) -> &Arc<RunContext> ⓘ
The context a bare Agent::run will use.
pub fn ctx(&self) -> &ToolCtx
Sourcepub fn ctx_mut(&mut self) -> &mut ToolCtx
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.
Sourcepub fn with_pricing(self, pricing: Option<Pricing>) -> Self
pub fn with_pricing(self, pricing: Option<Pricing>) -> Self
Attach per-million-token prices so cost budgets and reporting work.
Sourcepub fn with_homeostat(self) -> Self
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.
pub fn with_context_window(self, window: Option<u64>) -> Self
pub fn context_window(&self) -> Option<u64>
pub fn model(&self) -> &str
pub fn registry(&self) -> &Registry
Sourcepub fn registry_mut(&mut self) -> &mut Registry
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.
Sourcepub fn provider_id(&self) -> &str
pub fn provider_id(&self) -> &str
The provider’s own id (anthropic, local, …), for display.
Sourcepub fn vision(&self) -> bool
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.
Sourcepub fn set_hooks(&mut self, hooks: Arc<HookSet>)
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.
Sourcepub fn set_outbox(&mut self, route: Arc<OutboxRoute>)
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.
Sourcepub fn set_mailbox(&mut self, route: Arc<MailboxRoute>)
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.
Sourcepub fn set_cache_contended(&mut self)
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.
Sourcepub fn set_approver(&mut self, approver: Arc<dyn Approver>)
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.
Sourcepub fn system(&self) -> Option<&str>
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.
pub fn config(&self) -> &AgentConfig
Sourcepub async fn run(
&self,
convo: &mut Conversation,
events: Option<UnboundedSender<AgentEvent>>,
) -> Result<RunOutcome>
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.
Sourcepub async fn run_in(
&self,
cx: &RunContext,
convo: &mut Conversation,
events: Option<UnboundedSender<AgentEvent>>,
) -> Result<RunOutcome>
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.