Loading...
    • 建構
    • 管理
    • 模型與定價
    • 客戶端 SDK
    • API 參考
    Search...
    ⌘K
    第一步
    Claude 簡介快速入門
    使用 Claude 建構
    功能概覽使用 Messages API處理停止原因
    模型功能
    延伸思考自適應思考效能快速模式(測試版:研究預覽)結構化輸出引用來源串流訊息批次處理搜尋結果串流拒絕多語言支援嵌入向量
    工具
    概覽工具使用方式網路搜尋工具網路擷取工具程式碼執行工具記憶體工具Bash 工具電腦使用工具文字編輯器工具
    工具基礎架構
    工具搜尋程式化工具呼叫細粒度工具串流
    上下文管理
    上下文視窗壓縮上下文編輯提示快取Token 計數
    處理檔案
    Files APIPDF 支援圖像與視覺
    技能
    概覽快速入門最佳實踐企業版技能API 中的技能
    MCP
    遠端 MCP 伺服器MCP 連接器
    提示工程
    概覽提示最佳實踐Console 提示工具
    測試與評估
    定義成功標準並建立評估在 Console 中使用評估工具降低延遲
    強化防護欄
    減少幻覺提高輸出一致性防範越獄減少提示洩漏
    資源
    詞彙表
    版本說明
    Claude Platform
    Console
    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
    • Catalog
    • 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
    • Catalog
    • 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
    定義您的代理

    工具

    配置代理可用的工具。

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

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

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

    可用工具

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

    工具名稱描述
    Bashbash在 shell 會話中執行 bash 命令
    Readread從本地文件系統讀取文件
    Writewrite將文件寫入本地文件系統
    Editedit在文件中執行字符串替換
    Glob

    Was this page helpful?

    glob
    使用 glob 模式進行快速文件模式匹配
    Grepgrep使用正則表達式進行文本搜索
    Web fetchweb_fetch從 URL 獲取內容
    Web searchweb_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
    )

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

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

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