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