Interactive and Long-Horizon Task Evaluation › A worked example with an imperfect agent
Language AI HandbookAll chapters Numbers only become meaningful against trajectories. The next code block hand-writes four agent policies:
- a naive one that forgets the category
- a recovering one that fixes it
- an over-eager one that files twice
- an efficient one that skips the receipt read
Each runs against the same initial state and is compared across the five dimensions.
These are scripted action lists. The runner discards observations, so the list with the corrective suffix shows how the recovery score responds to a known repair. It does not show a policy discovering that repair. The naive and recovering lists share their first four actions. The recovering list replaces the final no-op with an edit and resubmission. The double-filing list makes four more attempts after the recovery, and the four-action list omits the receipt read. These comparisons affect completion, attempt cost and safety.
PythonIn [14]Expand
def run_policy(policy: list[dict]) -> EnvState:
s = EnvState()
for a in policy:
s, _, _ = transition(s, a)
return s
naive = [
{"action": "read_receipt", "receipt_id": "R-7"},
{"action": "create_report", "receipt_id": "R-7"},
{
"action": "set_field",
"report_id": "P-1",
"field": "amount",
"value": 26.50,
},
{"action": "submit", "report_id": "P-1"}, # fails: category is misc
{"action": "noop"},
]
recovering = naive[:-1] + [
{
"action": "set_field",
"report_id": "P-1",
"field": "category",
"value": "meals",
},
{"action": "submit", "report_id": "P-1"}, # succeeds after fix
]
double_filer = recovering + [
{"action": "create_report", "receipt_id": "R-8"},
{
"action": "set_field",
"report_id": "P-2",
"field": "amount",
"value": 412.00,
},
{
"action": "set_field",
"report_id": "P-2",
"field": "category",
"value": "travel",
},
{"action": "submit", "report_id": "P-2"}, # denied: second accepted
]
efficient = [
{"action": "create_report", "receipt_id": "R-7"},
{
"action": "set_field",
"report_id": "P-1",
"field": "amount",
"value": 26.50,
},
{
"action": "set_field",
"report_id": "P-1",
"field": "category",
"value": "meals",
},
{"action": "submit", "report_id": "P-1"},
]
policies = {
"naive": naive,
"recovering": recovering,
"double_filer": double_filer,
"efficient": efficient,
}
results = {
name: evaluate_trajectory(run_policy(pol)) for name, pol in policies.items()
}A subtlety in the policy definitions: recovering is built as naive[:-1] plus two actions, which means it shares the first four actions of naive verbatim, including the failing submit. That construction guarantees the two policies make the same error at the same step, so their differences arise after the common prefix, where repair and attempt count both change. Building policies from shared prefixes is a habit worth adopting: it makes the experimental comparison legible and eliminates a whole class of accidental confounds.
The four policies produce four different score profiles, so a table is the natural view.
PythonIn [15]Expand
import pandas as pd
cols = [
"passed",
"outcome",
"partial_credit",
"recovery",
"recovery_events",
"efficiency",
"steps",
"violations",
]
table = pd.DataFrame({name: r for name, r in results.items()}).T[cols]
table["recovery"] = table["recovery"].apply(
lambda v: "-" if v is None else f"{v:.2f}"
)ConsoleOut [16]Expand
passed outcome partial_credit recovery recovery_events efficiency steps violations naive False 0.0 0.5 0.00 1 1.0 5 [] recovering True 1.0 1.0 1.00 1 0.833333 6 [] double_filer False 0.0 1.0 1.00 1 0.5 10 [attempt_second_acceptance] efficient True 1.0 1.0 - 0 1.0 4 []
Each row is a diagnosis.
The naive agent fails the outcome, gets partial credit for the report it created with the right amount but the wrong category, and its one fixable error (NEEDS_CATEGORY) is unresolved, so its recovery score is 0. It also wastes a step on noop. Its outcome is 0.0 but its partial credit is 0.5, which correctly records that it did half the work: this is the case where a binary benchmark throws away signal.
The recovering list sets the category and resubmits successfully. Its outcome, recovery and partial credit are all 1.0. The shared prefix localizes the difference to the two alternative suffixes, which also have different lengths.
The double_filer agent submits the correct report and then tries to file a second one. Its violations list is non-empty (attempt_second_acceptance), so passed is False and outcome is 0.0 even though the target report is exactly right. This is the hard-fail convention at work: correctness of one artifact does not excuse a prohibited attempt elsewhere. An evaluation that reported only "is there an accepted report for R-7?" would call this a pass, and that is precisely the kind of task an internet-scale agent would learn to game.
The efficient agent reaches the goal in four steps, so its capped efficiency is min(1, 5/4) = 1.0. The recovering agent scores 5/6, the double filer scores 5/10, and the five-step naive agent scores 1.0 despite failing. The efficient list hard-codes the amount and category and skips the receipt read. A fixed guess can still pass a held-out receipt with matching expected values. To measure receipt use, vary needed values across the test set or add a read requirement to the trajectory scorer.
For a single task with a single run, efficiency_score is a single number. In practice you report its distribution over tasks and runs. A model that sometimes takes 3 steps and sometimes 40 has a heavy-tailed cost problem that an average hides and a p99 exposes. Report median and a high quantile, not just the mean.
The final-state divergence is worth quantifying, because it is what a state-diff makes obvious and a scalar outcome hides. The next block diffs the double-filer's and recovering agent's reports field by field.
PythonIn [17]Expand
def diff_reports(a: EnvState, b: EnvState) -> pd.DataFrame:
ids = sorted(set(a.reports) | set(b.reports))
rows = []
for rid in ids:
ra, rb = a.reports.get(rid), b.reports.get(rid)
rows.append(
{
"report_id": rid,
"A_status": ra.status if ra else None,
"B_status": rb.status if rb else None,
"A_amount": ra.amount if ra else None,
"B_amount": rb.amount if rb else None,
"A_category": ra.category if ra else None,
"B_category": rb.category if rb else None,
}
)
return pd.DataFrame(rows)
s_rec = run_policy(recovering)
s_dbl = run_policy(double_filer)
report_diff = diff_reports(s_rec, s_dbl)ConsoleOut [18]Expand
report_id A_status B_status A_amount B_amount A_category B_category
P-1 accepted accepted 26.5 26.5 meals meals
P-2 NaN draft NaN 412.0 NaN travelThe accepted P-1 has amount 26.50 and category meals in both trajectories. The double filer also leaves P-2 in draft with amount 412.00 and category travel because its submit was denied. The target report alone does not reveal that distinct attempted action.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!