Claude Platform Docs
  • 消息
  • 托管智能体
  • 管理

Search...
⌘K
第一步
概览快速入门在控制台中构建原型
定义您的智能体
智能体设置工具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(评分器),根据评分标准来评估产出物。评分器使用独立的 "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?

  • 创建评分标准
  • 创建带有结果的会话
  • 结果事件
  • 定义结果用户事件
  • 结果评估开始
  • 结果评估进行中
  • 结果评估结束
  • 检查结果状态
  • 获取交付物