# 策展 · X (Twitter) 🔥🔥🔥🔥🔥

> 作者：ClaudeDevs (@ClaudeDevs) · 平台：X (Twitter) · 日期：2026-05-07

> 原始來源：https://x.com/ClaudeDevs/status/2052069321355182447

## 中文摘要

Claude Managed Agents新增多Agent協調、成果循環自改善、夢境自學習與webhooks功能。

Claude Managed Agents推出多項重大更新，包括多Agent協調（multi-agent orchestration）、基於評分表的成果循環（outcomes loop）、夢境機制（dreaming）用於記憶整理，以及webhooks即時通知，這些功能透過`managed-agents-2026-04-01` beta header啟用，讓Agent能處理複雜任務並自主優化。

**多Agent協調架構**

多Agent協調讓主協調Agent（coordinator）委派任務給專門子Agent，每個子Agent擁有獨立context window與對話歷史，但共享container與filesystem以協調工作。協調Agent在主要thread（primary thread，等同session-level event stream）報告活動，子thread於runtime動態產生，最多支援25個並行thread。

適用模式包括：
- **並行化**：同時分派獨立子任務（如多來源搜尋、分別分析檔案），協調Agent再合成結果。
- **專門化**：路由至領域專屬Agent（如安全Agent或文件Agent），而非單一Agent負荷所有能力。
- **升級**：複雜子任務交由更強模型Agent處理。

配置協調Agent時，在`multiagent`設定子Agent清單，最多20個獨特Agent，且僅支援一層委派（depth >1忽略）。

```bash
coordinator=$(curl -fsS 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": "Engineering Lead",
  "model": "claude-opus-4-7",
  "system": "You coordinate engineering work. Delegate code review to the reviewer agent and test writing to the test agent.",
  "tools": [
    {
      "type": "agent_toolset_20260401"
    }
  ],
  "multiagent": {
    "type": "coordinator",
    "agents": [
      {"type": "agent", "id": "$REVIEWER_AGENT_ID"},
      {"type": "agent", "id": "$TEST_WRITER_AGENT_ID"}
    ]
  }
}
EOF
)
```

其他語言SDK如Python、TypeScript等類似，`multiagent.agents`可指定`{"type": "agent", "id": agent.id}`（預設最新版本）、特定`version`，或`{"type": "self"}`產生自身副本。

建立session引用協調Agent：

```bash
session=$(curl -fsSL https://api.anthropic.com/v1/sessions \
  -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
{
  "agent": "$COORDINATOR_ID",
  "environment_id": "$ENVIRONMENT_ID"
}
EOF
)
SESSION_ID=$(jq -r '.id' <<< "$session")
```

**Thread管理與事件**

主要thread為`/v1/sessions/:id/events/stream`，顯示所有活動濃縮視圖，包括子Agent工作起止與工具權限請求。列出所有thread：

```bash
curl -fsS "https://api.anthropic.com/v1/sessions/$SESSION_ID/threads" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01" \
  | jq -r '.data[] | "[\(.agent.name)] \(.status)"'
```

中斷特定thread（省略`session_thread_id`則針對主要thread）：

```bash
curl -fsS "https://api.anthropic.com/v1/sessions/$SESSION_ID/events?beta=true" \
  -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 "{\"events\": [{\"type\": \"user.interrupt\", \"session_thread_id\": \"$THREAD_ID\"}]}"
```

封存thread（僅idle狀態可封存，running或requires_action需先中斷）：

1. 中斷thread。
2. 執行封存：

```bash
curl -fsS -X POST "https://api.anthropic.com/v1/sessions/$SESSION_ID/threads/$THREAD_ID/archive" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01"
```

主要thread事件包括`session.thread_created`、`session.thread_status_running`、`session.thread_status_idle`（含`stop_reason`）、`session.thread_status_terminated`、`agent.thread_message_received`（含`from_session_thread_id`、`from_agent_name`、`content`）、`agent.thread_message_sent`（含`to_session_thread_id`、`to_agent_name`、`content`）。

子thread事件可透過`/v1/sessions/$SESSION_ID/threads/$THREAD_ID/stream?beta=true`串流或`/v1/sessions/$SESSION_ID/threads/$THREAD_ID/events`列出，包含完整推理與工具呼叫。

工具權限或自訂工具結果會跨發至主要thread，帶`session_thread_id`，回應`user.tool_confirmation`或`user.custom_tool_result`時伺服器自動路由。

**成果循環自改善**

成果（outcome）將session從對話轉為工作，定義「完成」標準與品質測量，Agent自主迭代至達標。harness自動配置獨立grader子Agent，使用分離context window評估產出，避免主Agent實作偏見影響。

Rubric為Markdown文件，描述可評分標準，如：

```markdown
# DCF Model Rubric

## Revenue Projections
- Uses historical revenue data from the last 5 fiscal years
- Projects revenue for at least 5 years forward
- Growth rate assumptions are explicitly stated and reasonable

## Cost Structure
- COGS and operating expenses are modeled separately
- Margins are consistent with historical trends or deviations are justified

## Discount Rate
- WACC is calculated with stated assumptions for cost of equity and cost of debt
- Beta, risk-free rate, and equity risk premium are sourced or justified

## Terminal Value
- Uses either perpetuity growth or exit multiple method (stated which)
- Terminal growth rate does not exceed long-term GDP growth

## Output Quality
- All figures are in a single .xlsx file with clearly labeled sheets
- Key assumptions are on a separate "Assumptions" sheet
- Sensitivity analysis on WACC and terminal growth rate is included
```

