pub struct AgentExecutor<'a> { /* private fields */ }Expand description
Configurable agent loop with tool calling support.
§Usage
let declarations = vec![FunctionDeclaration {
name: "search".into(),
description: "Search the web".into(),
parameters: Some(json!({"type": "object", "properties": {"q": {"type": "string"}}})),
}];
let handler: TextToolHandler = Arc::new(|name, _args| {
FunctionResponse { name: name.to_owned(), response: json!({"results": []}) }
});
let executor = AgentExecutor::new(provider, declarations, handler);
let messages = vec![ChatMessage::user("Search for Rust tutorials")];
let result = executor.run(messages).await?;
println!("{}", result.content);Implementations§
Source§impl<'a> AgentExecutor<'a>
impl<'a> AgentExecutor<'a>
Sourcepub fn new(
provider: &'a dyn LlmProvider,
declarations: Vec<FunctionDeclaration>,
tool_handler: TextToolHandler,
) -> Self
pub fn new( provider: &'a dyn LlmProvider, declarations: Vec<FunctionDeclaration>, tool_handler: TextToolHandler, ) -> Self
Create a new agent executor with default settings (max_turns=10)
Sourcepub fn with_max_turns(self, max_turns: u32) -> Self
pub fn with_max_turns(self, max_turns: u32) -> Self
Set the maximum number of turns (clamped to ceiling of 50)
Sourcepub fn with_on_turn(self, callback: OnTurnCallback) -> Self
pub fn with_on_turn(self, callback: OnTurnCallback) -> Self
Set an observability callback invoked after each turn
Sourcepub async fn run(
&self,
initial_messages: Vec<ChatMessage>,
) -> Result<AgentResult, RunnerError>
pub async fn run( &self, initial_messages: Vec<ChatMessage>, ) -> Result<AgentResult, RunnerError>
Run the agent loop with the given initial messages.
§Errors
Returns RunnerError if any provider.complete() call fails.
Auto Trait Implementations§
impl<'a> Freeze for AgentExecutor<'a>
impl<'a> !RefUnwindSafe for AgentExecutor<'a>
impl<'a> Send for AgentExecutor<'a>
impl<'a> Sync for AgentExecutor<'a>
impl<'a> Unpin for AgentExecutor<'a>
impl<'a> UnsafeUnpin for AgentExecutor<'a>
impl<'a> !UnwindSafe for AgentExecutor<'a>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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