アウトカムは、最終結果がどのようなものであるべきか、そしてその品質をどのように測定するかをセッションに伝えます。エージェントはそのターゲットに向かって作業し、アウトカムが満たされるまで自己評価と反復を行います。
アウトカムを定義すると、ハーネスは自動的にグレーダーをプロビジョニングし、ルーブリックに照らして成果物を評価します。グレーダーは、メインエージェントの実装上の選択に影響されないように、別のコンテキストウィンドウを使用します。
グレーダーは、どの基準が合格または不合格だったかを要約した説明、あるいは成果物がルーブリックを満たしていることを確認する説明を返します。そのフィードバックは、次の反復のためにエージェントに渡されます。
ルーブリックは、基準ごとの採点を記述したマークダウンドキュメントです。ルーブリックは必須です。
ルーブリックの例:
# 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 イベントを送信します。エージェントはすぐに作業を開始します。追加のユーザーメッセージイベントは必要ありません。
# 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 としてマークし、新しいアウトカムを開始できるようにします。これは、アウトカムを開始するために送信するイベントです。受信時にエコーバックされ、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 フィールドは次に何が起こるかを示します。
| 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を通じてそれらを取得します。
# List files produced by this session
# scope_id filtering requires the managed-agents beta on the files request
files = client.beta.files.list(scope_id=session.id, betas=["managed-agents-2026-04-01"])
for file in files:
print(file.id, file.filename)
# Download a file
if files.data:
content = client.files.download(files.data[0].id)
content.write_to_file("/tmp/output.txt")セッション作成時にユーザーごとの認証情報を登録します。
イベントの送信、レスポンスのストリーミング、実行中のセッションの中断やリダイレクトを行います。
ファイルをアップロードし、読み取りと処理のためにサンドボックスにマウントします。
Was this page helpful?