pub struct AgentBuilder { /* private fields */ }Expand description
Builder for Agent. provider and model are required, and an agent
with tools must cover every Safeguard::REQUIRED safeguard (see
AgentBuilder::attest and AgentBuilder::allow_unguarded).
Implementations§
Source§impl AgentBuilder
impl AgentBuilder
pub fn new(id: impl Into<String>) -> Self
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
The model id sent with every request. Unset, the provider’s
Provider::default_model is used, and building fails with
BuildError::MissingModel when it has none.
Sourcepub fn instructions(self, instructions: impl Into<String>) -> Self
pub fn instructions(self, instructions: impl Into<String>) -> Self
The system prompt. Sent first on every request and never compacted.
pub fn provider(self, provider: impl Provider + 'static) -> Self
pub fn tool(self, tool: impl Tool + 'static) -> Self
pub fn tool_arc(self, tool: Arc<dyn Tool>) -> Self
Sourcepub fn deferred_tool_arc(self, tool: Arc<dyn Tool>) -> Self
pub fn deferred_tool_arc(self, tool: Arc<dyn Tool>) -> Self
Register a tool whose schema is sent only once loaded: until then
the built-in load_tools lists it by name and one line. Calling it
directly loads it too. See crate::LOAD_TOOLS and
crate::LoadedTools.
Sourcepub fn retired_tool(
self,
name: impl Into<String>,
note: impl Into<String>,
) -> Self
pub fn retired_tool( self, name: impl Into<String>, note: impl Into<String>, ) -> Self
A tool that no longer exists: a call to name is refused as an
unknown tool, with note (where its work went) in the refusal.
Sourcepub fn loaded_tools(self, loaded: LoadedTools) -> Self
pub fn loaded_tools(self, loaded: LoadedTools) -> Self
The set of loaded deferred tools. Share one across a session’s runs so a tool loaded once stays loaded (and the tool block stable).
Sourcepub fn hook(self, hook: impl Hook + 'static) -> Self
pub fn hook(self, hook: impl Hook + 'static) -> Self
Hooks run in registration order. Register a hook that interrupts
(such as crate::UntrustedHook) last so a human or verifier sees
only calls the other hooks already allowed.
pub fn hook_arc(self, hook: Arc<dyn Hook>) -> Self
Sourcepub fn attest(self, safeguard: Safeguard) -> Self
pub fn attest(self, safeguard: Safeguard) -> Self
Declare that safeguard is enforced outside the hooks, for example
by the application’s own tool adapter. This is a statement the
composition root makes on purpose, so it is reviewable in one place.
Sourcepub fn allow_unguarded(self) -> Self
pub fn allow_unguarded(self) -> Self
Build without the Safeguard::REQUIRED check: for tests, demos
and tools that only touch data the agent fully controls.
pub fn limits(self, limits: Limits) -> Self
pub fn stuck_detection(self, config: StuckConfig) -> Self
pub fn stop_when(self, condition: impl StopCondition + 'static) -> Self
pub fn event_sink(self, sink: impl EventSink + 'static) -> Self
Sourcepub fn event_sink_arc(self, sink: Arc<dyn EventSink>) -> Self
pub fn event_sink_arc(self, sink: Arc<dyn EventSink>) -> Self
AgentBuilder::event_sink for a sink that is shared.
pub fn store(self, store: Arc<dyn RunStore>) -> Self
pub fn max_output_tokens(self, tokens: u32) -> Self
Sourcepub fn approval_key(self, key: [u8; 32]) -> Self
pub fn approval_key(self, key: [u8; 32]) -> Self
Application values every tool call can read from
crate::ToolContext::extensions. Replaces any earlier set.
The key approval digests are made with
(crate::Interruption::digest). Without one each process uses its
own random key, so an approval saved by one process and resumed by
another is not honored: its call is judged again and the owner asked
again. Give every process that resumes the same runs the same secret
key to honor approvals across them.
Sourcepub fn redaction_scope(self, scope: RedactionScope) -> Self
pub fn redaction_scope(self, scope: RedactionScope) -> Self
The registered secrets this agent’s runs redact (see
crate::redaction). The default is the process-wide set
(RedactionScope::process),
where every secret store registers what it hands out. Give an agent
RedactionScope::isolated
to keep its secrets from other agents’ runs and theirs from its own,
as a test should, and register its secrets there (its secret store
and Redactor take the same scope).