Claude 托管智能体提供了一组内置工具,Claude 可以在会话中自主使用这些工具。您可以通过在智能体配置中指定工具来控制哪些工具可用。
Claude 托管智能体还支持自定义的用户定义工具。您的应用程序单独执行这些工具并将结果返回给 Claude,Claude 会使用这些结果继续执行任务。如需为智能体提供来自 MCP 服务器的工具,请改用 MCP 连接器。
所有 Managed Agents API 请求都需要 managed-agents-2026-04-01 beta 标头。SDK 会自动设置该 beta 标头。
智能体工具集包含以下工具。当您在智能体配置中包含该工具集时,所有工具默认启用。请使用"名称"列中的值在 configs 数组中引用工具。
| 工具 | 名称 | 描述 |
|---|---|---|
| Bash | bash | 在 shell 会话中执行 bash 命令 |
| Read | read | 从沙箱文件系统读取文件 |
| Write | write | 将文件写入沙箱文件系统 |
| Edit | edit | 在文件中执行字符串替换 |
| Glob | glob | 使用 glob 模式进行快速文件模式匹配 |
| Grep | grep | 使用正则表达式模式进行文本搜索 |
| Web fetch | web_fetch | 从 URL 获取内容 |
| Web search | web_search | 在网络上搜索信息 |
当工具输出超过 100,000 个令牌时,它会自动写入沙箱中的文件。模型会收到带有文件路径的截断预览,并可以从该路径读取完整内容。
创建智能体时,使用 agent_toolset_20260401 启用完整工具集。使用 configs 数组禁用特定工具或覆盖其设置。每个配置条目还可以设置 permission_policy,用于控制该工具的调用是自动批准还是需要确认。有关可用的策略类型,请参阅权限策略。
ant beta:agents create <<'YAML'
name: Coding Assistant
model: claude-opus-4-8
tools:
- type: agent_toolset_20260401
configs:
- name: web_fetch
enabled: false
YAML要禁用某个工具,请在智能体 tools 数组的工具集对象中,将其配置条目的 enabled 设置为 false:
{
"type": "agent_toolset_20260401",
"configs": [
{ "name": "web_fetch", "enabled": false },
{ "name": "web_search", "enabled": false }
]
}default_config 对象为工具集中的每个工具设置基准配置,而各工具的 configs 条目会覆盖该基准。如需从全部关闭开始并仅启用所需的工具,请将 default_config.enabled 设置为 false:
{
"type": "agent_toolset_20260401",
"default_config": { "enabled": false },
"configs": [
{ "name": "bash", "enabled": true },
{ "name": "read", "enabled": true },
{ "name": "write", "enabled": true }
]
}除了内置工具外,您还可以定义自定义工具。自定义工具类似于 Messages API 中的用户定义的客户端工具。
每个自定义工具都定义了一个契约:您指定可用的操作及其返回内容,Claude 则决定何时以及如何调用它们。模型本身从不执行任何操作。它会发出结构化请求,由您的代码运行该操作,然后将结果返回到对话中。有关如何在会话期间接收自定义工具调用并返回结果,请参阅会话事件流。
ant beta:agents create <<'YAML'
name: Weather Agent
model: claude-opus-4-8
tools:
- type: agent_toolset_20260401
- type: custom
name: get_weather
description: Get current weather for a location
input_schema:
type: object
properties:
location:
type: string
description: City name
required:
- location
YAML在智能体上定义自定义工具后,智能体会在会话期间调用它们。
create_pr、review_pr、merge_pr),不如将它们组合成一个带有 action 参数的单一工具。更少但功能更强大的工具可以减少选择歧义,使 Claude 更容易浏览您的工具集。db_query 或 storage_read)。随着工具库的增长,这可以使工具选择更加明确。Was this page helpful?