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

Source

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.

Source

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

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

Source

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

Source

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

Source

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

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

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

AgentBuilder::event_sink for a sink that is shared.

Source

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

Source

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

Source

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.

Source

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

Source

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

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