← 返回总览

🔧 工具系统对比

18 个 Agent 的工具定义、调用和扩展机制横向对比

一、工具定义方式

项目定义方式Schema 生成验证类型
Aider无传统工具——用文本格式N/ARegex 解析文本解析
SWE-agentYAML action templates手动定义Regex 匹配Shell
OpenHandsPython Action 类PydanticPydanticFunction Calling
Codex CLI DEEPRust trait + DynamicToolSpecJSON Schema + schemars自动Shell apply_patch update_plan MCP
AutoGPT@command 装饰器手动 JSON手动Function Calling
MetaGPTAction 子类PydanticPydanticCode-as-Action
AutoGenPython 函数 + 类型注解自动生成 JSON SchemaPydanticFunction Calling
CrewAI@tool 装饰器自动 + 手动PydanticFunction Calling
LangGraphToolNode + LangChain Tools自动PydanticFunction Calling
PydanticAI@agent.tool 装饰器从类型注解自动Pydantic 严格验证Function Calling
AgnoToolkit 类 + @tool自动PydanticFunction Calling
Google ADKFunctionTool / AgentTool自动PydanticFunction Calling
SmolagentsTool 子类 + @tool自动JSON SchemaCode-as-Action
Browser UseController actions手动手动结构化文本
GPT ResearcherRetriever 抽象手动手动Function Calling
Goose DEEPRust MCP 工具 + ACPJSON Schema (rmcp)自动 (PermissionJudge)Extension(≤5/≤50) ACP Subagent

二、三种工具调用范式

范式 1: Function Calling (主流,12/18 项目)

使用 LLM 的 function calling / tool_use API。工具定义为 JSON Schema,模型返回结构化的 tool_call,运行时解析执行。

# AutoGen 示例
@agent.tool
async def search(query: str, max_results: int = 5) -> str:
    """Search the web for information."""
    return web_search(query, max_results)

优势: 标准化、可靠解析、类型安全
劣势: 依赖模型支持、工具数量受限

范式 2: Code-as-Action (3/18 项目)

模型生成可执行代码(Python),运行时直接执行。工具通过代码调用。

# Smolagents CodeAgent 示例
# Model generates:
final_answer(search(query="latest AI news", max_results=5))

优势: 灵活性极高、可组合工具、无限表达力
劣势: 安全风险、需要沙箱、错误处理难

范式 3: 文本解析 (3/18 项目)

模型输出自由文本,运行时用 regex/格式化规则解析出动作。

# Aider 示例 - 模型输出:
Here's the change:
```python
foo.py
<<<<<<< SEARCH
old_code
=======
new_code
>>>>>>> REPLACE
```

优势: 不依赖 function calling API、模型兼容性广
劣势: 解析脆弱、格式漂移、复杂工具难支持

三、安全机制对比

项目执行环境审批机制网络隔离文件系统隔离
OpenHandsDocker Sandbox❌ (auto)
Codex CLILandlock + Seccomp + Network NS✅ Guardian 风险评估✅ (on-request/never/on-failure)
SWE-agentDocker
Aider本地 (无沙箱)
AutoGPT本地/Docker⚠️ (user approval)可选可选
SmolagentsLocalPythonExecutor
PydanticAI本地
🎯 构建自己 Agent 的工具系统建议: