use uuid::Uuid;
use neuromance::Core;
use neuromance_client::LLMClient;
use neuromance_common::agents::AgentState;
use neuromance_common::chat::Message;
use neuromance_common::client::ToolChoice;
use neuromance_tools::ToolImplementation;
use crate::BaseAgent;
pub struct AgentBuilder<C: LLMClient> {
id: String,
core: Core<C>,
system_prompt: Option<String>,
user_prompt: Option<String>,
tool_choice: ToolChoice,
}
impl<C: LLMClient> AgentBuilder<C> {
pub fn new(id: impl Into<String>, client: C) -> Self {
Self {
id: id.into(),
core: Core::new(client),
system_prompt: None,
user_prompt: None,
tool_choice: ToolChoice::Auto,
}
}
pub fn system_prompt(mut self, prompt: impl Into<String>) -> Self {
self.system_prompt = Some(prompt.into());
self
}
pub fn user_prompt(mut self, prompt: impl Into<String>) -> Self {
self.user_prompt = Some(prompt.into());
self
}
pub fn add_tool<T: ToolImplementation + 'static>(mut self, tool: T) -> Self {
self.core.tool_executor.add_tool(tool);
self
}
pub fn max_turns(mut self, max_turns: u32) -> Self {
self.core.max_turns = Some(max_turns);
self
}
pub fn auto_approve_tools(mut self, auto_approve: bool) -> Self {
self.core.auto_approve_tools = auto_approve;
self
}
pub fn with_tool_choice(mut self, tool_choice: ToolChoice) -> Self {
self.tool_choice = tool_choice;
self
}
pub fn build(self) -> BaseAgent<C> {
let conversation_id = Uuid::new_v4();
let mut messages = Vec::new();
if let Some(ref prompt) = self.system_prompt {
messages.push(Message::system(conversation_id, prompt));
}
if let Some(ref prompt) = self.user_prompt {
messages.push(Message::user(conversation_id, prompt));
}
BaseAgent {
id: self.id,
conversation_id,
core: self.core,
state: AgentState::default(),
system_prompt: self.system_prompt,
user_prompt: self.user_prompt,
messages,
tool_choice: self.tool_choice,
}
}
}