//! Tool system for agent capabilities use async_trait::async_trait; use serde_json::Value; use zclaw_types::{AgentId, Result}; use crate::driver::ToolDefinition; /// Tool trait for implementing agent tools #[async_trait] pub trait Tool: Send + Sync { /// Get the tool name fn name(&self) -> &str; /// Get the tool description fn description(&self) -> &str; /// Get the JSON schema for input parameters fn input_schema(&self) -> Value; /// Execute the tool async fn execute(&self, input: Value, context: &ToolContext) -> Result; } /// Context provided to tool execution #[derive(Debug, Clone)] pub struct ToolContext { pub agent_id: AgentId, pub working_directory: Option, } /// Tool registry for managing available tools pub struct ToolRegistry { tools: Vec>, } impl ToolRegistry { pub fn new() -> Self { Self { tools: Vec::new() } } pub fn register(&mut self, tool: Box) { self.tools.push(tool); } pub fn get(&self, name: &str) -> Option<&dyn Tool> { self.tools.iter().find(|t| t.name() == name).map(|t| t.as_ref()) } pub fn list(&self) -> Vec<&dyn Tool> { self.tools.iter().map(|t| t.as_ref()).collect() } pub fn definitions(&self) -> Vec { self.tools.iter().map(|t| { ToolDefinition::new( t.name(), t.description(), t.input_schema(), ) }).collect() } } impl Default for ToolRegistry { fn default() -> Self { Self::new() } } // Built-in tools module pub mod builtin;