Skip to main content

AgentBuilder

Struct AgentBuilder 

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

Builder for constructing an Agent with a fluent API.

§Example

use traitclaw_core::prelude::*;
use traitclaw_core::agent_builder::AgentBuilder;

// Minimal agent (provider required):
// let agent = AgentBuilder::new()
//     .provider(my_provider)
//     .system("You are helpful")
//     .build()?;

Implementations§

Source§

impl AgentBuilder

Source

pub fn new() -> AgentBuilder

Create a new builder with default configuration.

Source

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

Set the LLM provider (required).

Prefer .model() for the idiomatic fluent-API usage. Both methods are equivalent; .model() matches the agent.model() pattern described in the architecture docs.

Source

pub fn provider_arc(self, provider: Arc<dyn Provider>) -> AgentBuilder

Set the LLM provider from a pre-wrapped Arc<dyn Provider>.

Use this when you already hold a shared provider reference (e.g., from AgentFactory).

Source

pub fn model(self, provider: impl Provider) -> AgentBuilder

Set the LLM provider — preferred alias for .provider().

Enables the idiomatic Agent::builder().model(provider).system("...").build() pattern.

Source

pub fn with_retry(self, config: RetryConfig) -> AgentBuilder

Wrap the configured provider with automatic retry and exponential backoff.

Must be called after .provider() or .model(). Uses RetryProvider internally.

Source

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

Set the system prompt.

Source

pub fn tool(self, tool: impl ErasedTool) -> AgentBuilder

Add a tool to the agent.

Source

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

Add a pre-wrapped Arc<dyn ErasedTool> directly.

Use this when you already hold a shared tool instance that you want to attach to multiple agents without cloning the underlying value.

Source

pub fn tools<I, T>(self, tools: I) -> AgentBuilder
where I: IntoIterator<Item = T>, T: ErasedTool,

Add multiple tools at once.

Source

pub fn tools_arc<I>(self, tools: I) -> AgentBuilder
where I: IntoIterator<Item = Arc<dyn ErasedTool>>,

Add multiple pre-wrapped Arc<dyn ErasedTool> instances at once.

Source

pub fn memory(self, memory: impl Memory) -> AgentBuilder

Set the memory backend.

Source

pub fn guard(self, guard: impl Guard) -> AgentBuilder

Add a guard to the agent.

Source

pub fn hint(self, hint: impl Hint) -> AgentBuilder

Add a hint to the agent.

Source

pub fn tracker(self, tracker: impl Tracker) -> AgentBuilder

Set the tracker for runtime monitoring.

Source

pub fn max_iterations(self, max: u32) -> AgentBuilder

Set the maximum number of tool call iterations.

Source

pub fn max_tokens(self, max: u32) -> AgentBuilder

Set the maximum tokens for LLM responses.

Source

pub fn temperature(self, temp: f32) -> AgentBuilder

Set the sampling temperature.

Source

pub fn token_budget(self, budget: usize) -> AgentBuilder

Set the token budget for the entire run.

Source

pub fn context_manager( self, manager: impl ContextManager + 'static, ) -> AgentBuilder

Set the async context window manager.

Supports LLM-powered compression and accurate token counting. Default: RuleBasedCompressor.

Source

pub fn execution_strategy( self, strategy: impl ExecutionStrategy + 'static, ) -> AgentBuilder

Set the tool execution strategy.

Default: SequentialStrategy (one at a time). Use ParallelStrategy for concurrent execution.

Source

pub fn output_transformer( self, transformer: impl OutputTransformer + 'static, ) -> AgentBuilder

Set the async tool output transformer.

Supports context-aware, async tool output processing. Default: BudgetAwareTruncator (10,000 chars).

Source

pub fn tool_registry( self, registry: impl ToolRegistry + 'static, ) -> AgentBuilder

Set the dynamic tool registry (v0.3.0).

Enables runtime tool activation/deactivation. Default: SimpleRegistry wrapping configured tools.

Source

pub fn strategy(self, strategy: impl AgentStrategy) -> AgentBuilder

Set the agent execution strategy.

Default: DefaultStrategy (preserves v0.1.0 loop behavior). Implement AgentStrategy for custom reasoning architectures.

Source

pub fn hook(self, hook: impl AgentHook) -> AgentBuilder

Add a lifecycle hook for observability and interception.

Multiple hooks can be registered and are called sequentially.

§Example
use traitclaw_core::traits::hook::LoggingHook;

// Agent::builder()
//     .model(my_provider)
//     .hook(LoggingHook::new(tracing::Level::INFO))
//     .build()
Source

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

Build the agent. Returns an error if no provider is configured.

§Errors

Returns Error::Config if no provider has been set.

Trait Implementations§

Source§

impl Default for AgentBuilder

Source§

fn default() -> AgentBuilder

Returns the “default value” for a type. 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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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, 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.
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