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
    定義您的代理

    定義您的 Agent

    建立可重複使用、具版本控制的 Agent 配置。

    Was this page helpful?

    • Agent 配置欄位
    • 建立 Agent
    • 更新 Agent
    • Agent 生命週期
    • 封存 Agent

    Agent 是一種可重複使用、具版本控制的配置,用於定義角色與能力。它將模型、系統提示、工具、MCP 伺服器和技能整合在一起,塑造 Claude 在工作階段中的行為方式。

    只需建立一次 Agent 作為可重複使用的資源,並在每次開始工作階段時透過 ID 引用它。Agent 具有版本控制功能,更易於跨多個工作階段進行管理。

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

    Agent 配置欄位

    欄位說明
    name必填。Agent 的人類可讀名稱。
    model必填。驅動 Agent 的 Claude 模型。支援所有 Claude 4.5 及更新版本的模型。
    system定義 Agent 行為和角色的系統提示。系統提示與使用者訊息不同,使用者訊息應描述需要完成的工作。
    toolsAgent 可用的工具。結合了預建 Agent 工具、MCP 工具和自訂工具。
    mcp_servers提供標準化第三方功能的 MCP 伺服器。
    skills透過漸進式揭露提供特定領域情境的技能。
    callable_agents此 Agent 可呼叫的其他 Agent,用於多 Agent 協作。這是研究預覽功能;申請存取權限以試用。
    descriptionAgent 功能的說明。
    metadata用於自訂追蹤的任意鍵值對。

    建立 Agent

    以下範例定義了一個使用 Claude Sonnet 4.6 並可存取預建 Agent 工具集的程式碼撰寫 Agent。工具集讓 Agent 能夠撰寫程式碼、讀取檔案、搜尋網路等。請參閱 Agent 工具參考以取得支援工具的完整清單。

    若要搭配快速模式使用 Claude Opus 4.6,請將 model 作為物件傳入:{"id": "claude-opus-4-6", "speed": "fast"}。

    回應會回傳您的配置,並新增 id、version、created_at、updated_at 和 archived_at 欄位。version 從 1 開始,每次更新 Agent 時遞增。

    {
      "id": "agent_01HqR2k7vXbZ9mNpL3wYcT8f",
      "type": "agent",
      "name": "Coding Assistant",
      "model": {
        "id": "claude-sonnet-4-6",
        "speed": "standard"
      },
      "system": "You are a helpful coding agent.",
      "description": null,
      "tools": [
        {
          "type": "agent_toolset_20260401",
          "default_config": {
            "permission_policy": { "type": "always_allow" }
          }
        }
      ],
      "skills": [],
      "mcp_servers": [],
      "metadata": {},
      "version": 1,
      "created_at": "2026-04-03T18:24:10.412Z",
      "updated_at": "2026-04-03T18:24:10.412Z",
      "archived_at": null
    }

    更新 Agent

    更新 Agent 會產生新版本。傳入目前的 version 以確保您是從已知狀態進行更新。

    更新語意

    • 省略的欄位將被保留。 您只需包含想要變更的欄位。

    • 純量欄位(model、system、name 等)將以新值取代。system 和 description 可透過傳入 null 來清除。model 和 name 為必填欄位,無法清除。

    • 陣列欄位(tools、mcp_servers、skills、callable_agents)將完全由新陣列取代。若要完全清除陣列欄位,請傳入 null 或空陣列。

    Agent 生命週期

    操作行為
    更新產生新的 Agent 版本。
    列出版本擷取完整版本歷史記錄以追蹤隨時間的變更。
    封存Agent 變為唯讀。新工作階段無法引用它,但現有工作階段可繼續執行。

    列出版本

    擷取完整版本歷史記錄以追蹤 Agent 隨時間的變更情況。

    封存 Agent

    封存使 Agent 變為唯讀。現有工作階段可繼續執行,但新工作階段無法引用該 Agent。回應會將 archived_at 設定為封存時間戳記。

    後續步驟

    • 配置工具以自訂 Agent 可使用的功能。
    • 附加技能以獲得特定領域的專業知識。
    • 開始工作階段以引用您的 Agent。
    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 '{
        "name": "Coding Assistant",
        "model": "claude-sonnet-4-6",
        "system": "You are a helpful coding agent.",
        "tools": [{"type": "agent_toolset_20260401"}]
      }')
    
    AGENT_ID=$(jq -r '.id' <<< "$agent")
    AGENT_VERSION=$(jq -r '.version' <<< "$agent")
    updated_agent=$(curl -fsSL "https://api.anthropic.com/v1/agents/$AGENT_ID" \
      -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
    {
      "version": $AGENT_VERSION,
      "system": "You are a helpful coding agent. Always write tests."
    }
    EOF
    )
    
    echo "New version: $(jq -r '.version' <<< "$updated_agent")"

    Metadata 在鍵值層級進行合併。您提供的鍵值將被新增或更新。您省略的鍵值將被保留。若要刪除特定鍵值,請將其值設為空字串。

  1. 無操作偵測。 如果更新相對於目前版本沒有產生任何變更,則不會建立新版本,並返回現有版本。

  2. curl -fsSL "https://api.anthropic.com/v1/agents/$AGENT_ID/versions" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      | jq -r '.data[] | "Version \(.version): \(.updated_at)"'
    archived=$(curl -fsSL -X POST "https://api.anthropic.com/v1/agents/$AGENT_ID/archive" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01")
    
    echo "Archived at: $(jq -r '.archived_at' <<< "$archived")"