Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Claude Managed Agents 提供了一組內置工具,Claude 可以在會話中自主使用。您可以通過在代理配置中指定工具來控制哪些工具可用。
還支持自定義的用戶定義工具。您的應用程序單獨執行這些工具,並將工具結果發送回 Claude;Claude 可以使用結果繼續執行當前任務。
所有 Managed Agents API 請求都需要 managed-agents-2026-04-01 beta 標頭。SDK 會自動設置 beta 標頭。
代理工具集包括以下工具。在代理配置中包含工具集時,所有工具默認都是啟用的。
| 工具 | 名稱 | 描述 |
|---|---|---|
| Bash | bash | 在 shell 會話中執行 bash 命令 |
| Read | read | 從本地文件系統讀取文件 |
| Write | write | 將文件寫入本地文件系統 |
| Edit | edit | 在文件中執行字符串替換 |
| Glob |
Was this page helpful?
glob| 使用 glob 模式進行快速文件模式匹配 |
| Grep | grep | 使用正則表達式進行文本搜索 |
| Web fetch | web_fetch | 從 URL 獲取內容 |
| Web search | web_search | 在網絡上搜索信息 |
在創建代理時使用 agent_toolset_20260401 啟用完整工具集。使用 configs 數組禁用特定工具或覆蓋其設置。
agent=$(curl -fsSL https://api.anthropic.com/v1/agents \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
-d @- <<'EOF'
{
"name": "Coding Assistant",
"model": "claude-sonnet-4-6",
"tools": [
{
"type": "agent_toolset_20260401",
"configs": [
{"name": "web_fetch", "enabled": false}
]
}
]
}
EOF
)要禁用工具,請在其配置條目中設置 enabled: false:
{
"type": "agent_toolset_20260401",
"configs": [
{ "name": "web_fetch", "enabled": false },
{ "name": "web_search", "enabled": false }
]
}要從禁用所有工具開始,然後僅啟用您需要的工具,請將 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 的功能以執行更多種類的任務。每個工具定義一個契約:您指定可用的操作及其返回內容;Claude 決定何時以及如何調用它們。模型永遠不會自己執行任何操作。它發出結構化請求,您的代碼運行操作,結果流回對話。
agent=$(curl -fsSL https://api.anthropic.com/v1/agents \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
-d @- <<'EOF'
{
"name": "Weather Agent",
"model": "claude-sonnet-4-6",
"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"]
}
}
]
}
EOF
)定義工具後,代理將在會話過程中調用工具。有關完整流程,請參閱會話事件流。
create_pr、review_pr、merge_pr),不如將它們分組到一個具有 action 參數的單一工具中。更少但功能更強大的工具可以減少選擇歧義,使 Claude 更容易導航您的工具表面。db_query、storage_read)。隨著您的庫增長,這使工具選擇變得明確。