use super::actions::execute_kill;
use super::{handlers, message, spawn};
use crate::tool::{Tool, ToolResult};
use anyhow::{Context, Result};
use async_trait::async_trait;
use serde_json::Value;
pub struct AgentTool;
impl AgentTool {
pub fn new() -> Self {
Self
}
}
impl Default for AgentTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl Tool for AgentTool {
fn id(&self) -> &str {
"agent"
}
fn name(&self) -> &str {
"Sub-Agent"
}
fn description(&self) -> &str {
"Spawn and communicate with specialized sub-agents. Actions: spawn, message, list, kill. Spawned agents must use a free/subscription-eligible model."
}
fn parameters(&self) -> Value {
super::tool_schema::agent_tool_parameters()
}
async fn execute(&self, params: Value) -> Result<ToolResult> {
let parsed: super::params::Params =
serde_json::from_value(params).context("Invalid params")?;
match parsed.action.as_str() {
"spawn" => spawn::handle_spawn(&parsed).await,
"message" => message::handle_message(&parsed).await,
"list" => Ok(handlers::handle_list()),
"kill" => execute_kill(&parsed),
_ => Ok(super::actions::unknown_action_result(&parsed.action)),
}
}
}