ai-agent-sdk 0.5.0

Idiomatic agent sdk inspired by the claude code source leak
Documentation
//! Team management tools.
//!
//! Provides tools for creating and deleting multi-agent teams.

use crate::types::*;

/// TeamCreate tool - create a team of agents
pub struct TeamCreateTool;

impl TeamCreateTool {
    pub fn new() -> Self {
        Self
    }

    pub fn input_schema(&self) -> ToolInputSchema {
        ToolInputSchema {
            schema_type: "object".to_string(),
            properties: serde_json::json!({
                "name": {
                    "type": "string",
                    "description": "Name of the team"
                },
                "description": {
                    "type": "string",
                    "description": "Description of what the team does"
                },
                "agents": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "name": { "type": "string" },
                            "description": { "type": "string" },
                            "model": { "type": "string" }
                        }
                    },
                    "description": "List of agents in the team"
                }
            }),
            required: Some(vec!["name".to_string()]),
        }
    }

    pub async fn execute(&self, input: serde_json::Value, _context: &ToolContext) -> Result<ToolResult, crate::error::AgentError> {
        let name = input["name"].as_str().unwrap_or("team");
        let description = input["description"].as_str().unwrap_or("");

        let response = format!(
            "Team '{}' created.\nDescription: {}\nNote: Full team coordination implementation would spawn multiple agents here.",
            name, description
        );

        Ok(ToolResult {
            result_type: "text".to_string(),
            tool_use_id: "team_create".to_string(),
            content: response,
            is_error: Some(false),
        })
    }
}

impl Default for TeamCreateTool {
    fn default() -> Self {
        Self::new()
    }
}

/// TeamDelete tool - delete a team
pub struct TeamDeleteTool;

impl TeamDeleteTool {
    pub fn new() -> Self {
        Self
    }

    pub fn input_schema(&self) -> ToolInputSchema {
        ToolInputSchema {
            schema_type: "object".to_string(),
            properties: serde_json::json!({
                "name": {
                    "type": "string",
                    "description": "Name of the team to delete"
                }
            }),
            required: Some(vec!["name".to_string()]),
        }
    }

    pub async fn execute(&self, input: serde_json::Value, _context: &ToolContext) -> Result<ToolResult, crate::error::AgentError> {
        let name = input["name"].as_str().unwrap_or("team");

        let response = format!("Team '{}' deleted.", name);

        Ok(ToolResult {
            result_type: "text".to_string(),
            tool_use_id: "team_delete".to_string(),
            content: response,
            is_error: Some(false),
        })
    }
}

impl Default for TeamDeleteTool {
    fn default() -> Self {
        Self::new()
    }
}

/// SendMessage tool - send message between agents
pub struct SendMessageTool;

impl SendMessageTool {
    pub fn new() -> Self {
        Self
    }

    pub fn input_schema(&self) -> ToolInputSchema {
        ToolInputSchema {
            schema_type: "object".to_string(),
            properties: serde_json::json!({
                "to": {
                    "type": "string",
                    "description": "Agent name to send message to"
                },
                "message": {
                    "type": "string",
                    "description": "Message content"
                }
            }),
            required: Some(vec!["to".to_string(), "message".to_string()]),
        }
    }

    pub async fn execute(&self, input: serde_json::Value, _context: &ToolContext) -> Result<ToolResult, crate::error::AgentError> {
        let to = input["to"].as_str().unwrap_or("agent");
        let message = input["message"].as_str().unwrap_or("");

        let response = format!(
            "Message sent to '{}': {}",
            to, message
        );

        Ok(ToolResult {
            result_type: "text".to_string(),
            tool_use_id: "send_message".to_string(),
            content: response,
            is_error: Some(false),
        })
    }
}

impl Default for SendMessageTool {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_team_create_schema() {
        let tool = TeamCreateTool::new();
        let schema = tool.input_schema();
        assert!(schema.properties.get("name").is_some());
    }

    #[test]
    fn test_team_delete_schema() {
        let tool = TeamDeleteTool::new();
        let schema = tool.input_schema();
        assert!(schema.properties.get("name").is_some());
    }

    #[test]
    fn test_send_message_schema() {
        let tool = SendMessageTool::new();
        let schema = tool.input_schema();
        assert!(schema.properties.get("to").is_some());
        assert!(schema.properties.get("message").is_some());
    }
}