pub struct AgentBuilder<Advanced, Balanced = Advanced, Fast = Balanced, H = ()> { /* private fields */ }Expand description
Builder for constructing agents with custom configuration.
Supports tiered LLM configuration:
- Advanced: Primary model for main reasoning (most capable)
- Balanced: Model for moderate tasks like subagents (defaults to advanced)
- Fast: Model for quick tasks like compaction (defaults to balanced)
§Example
// Simple: all tiers use the same model
let agent = Agent::builder(claude).build();
// Tiered: different models for different tasks
let agent = Agent::builder(opus) // Advanced
.balanced_model(sonnet) // Balanced
.fast_model(haiku) // Fast
.system_prompt("You are a helpful assistant.")
.tool(FileSystemTool::read_only("."))
.build();Implementations§
Source§impl<LLM: LanguageModel + Clone> AgentBuilder<LLM, LLM, LLM, ()>
impl<LLM: LanguageModel + Clone> AgentBuilder<LLM, LLM, LLM, ()>
Source§impl<Advanced, Balanced, Fast, H> AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced, Fast, H> AgentBuilder<Advanced, Balanced, Fast, H>
Sourcepub fn balanced_model<B2: LanguageModel>(
self,
model: B2,
) -> AgentBuilder<Advanced, B2, Fast, H>
pub fn balanced_model<B2: LanguageModel>( self, model: B2, ) -> AgentBuilder<Advanced, B2, Fast, H>
Sets the balanced model for moderate tasks (e.g., subagents).
This model is used when spawning subagents that don’t need the full capabilities of the advanced model.
Sourcepub fn fast_model<F2: LanguageModel>(
self,
model: F2,
) -> AgentBuilder<Advanced, Balanced, F2, H>
pub fn fast_model<F2: LanguageModel>( self, model: F2, ) -> AgentBuilder<Advanced, Balanced, F2, H>
Sets the fast model for quick tasks (e.g., compaction, ask command).
This model is used for tasks where speed and cost matter more than capability, such as context compression.
Sourcepub const fn tier(self, tier: ModelTier) -> Self
pub const fn tier(self, tier: ModelTier) -> Self
Sets which model tier to use for the agent’s main reasoning loop.
This allows creating subagents that use different capability levels:
ModelTier::Advanced: Use the most capable model (default)ModelTier::Balanced: Use the balanced model (good for subagents)ModelTier::Fast: Use the fast model (for quick tasks)
§Example
// Create an explore subagent using the balanced model
let explore_agent = Agent::builder(opus)
.balanced_model(sonnet)
.fast_model(haiku)
.tier(ModelTier::Balanced) // Use sonnet for reasoning
.build();Sourcepub fn tool<T: Tool + 'static>(self, tool: T) -> Self
pub fn tool<T: Tool + 'static>(self, tool: T) -> Self
Registers an eager (always-loaded) tool.
Eager tools are included in every LLM request.
§Panics
Panics if the tool cannot be registered: another tool already uses its name, or it carries no description for the model to read. Both are mistakes in the calling program.
Sourcepub fn dyn_terminal(self, dyn_tool: DynTerminalTool) -> Self
pub fn dyn_terminal(self, dyn_tool: DynTerminalTool) -> Self
Registers a dynamic terminal tool (type-erased).
This is used for child terminal capability bundles in subagents where the concrete terminal type is not known at compile time.
Sourcepub fn hook<NH: Hook>(
self,
hook: NH,
) -> AgentBuilder<Advanced, Balanced, Fast, HCons<NH, H>>
pub fn hook<NH: Hook>( self, hook: NH, ) -> AgentBuilder<Advanced, Balanced, Fast, HCons<NH, H>>
Adds a hook to intercept agent operations.
Hooks are composed using the HCons pattern, allowing multiple
hooks to be chained at compile time.
§Example
let agent = Agent::builder(llm)
.hook(LoggingHook)
.hook(ConfirmationHook)
.build();
// Type: Agent<LLM, HCons<ConfirmationHook, HCons<LoggingHook, ()>>>Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Sets the system prompt.
The system prompt is prepended to every conversation and remains stable for prompt caching.
Sourcepub const fn max_iterations(self, limit: usize) -> Self
pub const fn max_iterations(self, limit: usize) -> Self
Sets the maximum number of iterations (turns).
The agent will stop and return an error if this limit is exceeded.
Sourcepub const fn context_strategy(self, strategy: ContextStrategy) -> Self
pub const fn context_strategy(self, strategy: ContextStrategy) -> Self
Sets the context compression strategy.
Sourcepub fn persona_prompt(self, prompt: impl Into<String>) -> Self
pub fn persona_prompt(self, prompt: impl Into<String>) -> Self
Sets an optional persona overlay prompt.
Sourcepub const fn agent_kind(self, kind: AgentKind) -> Self
pub const fn agent_kind(self, kind: AgentKind) -> Self
Sets agent kind (coding or chatbot).
Sourcepub fn transcript_path(self, path: impl Into<String>) -> Self
pub fn transcript_path(self, path: impl Into<String>) -> Self
Sets transcript path for long-memory recovery guidance.
Sourcepub fn transcript(self, path: impl Into<PathBuf>) -> Self
pub fn transcript(self, path: impl Into<PathBuf>) -> Self
Enables writing a readable transcript to the given path.
Sourcepub fn sandbox_dir(self, path: impl Into<PathBuf>) -> Self
pub fn sandbox_dir(self, path: impl Into<PathBuf>) -> Self
Sets sandbox directory for working document supervision.
Sourcepub fn system<T: Serialize>(self, value: T) -> Self
pub fn system<T: Serialize>(self, value: T) -> Self
Inserts or replaces a typed persistent system block.
Sourcepub fn system_named(
self,
tag: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn system_named( self, tag: impl Into<String>, content: impl Into<String>, ) -> Self
Inserts or replaces a persistent system block with an explicit tag.
Sourcepub fn system_text(
self,
tag: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn system_text( self, tag: impl Into<String>, content: impl Into<String>, ) -> Self
Inserts or replaces a persistent system block with raw text.
Unlike system and system_named,
the content is stored verbatim without any XML wrapping. This is the
preferred entry point for prose system blocks (workspace descriptions,
runtime metadata, environment hints) where XML structure adds tokens
without providing semantic value.
Sourcepub fn terminal<P, E, State>(
self,
terminal_tool: TerminalTool<P, E, State>,
) -> Selfwhere
P: PermissionHandler + 'static,
E: Executor + Clone + 'static,
State: Clone + 'static,
TerminalTool<P, E, State>: Tool + 'static,
pub fn terminal<P, E, State>(
self,
terminal_tool: TerminalTool<P, E, State>,
) -> Selfwhere
P: PermissionHandler + 'static,
E: Executor + Clone + 'static,
State: Clone + 'static,
TerminalTool<P, E, State>: Tool + 'static,
Registers the terminal tool for command execution in a sandbox.
The terminal tool enables command execution with configurable permission modes (sandboxed, network, unsafe). It creates its own working directory with four random words and manages output storage internally.
This also captures the background task receiver for polling completed background tasks during the agent loop.
§Example
use aither_sandbox::{TerminalTool, ToolRegistryBuilder, permission::DenyUnsafe};
use std::sync::Arc;
// Create terminal tool (creates random working dir like amber-forest-thunder-pearl/)
let terminal_tool = TerminalTool::new_in(parent, DenyUnsafe, executor).await?;
let registry = Arc::new(ToolRegistryBuilder::new().build(terminal_tool.outputs_dir()));
let terminal_tool = terminal_tool.with_registry(registry);
let agent = Agent::builder(llm)
.terminal(terminal_tool)
.build();§Panics
Panics if the tool cannot be registered: another tool already uses its name, or it carries no description for the model to read. Both are mistakes in the calling program.
Sourcepub fn config(self, config: AgentConfig) -> Self
pub fn config(self, config: AgentConfig) -> Self
Sets the full agent configuration.
Sourcepub fn todo(self) -> Self
pub fn todo(self) -> Self
Enables todo list tracking for managing long tasks.
When enabled, the agent will:
- Inject the current todo list into the context before each LLM request
- Generate system reminders when tasks are completed
§Example
let agent = Agent::builder(llm)
.todo()
.build();§Panics
Panics if the tool cannot be registered: another tool already uses its name, or it carries no description for the model to read. Both are mistakes in the calling program.
Sourcepub fn todo_with_list(self, list: TodoList) -> Self
pub fn todo_with_list(self, list: TodoList) -> Self
Enables todo list tracking with a shared list.
Use this when you want to share a todo list between multiple agents or access the list externally.
§Panics
Panics if the tool cannot be registered: another tool already uses its name, or it carries no description for the model to read. Both are mistakes in the calling program.
Trait Implementations§
Auto Trait Implementations§
impl<Advanced, Balanced = Advanced, Fast = Balanced, H = ()> !RefUnwindSafe for AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced = Advanced, Fast = Balanced, H = ()> !Unpin for AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced = Advanced, Fast = Balanced, H = ()> !UnsafeUnpin for AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced = Advanced, Fast = Balanced, H = ()> !UnwindSafe for AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced, Fast, H> Freeze for AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced, Fast, H> Send for AgentBuilder<Advanced, Balanced, Fast, H>
impl<Advanced, Balanced, Fast, H> Sync for AgentBuilder<Advanced, Balanced, Fast, H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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