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>) -> AgentBuilder
Sourcepub fn model(self, model: impl Into<String>) -> AgentBuilder
pub fn model(self, model: impl Into<String>) -> AgentBuilder
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>) -> AgentBuilder
pub fn instructions(self, instructions: impl Into<String>) -> AgentBuilder
The system prompt. Sent first on every request and never compacted.
pub fn provider(self, provider: impl Provider + 'static) -> AgentBuilder
pub fn tool(self, tool: impl Tool + 'static) -> AgentBuilder
pub fn tool_arc(self, tool: Arc<dyn Tool>) -> AgentBuilder
Sourcepub fn deferred_tool_arc(self, tool: Arc<dyn Tool>) -> AgentBuilder
pub fn deferred_tool_arc(self, tool: Arc<dyn Tool>) -> AgentBuilder
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>,
) -> AgentBuilder
pub fn retired_tool( self, name: impl Into<String>, note: impl Into<String>, ) -> AgentBuilder
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) -> AgentBuilder
pub fn loaded_tools(self, loaded: LoadedTools) -> AgentBuilder
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) -> AgentBuilder
pub fn hook(self, hook: impl Hook + 'static) -> AgentBuilder
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>) -> AgentBuilder
Sourcepub fn attest(self, safeguard: Safeguard) -> AgentBuilder
pub fn attest(self, safeguard: Safeguard) -> AgentBuilder
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) -> AgentBuilder
pub fn allow_unguarded(self) -> AgentBuilder
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) -> AgentBuilder
pub fn stuck_detection(self, config: StuckConfig) -> AgentBuilder
pub fn stop_when(self, condition: impl StopCondition + 'static) -> AgentBuilder
pub fn event_sink(self, sink: impl EventSink + 'static) -> AgentBuilder
Sourcepub fn event_sink_arc(self, sink: Arc<dyn EventSink>) -> AgentBuilder
pub fn event_sink_arc(self, sink: Arc<dyn EventSink>) -> AgentBuilder
AgentBuilder::event_sink for a sink that is shared.
pub fn store(self, store: Arc<dyn RunStore>) -> AgentBuilder
pub fn max_output_tokens(self, tokens: u32) -> AgentBuilder
Sourcepub fn approval_key(self, key: [u8; 32]) -> AgentBuilder
pub fn approval_key(self, key: [u8; 32]) -> AgentBuilder
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) -> AgentBuilder
pub fn redaction_scope(self, scope: RedactionScope) -> AgentBuilder
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).
pub fn tool_extensions(self, extensions: Extensions) -> AgentBuilder
pub fn build(self) -> Result<Agent, BuildError>
Auto Trait Implementations§
impl !RefUnwindSafe for AgentBuilder
impl !UnwindSafe for AgentBuilder
impl Forget for AgentBuilder
impl Freeze for AgentBuilderwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<dyn Provider> is !null: Freeze,
PhantomData<ArcInner<dyn Provider>>: Freeze,
PhantomData<Arc<dyn Tool>>: Freeze,
PhantomData<(String, String)>: Freeze,
*const ArcInner<RwLock<BTreeSet<String>>> is !null: Freeze,
PhantomData<ArcInner<RwLock<BTreeSet<String>>>>: Freeze,
PhantomData<Arc<dyn Hook>>: Freeze,
PhantomData<Safeguard>: Freeze,
PhantomData<Arc<dyn StopCondition>>: Freeze,
PhantomData<Arc<dyn EventSink>>: Freeze,
*const ArcInner<dyn RunStore> is !null: Freeze,
PhantomData<ArcInner<dyn RunStore>>: Freeze,
PhantomData<(TypeId, Arc<dyn Any + Send + Sync>)>: Freeze,
*const ArcInner<RwLock<Vec<String>>> is !null: Freeze,
PhantomData<ArcInner<RwLock<Vec<String>>>>: Freeze,
impl Move for AgentBuilder
impl Send for AgentBuilderwhere
RawVecInner: Send,
Arc<dyn Provider>: Send,
Arc<dyn Tool>: Send,
RawTable<(String, String)>: Send,
Arc<RwLock<BTreeSet<String>>>: Send,
Arc<dyn Hook>: Send,
Arc<dyn StopCondition>: Send,
Arc<dyn EventSink>: Send,
Arc<dyn RunStore>: Send,
RawTable<(TypeId, Arc<dyn Any + Send + Sync>)>: Send,
Arc<RwLock<Vec<String>>>: Send,
impl Sync for AgentBuilderwhere
RawVecInner: Sync,
Arc<dyn Provider>: Sync,
Arc<dyn Tool>: Sync,
RawTable<(String, String)>: Sync,
Arc<RwLock<BTreeSet<String>>>: Sync,
Arc<dyn Hook>: Sync,
Arc<dyn StopCondition>: Sync,
Arc<dyn EventSink>: Sync,
Arc<dyn RunStore>: Sync,
RawTable<(TypeId, Arc<dyn Any + Send + Sync>)>: Sync,
Arc<RwLock<Vec<String>>>: Sync,
impl Unpin for AgentBuilderwhere
*const u8 is !null: Unpin,
Arc<dyn Provider>: Unpin,
Arc<dyn Tool>: Unpin,
Arc<RwLock<BTreeSet<String>>>: Unpin,
Arc<dyn Hook>: Unpin,
Arc<dyn StopCondition>: Unpin,
Arc<dyn EventSink>: Unpin,
Arc<dyn RunStore>: Unpin,
*const (): Unpin,
Arc<dyn Any + Send + Sync>: Unpin,
Arc<RwLock<Vec<String>>>: Unpin,
impl UnsafeUnpin for AgentBuilderwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<dyn Provider> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Provider>>: UnsafeUnpin,
PhantomData<Arc<dyn Tool>>: UnsafeUnpin,
PhantomData<(String, String)>: UnsafeUnpin,
*const ArcInner<RwLock<BTreeSet<String>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<BTreeSet<String>>>>: UnsafeUnpin,
PhantomData<Arc<dyn Hook>>: UnsafeUnpin,
PhantomData<Safeguard>: UnsafeUnpin,
PhantomData<Arc<dyn StopCondition>>: UnsafeUnpin,
PhantomData<Arc<dyn EventSink>>: UnsafeUnpin,
*const ArcInner<dyn RunStore> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn RunStore>>: UnsafeUnpin,
PhantomData<(TypeId, Arc<dyn Any + Send + Sync>)>: UnsafeUnpin,
*const ArcInner<RwLock<Vec<String>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<Vec<String>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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