Skip to main content

AgentBuilder

Struct AgentBuilder 

Source
pub struct AgentBuilder { /* private fields */ }
Expand description

Fluent assembly of one canonical Agent.

Registration failures are retained and returned by Self::build so Tool and child Agent calls remain chainable without silently replacing an existing name.

Implementations§

Source§

impl AgentBuilder

Source

pub fn new( name: impl Into<String>, model: Arc<dyn Model>, model_ref: ModelRef, ) -> Self

Creates a builder around the same execution path as Agent::new.

Source

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

Appends a system instruction.

Source

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

Adds one static document as untrusted user-level context.

The document is never promoted to a system instruction. Use Self::system for trusted application policy.

Source

pub fn context_document(self, document: Document) -> Self

Adds one validated static context document.

Source

pub fn artifacts( self, scope: ArtifactScope, store: Arc<dyn ArtifactStore>, ) -> Self

Configures reference-only artifact persistence for Tools and resolves those references only at the final model transport boundary.

Source

pub fn dynamic_context<R>(self, limit: usize, retriever: R) -> Self
where R: Retriever + 'static,

Adds an owned dynamic context source.

Source

pub fn shared_dynamic_context( self, limit: usize, retriever: Arc<dyn Retriever>, ) -> Self

Adds a shared, type-erased dynamic context source.

Source

pub fn tool<T>(self, tool: T) -> Self
where T: Tool + 'static,

Registers an owned Tool.

Source

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

Registers a shared, type-erased Tool.

Source

pub fn child( self, descriptor: AgentDescriptor, child: Arc<Agent>, capabilities: CapabilitySet, ) -> Self

Registers a child Agent route with explicit delegated capabilities.

Source

pub fn gateway_layer(self, middleware: Arc<dyn GatewayMiddleware>) -> Self

Appends Gateway around-middleware.

Source

pub fn max_delegation_depth(self, max_depth: u32) -> Self

Sets the maximum nested Agent delegation depth.

Source

pub const fn max_turns(self, max_turns: u32) -> Self

Sets the local model-turn limit.

Source

pub const fn min_successful_tool_calls(self, minimum: u32) -> Self

Requires this many successful local Tool calls before terminal output.

The runtime requests at least one Tool while the requirement remains unsatisfied and returns an explicit error if the model violates that contract. A value of zero disables the requirement.

Source

pub const fn tool_error_policy(self, policy: ToolErrorPolicy) -> Self

Sets Tool failure behavior.

Source

pub fn completion_requirement(self, requirement: CompletionRequirement) -> Self

Sets terminal validation and bounded repair behavior.

Source

pub const fn feature_policy(self, policy: FeaturePolicy) -> Self

Sets provider feature-degradation behavior.

Source

pub fn output_format(self, output_format: OutputFormat) -> Self

Sets the desired terminal model-output format.

Source

pub fn structured_output<T>(self, name: impl Into<String>) -> Self
where T: JsonSchema,

Requests strict structured output described by the Rust type T.

Source

pub fn provider_tool(self, tool: ProviderToolSpec) -> Self

Adds a provider-hosted tool such as Ark web search.

Source

pub fn generation(self, generation: GenerationOptions) -> Self

Replaces common model generation controls for every Agent turn.

Source

pub fn temperature(self, temperature: f64) -> Self

Sets the sampling temperature for every Agent turn.

Source

pub fn top_p(self, top_p: f64) -> Self

Sets nucleus sampling for every Agent turn.

Source

pub fn max_output_tokens(self, max_output_tokens: u64) -> Self

Sets the maximum number of output tokens for every Agent turn.

Source

pub const fn response_mode(self, response_mode: ResponseMode) -> Self

Selects streaming or complete response delivery for every Agent turn.

Source

pub fn provider_options( self, provider: impl Into<String>, options: Value, ) -> Self

Adds namespaced provider options to every Agent turn.

Source

pub const fn config(self, config: AgentConfig) -> Self

Replaces all local Agent configuration.

Source

pub fn effect_executor(self, effects: EffectExecutor) -> Self

Shares a write-ahead effect coordinator with this Agent.

Source

pub const fn effect_recovery_policy(self, policy: EffectRecoveryPolicy) -> Self

Sets recovery behavior for ambiguous callable effects.

Source

pub fn build(self) -> Result<Agent, AgentBuildError>

Validates registrations and returns the canonical Agent.

§Errors

Returns AgentBuildError for blank identity, invalid turn bounds, duplicate registrations, or Tool/Agent name collisions.

Source

pub fn prompt( self, input: impl Into<String> + Send + 'static, ) -> AgentFuture<'static, Result<AgentOutcome, AgentPromptError>>

Builds the Agent and runs one ergonomic prompt.

This removes the explicit build step for one-shot usage while retaining the complete canonical outcome. Use Self::build when the Agent will be reused or executed with an explicit runtime context.

Source

pub fn prompt_text( self, input: impl Into<String> + Send + 'static, ) -> AgentFuture<'static, Result<String, AgentPromptError>>

Builds the Agent, runs one ergonomic prompt, and returns only model-visible text.

This is the shortest path from provider configuration to a text answer. Use Self::prompt when transcript, usage, warnings, and provider events must be preserved.

Source

pub fn build_structured<T>( self, name: impl Into<String>, ) -> Result<StructuredAgent<T>, AgentBuildError>
where T: JsonSchema + DeserializeOwned + Send + 'static,

Builds an Agent whose schema and local decoder are bound to T.

This is the preferred terminal builder operation for structured output because a different decode type cannot be selected later by mistake.

§Errors

Returns AgentBuildError under the same validation rules as Self::build.

Trait Implementations§

Source§

impl Debug for AgentBuilder

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.