Skip to main content

AgentLoop

Struct AgentLoop 

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

The core ReAct agent loop.

Drives an LLM through iterative reasoning and tool execution until the model produces a final text answer or the iteration limit is reached.

The loop does not own the LLM client; instead, run() takes &dyn LlmClient so the same loop can be reused with different backends.

Implementations§

Source§

impl AgentLoop

Source

pub fn builder() -> AgentLoopBuilder

Create a builder with default settings.

Source

pub fn channel_config(&self) -> &ChannelConfig

Returns the channel configuration for this agent loop.

Used by AgentSession to create bounded channels with the configured capacities and policies.

Source

pub async fn run( &self, llm: &dyn LlmClient, messages: Vec<Message>, on_event: impl Fn(AgentEvent) + Send + Sync, ) -> Result<AgentResult>

Run the agent loop to completion.

Iteratively calls the LLM, executes any requested tools, and feeds tool results back into the conversation until the LLM produces a final text response or max_iterations is exceeded.

The on_event callback is invoked for each notable event (tool started, tool completed, text chunk). Pass |_| {} for a no-op.

Source

pub async fn run_with_ops( &self, llm: &dyn LlmClient, messages: Vec<Message>, ops_rx: Option<Receiver<AgentOp>>, on_event: impl Fn(AgentEvent) + Send + Sync, ) -> Result<AgentResult>

Run with an optional interactive operations channel.

Pass ops_rx: None for behavior equivalent to run.

Source

pub async fn run_streaming( &self, llm: &dyn LlmClient, messages: Vec<Message>, on_event: impl Fn(AgentEvent) + Send + Sync, ) -> Result<AgentResult>

Streaming variant of run.

Uses LlmClient::chat_stream so that on_event receives AgentEvent::TextChunk for each text delta as it arrives, plus AgentEvent::TextDone with the full accumulated text and AgentEvent::IterationStarted at each reasoning iteration.

Tool execution is identical to the non-streaming path.

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.