pub struct AgentExecutor { /* private fields */ }Expand description
Agent executor.
Responsible for executing the agent’s decision loop: Plan -> Act -> Observe.
Implementations§
Source§impl AgentExecutor
impl AgentExecutor
Sourcepub fn new(agent: Arc<dyn BaseAgent>, tools: Vec<Arc<dyn BaseTool>>) -> Self
pub fn new(agent: Arc<dyn BaseAgent>, tools: Vec<Arc<dyn BaseTool>>) -> Self
Creates a new AgentExecutor.
Sourcepub fn with_max_iterations(self, max_iterations: usize) -> Self
pub fn with_max_iterations(self, max_iterations: usize) -> Self
Sets max iterations.
Sourcepub fn with_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Sets verbose output.
Sourcepub fn with_memory(self, memory: Arc<Mutex<dyn BaseMemory>>) -> Self
pub fn with_memory(self, memory: Arc<Mutex<dyn BaseMemory>>) -> Self
Sets memory.
Sourcepub fn with_callbacks(self, callbacks: Arc<CallbackManager>) -> Self
pub fn with_callbacks(self, callbacks: Arc<CallbackManager>) -> Self
Sets callback manager.
Sourcepub fn stream(
&self,
input: String,
) -> Pin<Box<dyn Stream<Item = Result<AgentStreamEvent, AgentError>> + Send>>
pub fn stream( &self, input: String, ) -> Pin<Box<dyn Stream<Item = Result<AgentStreamEvent, AgentError>> + Send>>
Stream agent execution as a true async stream of events.
Each step of the agent loop (tool calls, observations, final answer)
is emitted as an AgentStreamEvent as soon as it occurs.
§Example
ⓘ
let mut stream = executor.stream("What is Rust?".to_string());
while let Some(event) = stream.next().await {
match event {
Ok(AgentStreamEvent::ToolStart { name, input }) => { /* show tool call */ }
Ok(AgentStreamEvent::ToolEnd { name, output }) => { /* show result */ }
Ok(AgentStreamEvent::FinalAnswer { content }) => { /* show answer */ }
_ => {}
}
}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AgentExecutor
impl !UnwindSafe for AgentExecutor
impl Freeze for AgentExecutor
impl Send for AgentExecutor
impl Sync for AgentExecutor
impl Unpin for AgentExecutor
impl UnsafeUnpin for AgentExecutor
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
Mutably borrows from an owned value. Read more