#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AgentSpec {
pub name: String,
pub description: String,
pub model: Option<String>,
pub tools: Vec<String>,
pub instructions: String,
}
pub struct AgentCreatorController {
name: String,
description: String,
model: Option<String>,
tools: Vec<String>,
instructions: String,
}
impl AgentCreatorController {
pub fn new() -> Self {
Self {
name: String::new(),
description: String::new(),
model: None,
tools: Vec::new(),
instructions: String::new(),
}
}
pub fn set_name(&mut self, name: impl Into<String>) {
self.name = name.into();
}
pub fn name(&self) -> &str {
&self.name
}
pub fn set_description(&mut self, description: impl Into<String>) {
self.description = description.into();
}
pub fn description(&self) -> &str {
&self.description
}
pub fn set_model(&mut self, model: Option<String>) {
self.model = model;
}
pub fn model(&self) -> Option<&str> {
self.model.as_deref()
}
pub fn add_tool(&mut self, tool: impl Into<String>) {
let tool = tool.into();
if !self.tools.contains(&tool) {
self.tools.push(tool);
}
}
pub fn remove_tool(&mut self, tool: &str) -> bool {
if let Some(pos) = self.tools.iter().position(|t| t == tool) {
self.tools.remove(pos);
true
} else {
false
}
}
pub fn tools(&self) -> &[String] {
&self.tools
}
pub fn set_instructions(&mut self, instructions: impl Into<String>) {
self.instructions = instructions.into();
}
pub fn instructions(&self) -> &str {
&self.instructions
}
pub fn validate(&self) -> Result<AgentSpec, String> {
if self.name.trim().is_empty() {
return Err("Agent name is required".into());
}
if self.description.trim().is_empty() {
return Err("Agent description is required".into());
}
if self.instructions.trim().is_empty() {
return Err("Agent instructions are required".into());
}
Ok(AgentSpec {
name: self.name.trim().to_string(),
description: self.description.trim().to_string(),
model: self.model.clone(),
tools: self.tools.clone(),
instructions: self.instructions.clone(),
})
}
pub fn reset(&mut self) {
self.name.clear();
self.description.clear();
self.model = None;
self.tools.clear();
self.instructions.clear();
}
}
impl Default for AgentCreatorController {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
#[path = "agent_creator_tests.rs"]
mod tests;