feat: add internal ZCLAW kernel crates to git tracking

This commit is contained in:
iven
2026-03-22 09:26:36 +08:00
parent d72c0f7161
commit 58cd24f85b
36 changed files with 10298 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
//! 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<Value>;
}
/// Context provided to tool execution
#[derive(Debug, Clone)]
pub struct ToolContext {
pub agent_id: AgentId,
pub working_directory: Option<String>,
}
/// Tool registry for managing available tools
pub struct ToolRegistry {
tools: Vec<Box<dyn Tool>>,
}
impl ToolRegistry {
pub fn new() -> Self {
Self { tools: Vec::new() }
}
pub fn register(&mut self, tool: Box<dyn Tool>) {
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<ToolDefinition> {
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;