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?