「outcome」(アウトカム)は、最終結果がどのようなものであるべきか、そしてその品質をどのように測定するかをセッションに伝えます。エージェントはその目標に向かって作業し、アウトカムが満たされるまで自己評価と反復を繰り返します。
アウトカムを定義すると、ハーネスは自動的に「grader」(グレーダー)をプロビジョニングし、ルーブリックに照らして成果物を評価します。グレーダーは、メインエージェントの実装上の選択に影響されないよう、別の「context window」(コンテキストウィンドウ)を使用します。
グレーダーは、どの基準が合格または不合格だったかを要約した説明、あるいは成果物がルーブリックを満たしていることを確認する説明を返します。そのフィードバックは次の反復のためにエージェントに渡されます。
「rubric」(ルーブリック)は、基準ごとの採点を記述したマークダウンドキュメントです。ルーブリックは必須です。
ルーブリックの例:
# 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経由でアップロードします。
import time
from pathlib import Path
from anthropic import Anthropic
client = Anthropic()
RUBRIC = """# DCF Model Rubric
## Revenue Projections
- Uses historical revenue data from the last 5 fiscal years
- Projects revenue for at least 5 years forward
## Output Quality
- All figures are in a single .xlsx file with clearly labeled sheets
"""
Path("/tmp/rubric.md").write_text(RUBRIC)
rubric = client.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 としてマークします。これにより、新しいアウトカムを開始できます。これはアウトカムを開始するために送信するイベントです。受信時に、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
}グレーダーが1回の反復ループに対する評価を開始すると発行されます。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...",
"iteration": 0,
"processed_at": "2026-03-25T14:02:10Z"
}アウトカム評価サイクルが終了したときに発行されます。グレーダーが1回の反復の評価を終えた後、またはアウトカムがアクティブな間にセッションが中断されたときです。result フィールドは次に何が起こるかを示します。
| 結果 | 次の動作 |
|---|---|
satisfied | セッションは idle に遷移します。 |
needs_revision | エージェントは新しい反復サイクルを開始します。 |
max_iterations_reached | セッションが idle に遷移する前に、最後の確認ターンが1回続きます。それ以上の評価は実行されません。 |
failed | セッションは idle に遷移します。ルーブリックが成果物に適用できない場合、たとえば説明とルーブリックが互いに矛盾している場合に返されます。 |
interrupted | アウトカムがアクティブな間にセッションが中断されたときに発行されます。評価がまだ開始されていなかった場合でも発行されます。中断前に outcome_evaluation_start が発火していなかった場合、outcome_evaluation_start_id は空文字列になります。 |
{
"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/{session_id} をポーリングして outcome_evaluations[].result を読み取ることができます。評価が完了するまで、result は pending、running、または evaluating を報告します。
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を通じてそれらを取得します。
# このセッションで生成されたファイルを一覧表示
# scope_id フィルタリングにはファイルリクエストで managed-agents ベータが必要です
files = client.beta.files.list(scope_id=session.id, betas=["managed-agents-2026-04-01"])
for file in files:
print(file.id, file.filename)
# ファイルをダウンロード
if files.data:
content = client.files.download(files.data[0].id)
content.write_to_file("/tmp/output.txt")セッション作成時にユーザーごとの認証情報を登録します。
イベントを送信し、レスポンスをストリーミングし、実行中のセッションを中断またはリダイレクトします。
ファイルをアップロードしてサンドボックスにマウントし、読み取りと処理を行います。
Was this page helpful?