BotOf Tech
返回首页Anthropic 工程团队:为 AI 智能体打造高效工具

Anthropic 工程团队:为 AI 智能体打造高效工具

·1 分钟阅读·

为什么这篇文章重要?

Anthropic 工程团队发表的技术文章,直接来自 Claude Code 的实战经验。毕竟现在最好的 Coding Agent 就是他们做的。

核心原则

1. 工具名称即文档

{
  "name": "read_file",
  "description": "Read the contents of a file at the given path"
}

不要用 fn_001processData 这种模糊命名。Agent 需要从工具名称就能判断什么时候该用。

2. 参数设计要有约束

{
  "type": "object",
  "properties": {
    "path": { "type": "string", "description": "Absolute file path" },
    "encoding": { "type": "string", "enum": ["utf-8", "ascii", "binary"] }
  },
  "required": ["path"]
}

enum 限制选项,用 required 明确必填。减少 Agent 的决策负担。

3. 错误信息要可操作

不好的错误:Error: Operation failed 好的错误:File not found: /path/to/file. Did you mean /path/to/file.txt?

Agent 需要从错误信息中获取下一步行动的线索。

4. 幂等性

同一个工具调用执行两次应该产生相同结果。Agent 经常会在不确定时重试。

实践建议

  • 工具数量控制在 10-20 个
  • 每个工具做一件事
  • 返回结构化数据,不要返回纯文本
  • 提供示例调用和返回值

来源: @dotey 宝玉的推荐解读