Skip to main content

AgentBuilder

Struct AgentBuilder 

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

Ergonomic constructor for AgentConfig. Required inputs are passed to AgentBuilder::new; every other field defaults to the same values the nitpicker review path uses, and is overridable via the chainable setters. Use AgentBuilder::build for a raw config or AgentBuilder::run to execute in one call.

Concurrency note: each builder defaults to its own Semaphore::new(MAX_CONCURRENT_LLM_CALLS), so it bounds in-flight LLM calls within one agent (and its subagents) but not across independent builders — N agents can run N × MAX_CONCURRENT_LLM_CALLS calls at once. To cap aggregate concurrency account-wide, share one Arc<Semaphore> via AgentBuilder::llm_semaphore.

Implementations§

Source§

impl AgentBuilder

Source

pub fn new( name: impl Into<String>, model: impl Into<String>, system_prompt: impl Into<String>, client: Arc<dyn LLMClientDyn>, ) -> Self

Source

pub fn max_turns(self, max_turns: usize) -> Self

Source

pub fn compact_threshold(self, threshold: u64) -> Self

Source

pub fn max_tokens(self, max_tokens: NonZeroU64) -> Self

Cap the output of each turn. Unset by default, which leaves the provider’s own per-model limit to apply; set it only to bound spend, since a cap below what the model reasons through returns empty content rather than a shorter answer. NonZeroU64 because a zero cap asks for a response the provider answers with nothing at all.

Source

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

Override the system prompt spawned subagents run with (default: the built-in generic prompt). The override propagates through nested subagent spawns.

Source

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

Extra context appended to the system prompt (e.g. a project summary).

Source

pub fn llm_semaphore(self, semaphore: Arc<Semaphore>) -> Self

Share a concurrency limiter across agents instead of the per-builder default (Semaphore::new(MAX_CONCURRENT_LLM_CALLS)), to cap aggregate in-flight LLM calls.

Source

pub fn progress( self, progress: Arc<dyn Fn(AgentProgress) + Send + Sync>, ) -> Self

Source

pub fn build(self) -> AgentConfig

Source

pub async fn run( self, initial_message: &str, tools: &HashMap<String, Arc<dyn Tool>>, work_dir: &Path, ) -> Result<AgentResult>

Build and run the agent to completion.

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> 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: Sized + 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: Sized + 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> 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<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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