Skip to main content

AgentBuilder

Struct AgentBuilder 

Source
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

Source

pub fn new(id: impl Into<String>) -> AgentBuilder

Source

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.

Source

pub fn instructions(self, instructions: impl Into<String>) -> AgentBuilder

The system prompt. Sent first on every request and never compacted.

Source

pub fn provider(self, provider: impl Provider + 'static) -> AgentBuilder

Source

pub fn tool(self, tool: impl Tool + 'static) -> AgentBuilder

Source

pub fn tool_arc(self, tool: Arc<dyn Tool>) -> AgentBuilder

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn hook_arc(self, hook: Arc<dyn Hook>) -> AgentBuilder

Source

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.

Source

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.

Source

pub fn limits(self, limits: Limits) -> AgentBuilder

Source

pub fn stuck_detection(self, config: StuckConfig) -> AgentBuilder

Source

pub fn stop_when(self, condition: impl StopCondition + 'static) -> AgentBuilder

Source

pub fn event_sink(self, sink: impl EventSink + 'static) -> AgentBuilder

Source

pub fn event_sink_arc(self, sink: Arc<dyn EventSink>) -> AgentBuilder

AgentBuilder::event_sink for a sink that is shared.

Source

pub fn store(self, store: Arc<dyn RunStore>) -> AgentBuilder

Source

pub fn max_output_tokens(self, tokens: u32) -> AgentBuilder

Source

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.

Source

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

Source

pub fn tool_extensions(self, extensions: Extensions) -> AgentBuilder

Source

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 AgentBuilder

§

impl Move for AgentBuilder

§

impl Send for AgentBuilder
where 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 AgentBuilder
where 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 AgentBuilder

§

impl UnsafeUnpin for AgentBuilder

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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, !>

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