Skip to main content

ai_agent/tools/
team.rs

1//! Team management tools.
2//!
3//! Provides tools for creating and deleting multi-agent teams.
4
5use crate::types::*;
6
7/// TeamCreate tool - create a team of agents
8pub struct TeamCreateTool;
9
10impl TeamCreateTool {
11    pub fn new() -> Self {
12        Self
13    }
14
15    pub fn input_schema(&self) -> ToolInputSchema {
16        ToolInputSchema {
17            schema_type: "object".to_string(),
18            properties: serde_json::json!({
19                "name": {
20                    "type": "string",
21                    "description": "Name of the team"
22                },
23                "description": {
24                    "type": "string",
25                    "description": "Description of what the team does"
26                },
27                "agents": {
28                    "type": "array",
29                    "items": {
30                        "type": "object",
31                        "properties": {
32                            "name": { "type": "string" },
33                            "description": { "type": "string" },
34                            "model": { "type": "string" }
35                        }
36                    },
37                    "description": "List of agents in the team"
38                }
39            }),
40            required: Some(vec!["name".to_string()]),
41        }
42    }
43
44    pub async fn execute(
45        &self,
46        input: serde_json::Value,
47        _context: &ToolContext,
48    ) -> Result<ToolResult, crate::error::AgentError> {
49        let name = input["name"].as_str().unwrap_or("team");
50        let description = input["description"].as_str().unwrap_or("");
51
52        let response = format!(
53            "Team '{}' created.\nDescription: {}\nNote: Full team coordination implementation would spawn multiple agents here.",
54            name, description
55        );
56
57        Ok(ToolResult {
58            result_type: "text".to_string(),
59            tool_use_id: "team_create".to_string(),
60            content: response,
61            is_error: Some(false),
62        })
63    }
64}
65
66impl Default for TeamCreateTool {
67    fn default() -> Self {
68        Self::new()
69    }
70}
71
72/// TeamDelete tool - delete a team
73pub struct TeamDeleteTool;
74
75impl TeamDeleteTool {
76    pub fn new() -> Self {
77        Self
78    }
79
80    pub fn input_schema(&self) -> ToolInputSchema {
81        ToolInputSchema {
82            schema_type: "object".to_string(),
83            properties: serde_json::json!({
84                "name": {
85                    "type": "string",
86                    "description": "Name of the team to delete"
87                }
88            }),
89            required: Some(vec!["name".to_string()]),
90        }
91    }
92
93    pub async fn execute(
94        &self,
95        input: serde_json::Value,
96        _context: &ToolContext,
97    ) -> Result<ToolResult, crate::error::AgentError> {
98        let name = input["name"].as_str().unwrap_or("team");
99
100        let response = format!("Team '{}' deleted.", name);
101
102        Ok(ToolResult {
103            result_type: "text".to_string(),
104            tool_use_id: "team_delete".to_string(),
105            content: response,
106            is_error: Some(false),
107        })
108    }
109}
110
111impl Default for TeamDeleteTool {
112    fn default() -> Self {
113        Self::new()
114    }
115}
116
117/// SendMessage tool - send message between agents
118pub struct SendMessageTool;
119
120impl SendMessageTool {
121    pub fn new() -> Self {
122        Self
123    }
124
125    pub fn input_schema(&self) -> ToolInputSchema {
126        ToolInputSchema {
127            schema_type: "object".to_string(),
128            properties: serde_json::json!({
129                "to": {
130                    "type": "string",
131                    "description": "Agent name to send message to"
132                },
133                "message": {
134                    "type": "string",
135                    "description": "Message content"
136                }
137            }),
138            required: Some(vec!["to".to_string(), "message".to_string()]),
139        }
140    }
141
142    pub async fn execute(
143        &self,
144        input: serde_json::Value,
145        _context: &ToolContext,
146    ) -> Result<ToolResult, crate::error::AgentError> {
147        let to = input["to"].as_str().unwrap_or("agent");
148        let message = input["message"].as_str().unwrap_or("");
149
150        let response = format!("Message sent to '{}': {}", to, message);
151
152        Ok(ToolResult {
153            result_type: "text".to_string(),
154            tool_use_id: "send_message".to_string(),
155            content: response,
156            is_error: Some(false),
157        })
158    }
159}
160
161impl Default for SendMessageTool {
162    fn default() -> Self {
163        Self::new()
164    }
165}
166
167#[cfg(test)]
168mod tests {
169    use super::*;
170
171    #[test]
172    fn test_team_create_schema() {
173        let tool = TeamCreateTool::new();
174        let schema = tool.input_schema();
175        assert!(schema.properties.get("name").is_some());
176    }
177
178    #[test]
179    fn test_team_delete_schema() {
180        let tool = TeamDeleteTool::new();
181        let schema = tool.input_schema();
182        assert!(schema.properties.get("name").is_some());
183    }
184
185    #[test]
186    fn test_send_message_schema() {
187        let tool = SendMessageTool::new();
188        let schema = tool.input_schema();
189        assert!(schema.properties.get("to").is_some());
190        assert!(schema.properties.get("message").is_some());
191    }
192}