pub struct Agent<T, R> { /* private fields */ }Implementations§
Source§impl<R, T: Tools<R>> Agent<T, R>
impl<R, T: Tools<R>> Agent<T, R>
Sourcepub fn new(tools: T, finish: FinishHandler<R>) -> Self
pub fn new(tools: T, finish: FinishHandler<R>) -> Self
Creates a new agent with the provided tools.
finish is invoked when the LLM finishes without a tool call.
When ControlFlow::Break is returned, the loop will terminate with the provided return value.
When ControlFlow::Continue(message) is returned, the loop continues with the returned message appended to the chat history.
Sourcepub fn with_content_listener(self, listener: Box<dyn Fn(&str)>) -> Self
pub fn with_content_listener(self, listener: Box<dyn Fn(&str)>) -> Self
Adds a listener that is invoked when streamed message content is available. This is intended for debugging purposes only.
Sourcepub fn with_tool_call_listener(self, listener: Box<dyn Fn(&str)>) -> Self
pub fn with_tool_call_listener(self, listener: Box<dyn Fn(&str)>) -> Self
Adds a listener that is invoked when tool calling content is available. This is intended for debugging purposes only. Tools are called automatically.
Sourcepub async fn run<C: Config>(&mut self, client: &Client<C>, prompt: &str) -> R
pub async fn run<C: Config>(&mut self, client: &Client<C>, prompt: &str) -> R
Runs the agent loop. If tools were provided, they may be called.
Terminates when a tool returns ControlFlow::Break.
It is assumed that any single message or tool response always fits in the context window fully. If this is not the case, this function may crash.