Skip to main content

codetether_agent/tool/agent/
tool_impl.rs

1//! Top-level tool implementation for sub-agent operations.
2//!
3//! This module holds the `Tool` trait implementation and dispatches parsed
4//! actions to focused submodules.
5//!
6//! # Examples
7//!
8//! ```ignore
9//! let tool = AgentTool::new();
10//! ```
11
12use super::actions::execute_kill;
13use super::{handlers, message, spawn};
14use crate::tool::{Tool, ToolResult};
15use anyhow::{Context, Result};
16use async_trait::async_trait;
17use serde_json::Value;
18
19/// Tool entrypoint for spawning and managing sub-agents.
20///
21/// The tool supports `spawn`, `message`, `list`, and `kill` actions and
22/// delegates the implementation to narrower modules.
23///
24/// # Examples
25///
26/// ```ignore
27/// let tool = AgentTool::new();
28/// assert_eq!(tool.name(), "Sub-Agent");
29/// ```
30pub struct AgentTool;
31
32impl AgentTool {
33    /// Creates the sub-agent management tool.
34    ///
35    /// # Examples
36    ///
37    /// ```ignore
38    /// let tool = AgentTool::new();
39    /// ```
40    pub fn new() -> Self {
41        Self
42    }
43}
44
45impl Default for AgentTool {
46    fn default() -> Self {
47        Self::new()
48    }
49}
50
51#[async_trait]
52impl Tool for AgentTool {
53    fn id(&self) -> &str {
54        "agent"
55    }
56
57    fn name(&self) -> &str {
58        "Sub-Agent"
59    }
60
61    fn description(&self) -> &str {
62        "Spawn and communicate with specialized sub-agents. Actions: spawn, message, list, kill. Spawned agents must use a free/subscription-eligible model."
63    }
64
65    fn parameters(&self) -> Value {
66        super::tool_schema::agent_tool_parameters()
67    }
68
69    async fn execute(&self, params: Value) -> Result<ToolResult> {
70        let parsed: super::params::Params =
71            serde_json::from_value(params).context("Invalid params")?;
72        match parsed.action.as_str() {
73            "spawn" => spawn::handle_spawn(&parsed).await,
74            "message" => message::handle_message(&parsed).await,
75            "list" => Ok(handlers::handle_list()),
76            "kill" => execute_kill(&parsed),
77            _ => Ok(super::actions::unknown_action_result(&parsed.action)),
78        }
79    }
80}