pub struct AgentBuilder { /* private fields */ }Expand description
Implementations§
Source§impl AgentBuilder
impl AgentBuilder
Sourcepub fn new() -> AgentBuilder
pub fn new() -> AgentBuilder
Create a new builder with default configuration.
Sourcepub fn provider(self, provider: impl Provider) -> AgentBuilder
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.
Sourcepub fn provider_arc(self, provider: Arc<dyn Provider>) -> AgentBuilder
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).
Sourcepub fn model(self, provider: impl Provider) -> AgentBuilder
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.
Sourcepub fn with_retry(self, config: RetryConfig) -> AgentBuilder
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.
Sourcepub fn system(self, prompt: impl Into<String>) -> AgentBuilder
pub fn system(self, prompt: impl Into<String>) -> AgentBuilder
Set the system prompt.
Sourcepub fn tool(self, tool: impl ErasedTool) -> AgentBuilder
pub fn tool(self, tool: impl ErasedTool) -> AgentBuilder
Add a tool to the agent.
Sourcepub fn tool_arc(self, tool: Arc<dyn ErasedTool>) -> AgentBuilder
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.
Sourcepub fn tools<I, T>(self, tools: I) -> AgentBuilderwhere
I: IntoIterator<Item = T>,
T: ErasedTool,
pub fn tools<I, T>(self, tools: I) -> AgentBuilderwhere
I: IntoIterator<Item = T>,
T: ErasedTool,
Add multiple tools at once.
Sourcepub fn tools_arc<I>(self, tools: I) -> AgentBuilder
pub fn tools_arc<I>(self, tools: I) -> AgentBuilder
Add multiple pre-wrapped Arc<dyn ErasedTool> instances at once.
Sourcepub fn memory(self, memory: impl Memory) -> AgentBuilder
pub fn memory(self, memory: impl Memory) -> AgentBuilder
Set the memory backend.
Sourcepub fn guard(self, guard: impl Guard) -> AgentBuilder
pub fn guard(self, guard: impl Guard) -> AgentBuilder
Add a guard to the agent.
Sourcepub fn hint(self, hint: impl Hint) -> AgentBuilder
pub fn hint(self, hint: impl Hint) -> AgentBuilder
Add a hint to the agent.
Sourcepub fn tracker(self, tracker: impl Tracker) -> AgentBuilder
pub fn tracker(self, tracker: impl Tracker) -> AgentBuilder
Set the tracker for runtime monitoring.
Sourcepub fn max_iterations(self, max: u32) -> AgentBuilder
pub fn max_iterations(self, max: u32) -> AgentBuilder
Set the maximum number of tool call iterations.
Sourcepub fn max_tokens(self, max: u32) -> AgentBuilder
pub fn max_tokens(self, max: u32) -> AgentBuilder
Set the maximum tokens for LLM responses.
Sourcepub fn temperature(self, temp: f32) -> AgentBuilder
pub fn temperature(self, temp: f32) -> AgentBuilder
Set the sampling temperature.
Sourcepub fn token_budget(self, budget: usize) -> AgentBuilder
pub fn token_budget(self, budget: usize) -> AgentBuilder
Set the token budget for the entire run.
Sourcepub fn context_manager(
self,
manager: impl ContextManager + 'static,
) -> AgentBuilder
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.
Sourcepub fn execution_strategy(
self,
strategy: impl ExecutionStrategy + 'static,
) -> AgentBuilder
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.
Sourcepub fn output_transformer(
self,
transformer: impl OutputTransformer + 'static,
) -> AgentBuilder
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).
Sourcepub fn tool_registry(
self,
registry: impl ToolRegistry + 'static,
) -> AgentBuilder
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.
Sourcepub fn strategy(self, strategy: impl AgentStrategy) -> AgentBuilder
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.
Sourcepub fn hook(self, hook: impl AgentHook) -> AgentBuilder
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()