Loading...
  • 建構
  • 管理
  • 模型與定價
  • 客戶端 SDK
  • API 參考
Search...
⌘K
Log in
工具
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
建構/定義您的代理

工具

配置代理可用的工具。

Was this page helpful?

Claude Managed Agents 提供了一組內置工具,Claude 可以在會話中自主使用這些工具。您可以通過在代理配置中指定工具來控制哪些工具可用。

還支持自定義的用戶定義工具。您的應用程序單獨執行這些工具,並將工具結果發送回 Claude;Claude 可以使用這些結果來繼續執行手頭的任務。

所有 Managed Agents API 請求都需要 managed-agents-2026-04-01 beta 標頭。SDK 會自動設置 beta 標頭。

可用工具

代理工具集包括以下工具。當您在代理配置中包含工具集時,所有工具默認都是啟用的。

工具名稱描述
Bashbash在 shell 會話中執行 bash 命令
Readread從本地文件系統讀取文件
Writewrite將文件寫入本地文件系統
Editedit在文件中執行字符串替換
Globglob使用 glob 模式進行快速文件模式匹配
Grepgrep使用正則表達式進行文本搜索
Web fetchweb_fetch從 URL 獲取內容
Web searchweb_search在網絡上搜索信息

配置工具集

在創建代理時,使用 agent_toolset_20260401 啟用完整工具集。使用 configs 數組禁用特定工具或覆蓋其設置。

禁用特定工具

要禁用工具,請在其配置條目中設置 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 決定何時以及如何調用它們。該模型永遠不會自行執行任何操作。它發出結構化請求,您的代碼運行該操作,結果流回對話。

定義工具後,代理將在會話過程中調用這些工具。有關完整流程,請參閱會話事件流。

自定義工具定義的最佳實踐

  • 提供極其詳細的描述。 這是迄今為止影響工具性能的最重要因素。您的描述應該解釋工具的功能、何時應該使用它(以及何時不應該使用它)、每個參數的含義及其如何影響工具的行為,以及任何重要的注意事項或限制。您為 Claude 提供的關於工具的上下文越多,它在決定何時以及如何使用它們時就會越好。每個工具描述至少應有 3-4 句話,如果工具複雜,則應更多。
  • 將相關操作合併為更少的工具。 與其為每個操作創建單獨的工具(create_pr、review_pr、merge_pr),不如將它們分組到一個具有 action 參數的單一工具中。更少、更強大的工具可以減少選擇歧義,使您的工具表面更容易讓 Claude 導航。
  • 在工具名稱中使用有意義的命名空間。 當您的工具跨越多個服務或資源時,使用資源前綴命名(例如 db_query、storage_read)。這使得工具選擇明確,隨著您的庫的增長而不會產生歧義。
  • 設計工具響應以僅返回高信號信息。 返回語義、穩定的標識符(例如 slug 或 UUID),而不是不透明的內部引用,並僅包含 Claude 需要推理其下一步的字段。冗長的響應會浪費上下文,使 Claude 更難提取重要信息。
ant beta:agents create <<'YAML'
name: Coding Assistant
model: claude-opus-4-7
tools:
  - type: agent_toolset_20260401
    configs:
      - name: web_fetch
        enabled: false
YAML
ant beta:agents create <<'YAML'
name: Weather Agent
model: claude-opus-4-7
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