Claude Managed Agents 提供一組內建工具,Claude 可以在 session(工作階段)中自主使用這些工具。您可以透過在代理設定中指定工具來控制哪些工具可供使用。
Claude Managed Agents 也支援自訂的使用者定義工具。您的應用程式會單獨執行這些工具,並將結果回傳給 Claude,Claude 會使用這些結果繼續執行任務。若要為代理提供來自 MCP 伺服器的工具,請改用 MCP connector(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 個 token 時,會自動寫入 sandbox(沙箱)中的檔案。模型會收到截斷的預覽內容及檔案路徑,並可從該處讀取完整內容。
建立代理時,使用 agent_toolset_20260401 啟用完整工具集。使用 configs 陣列來停用特定工具或覆寫其設定。每個 config 項目也可以設定 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 陣列的工具集物件中,於該工具的 config 項目設定 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?