use crate::agent::Agent;
use crate::agent::react::builder::ReactAgentBuilder;
use crate::error::Result;
use crate::tools::Tool;
use std::sync::Arc;
pub struct Runner;
impl Runner {
pub async fn run(model: &str, system_prompt: &str, task: &str) -> Result<String> {
let agent = ReactAgentBuilder::simple(model, system_prompt)?;
agent.execute(task).await
}
pub fn builder(model: &str) -> RunnerBuilder {
RunnerBuilder {
inner: ReactAgentBuilder::new().model(model),
}
}
}
pub struct RunnerBuilder {
inner: ReactAgentBuilder,
}
impl RunnerBuilder {
pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
self.inner = self.inner.system_prompt(prompt);
self
}
pub fn enable_tools(mut self) -> Self {
self.inner = self.inner.enable_tools();
self
}
pub fn tool(mut self, tool: Box<dyn Tool>) -> Self {
self.inner = self.inner.tool(tool);
self
}
pub fn tools(mut self, tools: Vec<Box<dyn Tool>>) -> Self {
self.inner = self.inner.tools(tools);
self
}
pub fn llm_client(mut self, client: Arc<dyn crate::llm::LlmClient>) -> Self {
self.inner = self.inner.llm_client(client);
self
}
pub fn max_iterations(mut self, max: usize) -> Self {
self.inner = self.inner.max_iterations(max);
self
}
pub async fn run(self, task: &str) -> Result<String> {
let agent = self.inner.build()?;
agent.execute(task).await
}
pub fn build(self) -> Result<crate::agent::react::ReactAgent> {
self.inner.build()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_runner_builder_compiles() {
let _builder = Runner::builder("test-model")
.system_prompt("You are an assistant")
.enable_tools()
.max_iterations(5);
}
}