Skip to main content

AgentLoopBuilder

Struct AgentLoopBuilder 

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

Builder for constructing an AgentLoop with validated configuration.

Implementations§

Source§

impl AgentLoopBuilder

Source

pub fn max_iterations(self, n: usize) -> Self

Set the maximum number of LLM round-trips before aborting.

Source

pub fn tool(self, tool: Arc<dyn Tool>) -> Self

Register a tool with the agent loop.

Source

pub fn tools(self, tools: impl IntoIterator<Item = Arc<dyn Tool>>) -> Self

Register multiple tools at once.

Source

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

Set a static system prompt that is injected as a System message at the beginning of every conversation.

This is a convenience shortcut for registering a ContextProvider that always returns the given string.

Source

pub fn context(self, provider: impl ContextProvider + 'static) -> Self

Register a context provider that injects dynamic context into the conversation before each AgentLoop::run call.

Multiple providers can be registered; they are invoked in registration order and each non-empty result becomes a System message.

Source

pub fn contexts( self, providers: impl IntoIterator<Item = Box<dyn ContextProvider>>, ) -> Self

Register multiple context providers at once.

This is the batch equivalent of context(), mirroring the tools() / tool() pattern.

Source

pub fn tool_timeout(self, duration: Duration) -> Self

Set a per-tool-call timeout. When a tool takes longer than duration it returns a ToolResult::error("timed out") instead of blocking.

By default there is no timeout.

Source

pub fn tool_context(self, ctx: ToolContext) -> Self

Set a custom ToolContext that will be passed to every tool invocation.

By default, ToolContext::default() is used. Use this when tools need access to session-level state such as a working directory or environment variables.

Source

pub fn channel_config(self, config: ChannelConfig) -> Self

Set the full channel configuration for bounded queues.

See ChannelConfig for details on each field.

Source

pub fn input_channel_capacity(self, capacity: usize) -> Self

Set the capacity of the user-input channel.

Default: 64.

Source

pub fn ops_channel_capacity(self, capacity: usize) -> Self

Set the capacity of the per-turn operations channel.

Default: 64.

Source

pub fn ops_backpressure(self, policy: BackpressurePolicy) -> Self

Set the backpressure policy for the operations channel.

Default: BackpressurePolicy::Block.

Source

pub fn with_ask_user(self) -> Self

Register the built-in ask_user tool with the default timeout (30s).

Source

pub fn with_ask_user_timeout(self, timeout: Duration) -> Self

Register the built-in ask_user tool with a custom timeout.

Source

pub fn build(self) -> AgentLoop

Consume the builder and produce an AgentLoop.

§Panics

Panics if input_capacity or ops_capacity is zero, since tokio::sync::mpsc::channel(0) panics at runtime.

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