Skip to main content

AgentBuilder

Struct AgentBuilder 

Source
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, ()>

Source

pub fn new(llm: LLM) -> Self

Creates a new agent builder with default configuration.

All model tiers (advanced/balanced/fast) use the same model.

Source§

impl<Advanced, Balanced, Fast, H> AgentBuilder<Advanced, Balanced, Fast, H>
where Advanced: LanguageModel, Balanced: LanguageModel, Fast: LanguageModel, H: Hook,

Source

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.

Source

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.

Source

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();
Source

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.

Source

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.

Source

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, ()>>>
Source

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.

Source

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.

Source

pub const fn context_strategy(self, strategy: ContextStrategy) -> Self

Sets the context compression strategy.

Source

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

Sets an optional persona overlay prompt.

Source

pub const fn agent_kind(self, kind: AgentKind) -> Self

Sets agent kind (coding or chatbot).

Source

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

Sets transcript path for long-memory recovery guidance.

Source

pub fn transcript(self, path: impl Into<PathBuf>) -> Self

Enables writing a readable transcript to the given path.

Source

pub fn sandbox_dir(self, path: impl Into<PathBuf>) -> Self

Sets sandbox directory for working document supervision.

Source

pub fn system<T: Serialize>(self, value: T) -> Self

Inserts or replaces a typed persistent system block.

Source

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.

Source

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.

Source

pub fn terminal<P, E, State>( self, terminal_tool: TerminalTool<P, E, State>, ) -> Self
where 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.

Source

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

Sets the full agent configuration.

Source

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.

Source

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.

Source

pub fn build(self) -> Agent<Advanced, Balanced, Fast, H>

Builds the agent.

Trait Implementations§

Source§

impl<Advanced, Balanced, Fast, H> Debug for AgentBuilder<Advanced, Balanced, Fast, H>

Source§

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

Formats the value using the given formatter. Read more

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>
where Advanced: Freeze, Balanced: Freeze, Fast: Freeze, H: Freeze,

§

impl<Advanced, Balanced, Fast, H> Send for AgentBuilder<Advanced, Balanced, Fast, H>
where Advanced: Send, Balanced: Send, Fast: Send, H: Send,

§

impl<Advanced, Balanced, Fast, H> Sync for AgentBuilder<Advanced, Balanced, Fast, H>
where Advanced: Sync, Balanced: Sync, Fast: Sync, H: Sync,

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
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 = !

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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