Skip to main content

autoagents_core/agent/
config.rs

1use crate::protocol::ActorID;
2use autoagents_llm::chat::StructuredOutputFormat;
3
4#[derive(Clone, Default)]
5pub struct AgentConfig {
6    /// The agent's name
7    pub name: String,
8    /// The agent's description
9    pub description: String,
10    /// The Agent ID
11    pub id: ActorID,
12    /// The output schema for the agent
13    pub output_schema: Option<StructuredOutputFormat>,
14}
15
16impl AgentConfig {
17    pub fn new(name: String, description: String) -> Self {
18        Self {
19            name,
20            description,
21            id: ActorID::new_v4(),
22            output_schema: None,
23        }
24    }
25
26    pub fn with_output_schema(mut self, schema: StructuredOutputFormat) -> Self {
27        self.output_schema = Some(schema);
28        self
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn test_agent_config_default() {
38        let config = AgentConfig::default();
39        assert!(config.name.is_empty());
40        assert!(config.description.is_empty());
41        assert!(config.id.is_nil());
42        assert!(config.output_schema.is_none());
43    }
44
45    #[test]
46    fn test_agent_config_new() {
47        let name = "TestAgent".to_string();
48        let description = "A test agent for unit tests".to_string();
49        let config = AgentConfig::new(name.clone(), description.clone());
50
51        assert_eq!(config.name, name);
52        assert_eq!(config.description, description);
53        assert!(!config.id.is_nil());
54        assert!(config.output_schema.is_none());
55    }
56
57    #[test]
58    fn test_agent_config_with_output_schema() {
59        let config = AgentConfig::new("Agent".to_string(), "Description".to_string());
60        let schema = StructuredOutputFormat {
61            name: "TestSchema".to_string(),
62            description: Some("Test schema".to_string()),
63            schema: Some(serde_json::json!({"type": "object"})),
64            strict: Some(true),
65        };
66        let config_with_schema = config.with_output_schema(schema.clone());
67
68        assert!(config_with_schema.output_schema.is_some());
69        if let Some(actual_schema) = config_with_schema.output_schema {
70            assert_eq!(actual_schema.name, "TestSchema");
71        }
72    }
73
74    #[test]
75    fn test_agent_config_clone() {
76        let original = AgentConfig::new("Original".to_string(), "Original description".to_string());
77        let cloned = original.clone();
78
79        assert_eq!(original.name, cloned.name);
80        assert_eq!(original.description, cloned.description);
81        assert_eq!(original.id, cloned.id);
82    }
83
84    #[test]
85    fn test_agent_config_unique_ids() {
86        let config1 = AgentConfig::new("Agent1".to_string(), "Description1".to_string());
87        let config2 = AgentConfig::new("Agent2".to_string(), "Description2".to_string());
88
89        assert_ne!(config1.id, config2.id);
90    }
91}