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(model: impl Into<String>, tools: T, finish: FinishHandler<R>) -> Self
pub fn new(model: impl Into<String>, 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
Convenience function that calls Self::start_session followed by Session::run.
See Session::run.
Sourcepub fn start_session<'agent>(
&'agent mut self,
prompt: &str,
) -> Session<&'agent mut Agent<T, R>, T, R>
pub fn start_session<'agent>( &'agent mut self, prompt: &str, ) -> Session<&'agent mut Agent<T, R>, T, R>
Start a new chat session with the provided prompt.
Keeps a reference to the agent rather than consuming it, such that the agent can be re-used later.