Claude Platform Docs
  • Messages
  • 託管代理
  • 管理

Search...
⌘K
第一步
概覽快速入門在 Console 中建立原型
定義您的代理
代理設定工具MCP 連接器權限政策代理技能
設定代理環境
雲端環境設定雲端沙箱參考
將工作委派給您的代理
啟動工作階段工作階段操作工作階段事件串流訂閱 Webhook定義結果使用保管庫進行驗證
管理代理上下文
存取 GitHub附加與下載檔案
進階協調
多代理工作階段排程部署
參考
託管代理參考
處理檔案
Files APIPDF 支援
技能
概覽最佳實踐企業技能
MCP
遠端 MCP 伺服器
雲端平台上的 Claude
AWS 上的 Claude Platform

Log in
定義結果
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Claude Platform Docs

Solutions

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

Partners

  • Claude on AWS
  • Claude on Google Cloud

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
託管代理/將工作委派給您的代理

定義成果

告訴代理程式「完成」的樣貌,並讓它反覆迭代直到達成目標。

outcome 將工作階段從對話提升為工作。您定義最終結果應該是什麼樣子以及如何衡量品質。代理程式會朝著該目標努力,自我評估並反覆迭代,直到達成成果為止。

當您定義成果時,框架會自動配置一個評分器(grader),根據評分標準(rubric)來評估產出物。評分器使用獨立的「context window」(上下文視窗),以避免受到主代理程式實作選擇的影響。

評分器會回傳一份說明,摘要哪些標準通過或未通過,或確認產出物符合評分標準。該回饋會傳回給代理程式,用於下一次迭代。



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

建立評分標準

評分標準是一份描述各項標準評分方式的 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

在 user.define_outcome 上以內嵌文字的方式傳遞評分標準(請參閱下一節),或透過 Files API 上傳以便在多個工作階段中重複使用。



透過 Files API 上傳需要同時使用 managed-agents-2026-04-01 和 files-api-2025-04-14 兩個 beta 標頭。

rubric = client.beta.files.upload(file=Path("/tmp/rubric.md"))
print(f"Uploaded rubric: {rubric.id}")

建立具有成果的工作階段

建立工作階段後,傳送 user.define_outcome 事件。代理程式會立即開始工作;不需要額外的使用者訊息事件。

# 建立工作階段
session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    title="Financial analysis on Costco",
)

# 定義成果 — 代理程式收到後即開始工作
client.beta.sessions.events.send(
    session_id=session.id,
    events=[
        {
            "type": "user.define_outcome",
            "description": "Build a DCF model for Costco in .xlsx",
            "rubric": {"type": "text", "content": RUBRIC},
            # 或:"rubric": {"type": "file", "file_id": rubric.id},
            "max_iterations": 5,  # optional; default 3, max 20
        }
    ],
)

成果事件

成果導向工作階段的進度會顯示在事件串流上。

  • agent.* 事件(例如訊息和工具使用)顯示朝向成果的進度。
  • span.outcome_evaluation_* 事件僅在成果導向的工作階段中發出,顯示迭代迴圈的次數以及評分器的回饋過程。
  • 您也可以向成果導向的工作階段傳送 user.message 事件,以在代理程式工作進行中引導其方向,但這並非必要:代理程式會自行朝向成果努力,反覆迭代直到成功或用盡迭代次數。
  • user.interrupt 事件會暫停目前成果的工作,並將 span.outcome_evaluation_end.result 標記為 interrupted,讓您可以啟動新的成果。
  • 在最終成果評估之後,工作階段可以繼續作為對話式工作階段,或啟動新的成果。工作階段會保留先前成果的歷史記錄。

定義成果使用者事件



一次僅支援一個成果,但您可以依序串接多個成果。要執行此操作,請在前一個成果的終止事件之後傳送新的 user.define_outcome 事件。

這是您傳送以啟動成果的事件。收到後會回傳相同內容,並包含 processed_at 時間戳記和 outcome_id。

{
  "type": "user.define_outcome",
  "description": "Build a DCF model for Costco in .xlsx",
  "rubric": { "type": "file", "file_id": "file_01..." },
  "max_iterations": 5
}

成果評估開始

當評分器開始對一個迭代迴圈進行評估時發出一次。iteration 欄位是從 0 開始的修訂計數器:0 是第一次評估,1 是第一次修訂後的重新評估,依此類推。

{
  "type": "span.outcome_evaluation_start",
  "id": "sevt_01def...",
  "outcome_id": "outc_01a...",
  "iteration": 0,
  "processed_at": "2026-03-25T14:01:45Z"
}

成果評估進行中

評分器執行期間發出的心跳訊號。評分器的內部推理是不透明的:您可以看到它正在運作,但看不到它在思考什麼。

{
  "type": "span.outcome_evaluation_ongoing",
  "id": "sevt_01ghi...",
  "outcome_id": "outc_01a...",
  "processed_at": "2026-03-25T14:02:10Z"
}

成果評估結束

評分器完成一次迭代評估後發出。result 欄位指示接下來會發生什麼。

結果下一步
satisfied工作階段轉換為 idle。
needs_revision代理程式開始新的迭代週期。
max_iterations_reached不再有進一步的評估週期。代理程式可能會在工作階段轉換為 idle 之前執行最後一次修訂。
failed工作階段轉換為 idle。當評分標準根本不符合任務時回傳,例如描述與評分標準相互矛盾。
interrupted僅在中斷前已觸發 outcome_evaluation_start 時發出。
{
  "type": "span.outcome_evaluation_end",
  "id": "sevt_01jkl...",
  "outcome_evaluation_start_id": "sevt_01def...",
  "outcome_id": "outc_01a...",
  "result": "satisfied",
  "explanation": "All 12 criteria met: revenue projections use 5 years of historical data, WACC assumptions are stated, sensitivity table is included...",
  "iteration": 0,
  "usage": {
    "input_tokens": 2400,
    "output_tokens": 350,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 1800
  },
  "processed_at": "2026-03-25T14:03:00Z"
}

檢查成果狀態

您可以在事件串流上監聽 span.outcome_evaluation_end,或輪詢 GET /v1/sessions/:id 並讀取 outcome_evaluations[].result:

session = client.beta.sessions.retrieve(session.id)

for outcome in session.outcome_evaluations:
    print(f"{outcome.outcome_id}: {outcome.result}")
    # outc_01a...: satisfied

擷取交付成果

代理程式會將輸出檔案寫入沙箱內的 /mnt/session/outputs/。一旦工作階段處於閒置狀態,透過限定於該工作階段範圍的 Files API 擷取這些檔案:

# 列出此工作階段產生的檔案
files = client.beta.files.list(scope_id=session.id)
for f in files:
    print(f.id, f.filename)

# 下載檔案
if files.data:
    content = client.beta.files.download(files.data[0].id)
    content.write_to_file("/tmp/output.txt")

Was this page helpful?

  • 建立評分標準
  • 建立具有成果的工作階段
  • 成果事件
  • 定義成果使用者事件
  • 成果評估開始
  • 成果評估進行中
  • 成果評估結束
  • 檢查成果狀態
  • 擷取交付成果