上傳rubric（需`files-api-2025-04-14` beta）：

```bash
rubric=$(curl -fsSL https://api.anthropic.com/v1/files \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01,files-api-2025-04-14" \
  -F file=@/tmp/rubric.md)
rubric_id=$(jq -r '.id' <<<"$rubric")
```

建立session後發`user.define_outcome`（Agent立即開始，無需額外訊息）：

```bash
session=$(curl -fsSL https://api.anthropic.com/v1/sessions \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01" \
  --json @- <<EOF
{
  "agent": "$agent_id",
  "environment_id": "$environment_id",
  "title": "Financial analysis on Costco"
}
EOF
)
session_id=$(jq -r '.id' <<<"$session")

curl -fsSL "https://api.anthropic.com/v1/sessions/$session_id/events" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01" \
  --json @- >/dev/null <<EOF
{
  "events": [
    {
      "type": "user.define_outcome",
      "description": "Build a DCF model for Costco in .xlsx",
      "rubric": {"type": "text", "content": "# DCF Model Rubric\n..."},
      "max_iterations": 5
    }
  ]
}
EOF
```

`max_iterations`預設3、最大20。事件包括`span.outcome_evaluation_start`（iteration從0計）、`span.outcome_evaluation_ongoing`（心跳）、`span.outcome_evaluation_end`（result為`satisfied`轉idle、`needs_revision`再迭代、`max_iterations_reached`最終修訂後idle、`failed`轉idle、`interrupted`）。

檢查狀態：串流事件或輪詢`GET /v1/sessions/:id`的`outcome_evaluations[].result`。產出檔案在`/mnt/session/outputs/`，透過Files API下載（scope_id=session_id）。

**Webhooks即時通知**

Webhooks通知主要狀態變更，無需維持SSE串流或輪詢。事件僅含`type`與`id`，需自行GET物件。支援事件：

| Event | Trigger |
|-------|---------|
| `session.status_run_started` | 轉`running` |
| `session.status_idled` | 等待輸入 |
| `session.status_rescheduled` | 自動重試暫時錯誤 |
| `session.status_terminated` | 終止錯誤 |
| `session.thread_created` | 新多Agent thread |
| `session.thread_idled` | 多Agent等待輸入 |
| `session.thread_terminated` | 多Agent thread封存 |
| `session.outcome_evaluation_ended` | 單迭代評估完成 |

在[Console](https://platform.claude.com/settings/workspaces/default/webhooks)註冊HTTPS 443端點，選擇事件類型，獲取`whsec_`簽名密鑰。驗證簽名（SDK `unwrap()`檢查5分鐘內有效）：

Python範例：

```python
from flask import Flask, request
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_WEBHOOK_SIGNING_KEY from env
app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
def webhook():
    try:
        event = client.beta.webhooks.unwrap(
            request.get_data(as_text=True),
            headers=dict(request.headers),
        )
    except Exception:
        return "invalid signature", 400

    if event.data.type == "session.status_idled":
        print("session idled:", event.data.id)

    return "", 200
```

處理後回`2xx`，否則重試（相同`event.id`為重試，可捨棄）。無順序保證，使用`created_at`排序。連續20失敗自動停用。

**夢境自學習機制**

夢境（Dreams）為研究預覽（需[申請存取](https://claude.com/form/claude-managed-agents)），需`dreaming-2026-04-21` beta，讓Claude反思多session，整理Agent記憶：合併重複、替換過時/矛盾、新增洞見。輸入記憶層不變，輸出新層。

建立dream（輸入記憶層+最多100 session，使用`claude-opus-4-7`或`claude-sonnet-4-6`）：

```bash
dream=$(curl -s https://api.anthropic.com/v1/dreams \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21" \
  -H "content-type: application/json" \
  --data @- <<EOF
{
  "inputs": [
    { "type": "memory_store", "memory_store_id": "$store_id" },
    { "type": "sessions", "session_ids": ["$session_a", "$session_b"] }
  ],
  "model": "claude-opus-4-7",
  "instructions": "Focus on coding-style preferences; ignore one-off debugging notes."
}
EOF
)
dream_id=$(jq -r '.id' <<< "$dream")
```

輪詢狀態（pending→running→completed/failed/canceled），running時`session_id`可串流觀察。完成後`outputs[]`有新記憶店ID，可附加至新session。

取消（pending/running轉canceled）：

```bash
curl -s -X POST "https://api.anthropic.com/v1/dreams/$dream_id/cancel" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: managed-agents-2026-04-01,dreaming-2026-04-21"
```

封存（僅終止狀態）。錯誤如`input_memory_store_unavailable`（輸入中途刪除）。計費按token，限制：每dream 100 session、`instructions` 4096字元。

**入門資源**

使用Claude Code的`/claude-api` skill或[OSS repo](https://github.com/anthropics/skills/tree/main/skills/claude-api)快速上手。詳細文件：[多Agent](https://platform.claude.com/docs/en/managed-agents/multi-agent)、[成果](https://platform.claude.com/docs/en/managed-agents/define-outcomes)、[Webhooks](https://platform.claude.com/docs/en/managed-agents/webhooks#supported-event-types)、[夢境](https://platform.claude.com/docs/en/managed-agents/dreams)。這些更新強化Agent自主性，適用複雜工程任務，但需注意thread限25、迭代max20等限制。

## 標籤

Agent, 功能更新, 框架更新, 記憶系統, Anthropic, Claude
