加载中...
搜索...
启动会话会话事件流订阅 Webhook定义产出目标使用保管库进行身份验证
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
解决方案
合作伙伴
学习
公司
学习
帮助与安全
条款与政策
定义产出目标
告诉代理 什么样才算完成,然后让它持续迭代,直到真正达到目标。
复制页面
outcome 将一个会话从_对话_提升为_工作_。你来定义最终结果应该是什么样,以及如何衡量质量。代理会朝这个目标推进,自我评估并持续迭代,直到满足该产出目标。
当你定义一个产出目标时,运行框架会自动配置一个_grader_,按照评分标准评估产物。它使用独立的上下文窗口,避免受到主代理实现选择的影响。
评分器会按每项标准返回拆解结果,或者确认产物满足评分标准,或者指出当前工作与要求之间的具体差距。这些反馈会再交还给代理,用于下一轮迭代。
所有 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 上传,便于跨会话复用。
需要 beta 请求头 files-api-2025-04-14。
curl CLI Python TypeScript C#Go Java PHP Ruby
rubric = client.beta.files.upload(file=Path("/tmp/rubric.md"))
print(f"Uploaded rubric: {rubric.id}")
创建带有产出目标的会话
创建会话后,发送一个 user.define_outcome 事件。代理会立刻开始工作,不需要额外再发送用户消息事件。
curl CLI Python TypeScript C#Go Java PHP Ruby
# Create a session
session = client.beta.sessions.create(
agent=agent.id,
environment_id=environment.id,
title="Financial analysis on Costco",
)
# Define the outcome — agent starts working on receipt
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},
# or: "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:
curl CLI Python TypeScript C#Go Java PHP Ruby
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 获取这些文件:
curl CLI Python TypeScript C#Go Java PHP Ruby
```
List files produced by this session
files = client.beta.files.list(scope_id=session.id) for f in files: print(f.id, f.filename)
Download a file
if files.data: content = client.beta.files.download(files.data[0].id) content.write_to_file("/tmp/output.txt")