ai-agent 0.13.4

Idiomatic agent sdk inspired by the claude code source leak
Documentation
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmbeddedTool {
    pub name: String,
    pub description: String,
    pub schema: serde_json::Value,
    pub handler: String,
}

pub fn get_embedded_tools() -> Vec<EmbeddedTool> {
    vec![
        EmbeddedTool {
            name: "read".to_string(),
            description: "Read a file from the filesystem".to_string(),
            schema: serde_json::json!({
                "type": "object",
                "properties": {
                    "file_path": {"type": "string"}
                },
                "required": ["file_path"]
            }),
            handler: "builtin".to_string(),
        },
        EmbeddedTool {
            name: "write".to_string(),
            description: "Write content to a file".to_string(),
            schema: serde_json::json!({
                "type": "object",
                "properties": {
                    "file_path": {"type": "string"},
                    "content": {"type": "string"}
                },
                "required": ["file_path", "content"]
            }),
            handler: "builtin".to_string(),
        },
        EmbeddedTool {
            name: "bash".to_string(),
            description: "Execute a bash command".to_string(),
            schema: serde_json::json!({
                "type": "object",
                "properties": {
                    "command": {"type": "string"},
                    "description": {"type": "string"}
                },
                "required": ["command"]
            }),
            handler: "builtin".to_string(),
        },
        EmbeddedTool {
            name: "grep".to_string(),
            description: "Search for patterns in files".to_string(),
            schema: serde_json::json!({
                "type": "object",
                "properties": {
                    "pattern": {"type": "string"},
                    "path": {"type": "string"}
                },
                "required": ["pattern"]
            }),
            handler: "builtin".to_string(),
        },
    ]
}

pub fn find_embedded_tool(name: &str) -> Option<EmbeddedTool> {
    get_embedded_tools().into_iter().find(|t| t.name == name)
}

pub fn is_builtin_tool(name: &str) -> bool {
    get_embedded_tools().iter().any(|t| t.name == name)
}

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

    #[test]
    fn test_get_embedded_tools() {
        let tools = get_embedded_tools();
        assert!(!tools.is_empty());
    }

    #[test]
    fn test_find_tool() {
        let tool = find_embedded_tool("read");
        assert!(tool.is_some());
        assert_eq!(tool.unwrap().name, "read");
    }
}