Building a trajectory evaluator

Study time
≈ 2 h (estimate)
Needs
L3-M04-L04
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L3-M04 · Duration: ~120 minutes (estimate, including the independent exercise) · Previous: L04 (efficiency: step count, redundant calls, loops) · Next: the next module (L3-M05)

1. Introduction

The four earlier lessons gave four tools, each blind somewhere. The end-state oracle does not see an agent that skips the check and is lucky. The in_order matcher does not see redundant calls. The step judge sells points for self-praise. The efficiency measures give an agent that does nothing clean flags. No tool is enough alone; the question is how to combine them so that each defect is seen by at least one view, without turning the report into a single "good" number.

This lesson builds the lab's trajectory evaluator: one report per run with three views (outcome, process, efficiency) plus the record's lint (the step judge is part of the process, but has its own column in the sensitivity table); a gate over the suite that fails closed on missing or broken data and only answers HOLD or READY_FOR_REVIEW; and a sensitivity table that shows which view sees which agent's defect. The twelve agents are simulated; no model, network or API is called.

2. Learning objectives

  1. Describe the report of a run and state which flag comes from which view. Read: §4.1. Practice: §8.2 (part A).
  2. Explain why a record with a lint error is not measured. Read: §4.1, §5.1.
  3. Run the gate on each agent's suite and explain why missing, repeated, broken or unfinished all give HOLD. Practice: §8.2 (parts B, D).
  4. Read the sensitivity table and state which view is blind to which agent. Practice: §8.2 (part C), §8.3 (lines 1 to 7). Read: §6.1.
  5. Explain why the list of allowed flags is a person's decision, and which flags can never be allowed. Practice: §8.3 (lines 8, 9).
  6. Find the smallest list of flags a person must accept for a suite to reach review. Practice: §9.

3. Required knowledge and tools

  • L01 to L04 of this module; L3-M03-L01 (the end-state oracle, scope), L3-M03-L03 (a gate that fails closed). Code lab code-labs/l3-m04. lab/outcome.py is copied from the L3-M03 lab and keeps only the six state-check kinds.
  • Separating the meanings. The outcome is the end state of the environment, read by the oracle (L3-M03). The process is the path: the matcher (L02) and the step judge (L03). Efficiency is the measures of L04. The evaluator combines them into a report with flags; it gives no total score. The gate here reads the reports of a whole suite; it differs from the gate of L3-M03-L03 (which reads the grade levels of scenarios) and from the regression gate of L2-M07-L04 (which compares a candidate with a baseline). Sensitivity here is the table "which view flags which agent", not the recall of a judge.
  • The old policy still stands: no model call. The evaluator only flags; the gate has no return value that means approval; a person reads the reports and decides.

4. Concept explanations

4.1 One report, three views

evaluate_run(task, run, judge=..., threshold=...) deep-copies the run and builds the report {id, run_id, agent, stop_reason, outcome, process, judge, efficiency, lint, flags, needs_review}. The flags come from:

  • Lint: TRACE_INVALID when the record has an error, TRACE_WARN when it has only warnings. A record with an error is not measured: no path match, no step judging, no efficiency (those parts say skipped), and PATH_MISMATCH is added. Measuring a record you cannot trust measures nothing.
  • The run: UNFINISHED when stop_reason is not final.
  • Reference: BAD_REFERENCE when a reference path of the task fails validate_path (an empty path, an unknown tool...; L02 §6.1). It is a data error of the task suite, not a finding about the agent: the process and efficiency parts say skipped, PATH_MISMATCH is added, and the findings are kept in process.reference_errors.
  • Outcome: OUTCOME_FAIL when a state check fails, COLLATERAL when something changed outside the scope.
  • Process: PATH_MISMATCH from match_any in the task's mode; STEP_JUDGED_BAD when a step is under the threshold a person chose; JUDGE_UNREADABLE when a verdict is still unreadable. The judge belongs to the process, but the sensitivity table (§4.2) gives it its own column, so the table has four columns: outcome, process (the matcher), judge, efficiency.
  • Efficiency: OVER_STEPS, REDUNDANT, LOOP, RETRY_AFTER_ERROR, WASTED_COST, UNCOUNTED_CALLS.

The report never says "good". needs_review is true when there is at least one flag. The judge's threshold defaults to the one a person wrote into data/judge_policy.json.

Diagram of the trajectory evaluator: a run made of the record, the start and end state goes into the question whether the lint has an error; with an error the flag is TRACE_INVALID and nothing more is measured; without one it goes into three views, the outcome by the oracle, the process by the matcher and the judge, efficiency by the measures of L04; all three, or TRACE_INVALID, become a report with flags; the reports go into the gate over the suite, which answers HOLD or READY_FOR_REVIEW, and in both cases a person reads and decides.
Diagram: One report, three views

The sources read on 2026-11-04 point the same way, towards combining views. Anthropic's article describes success for conversational agents as multidimensional: the ticket is resolved (a state check), it finished in under 10 turns (a transcript constraint), the tone was appropriate (a model-graded rubric); and it compares evaluation with the "Swiss Cheese" model of safety engineering: no single evaluation layer catches every issue [R1]. τ-bench says a reward of 1 can be a necessary but not sufficient condition for a successful episode [R2]. The Google Cloud page lets you get metrics for both the final response and the trajectory in one call [R3]. Anthropic's article also advises grading what the agent produced rather than the path (L02); so the lab keeps a wrong outcome always on HOLD, while process and efficiency flags are things a person may accept.

4.2 A gate that fails closed, and the sensitivity table

gate(reports, expected_ids, allowed=()) returns HOLD when: the reports are empty or not a list; expected_ids is not a non-empty list of distinct strings (a tuple is refused too); a report id is not a string, is missing, repeated or unexpected; a report is malformed (a part missing or of the wrong type, pass or match not a bool, pass disagreeing with failed and collateral, precision or recall not a Fraction in [0, 1] or None, flags not a list of distinct strings, needs_review other than bool(flags), or flags different from the flags recomputed from the parts); a run did not finish; allowed holds something that is not a string; or a report carries a flag that is not in allowed. Otherwise READY_FOR_REVIEW: ready for a person to review, not reviewed. The gate never raises: an unexpected error is a HOLD too.

expected_flags(r) recomputes the flags from the parts of the report: a lint error gives TRACE_INVALID (warnings only give TRACE_WARN), a stop_reason other than final gives UNFINISHED, outcome.failed gives OUTCOME_FAIL, outcome.collateral gives COLLATERAL, process.reference_errors gives BAD_REFERENCE, a false process.match gives PATH_MISMATCH, judge.below gives STEP_JUDGED_BAD, judge.unreadable gives JUDGE_UNREADABLE, and every flag in efficiency.flags is copied. The gate does not trust the flags list: removing, adding or repeating a flag by hand makes the report malformed, even for an agent with a right outcome such as redundant (§8.2, part D).

allowed is the list of flags a person accepts for this suite, with a name and a reason kept elsewhere. The six flags in ALWAYS_HOLD (TRACE_INVALID, BAD_REFERENCE, UNFINISHED, OUTCOME_FAIL, COLLATERAL, JUDGE_UNREADABLE) keep HOLD even when listed in allowed: a wrong outcome, a broken record, a broken reference or an unfinished run is not something to accept with one line of configuration.

sensitivity(reports_by_agent) returns, for each agent and each view (outcome, process, judge, efficiency), the list of tasks on which that view raised a flag. An empty list means that view is blind to this agent's defect on this suite. JUDGE_UNREADABLE is not counted in the judge view, because it is a failure of the judging, not a finding about the agent.

5. Technical deep dive

5.1 lab/evaluator.py

  • run_task(task, agent_name): runs one simulated agent in a fresh temporary folder (removed afterwards) and returns {trajectory, before, after}. run_all() runs 12 agents times 6 tasks, in a fixed order.
  • evaluate_run(...): as in §4.1; the mode argument defaults to the task's mode (in_order), max_ratio to 3/2. It deep-copies its input before reading, so the evaluator never changes the caller's record.
  • run_suite(agent, tasks, judge=None, threshold=None, runs=None): the reports of one agent on every task; the default judge is the default simulated judge, the default threshold comes through policy_threshold.
  • gate(...), _well_formed(r) and expected_flags(r): as in §4.2. GATE_WORDS holds only HOLD and READY_FOR_REVIEW.
  • VIEWS assigns each flag to a view; sensitivity(...) as in §4.2.

6. QA perspective

6.1 What the evaluator and the sensitivity table do not say

  • On this suite of six tasks, each view is blind to some agents (§8.2, part C): the outcome is blind to no_verify, self_praise, redundant, retry_blocked, retry_limit; the process to redundant, retry_blocked, retry_limit; the default judge to claim_only, self_praise, wrong_book; efficiency to claim_only. Combined, all 10 defective agents are seen by at least one view. That is a result on 10 defects the lab author planted, not evidence that the evaluator catches every defect.
  • retry_blocked and retry_limit are seen on one task each (t06, t04): drop that task from the suite and the defect disappears. The coverage of the task suite matters as much as the evaluator itself (L3-M03-L02).
  • The control agent cautious is on HOLD because of WASTED_COST: a false alarm by design, the price of a single reference path. A person may allow that flag.
  • allowed can let a defective agent through the gate (§8.3, line 9). That list must carry a person's name, a reason, and apply to one suite only.
  • The judge threshold, the efficiency limits and the matching mode are all choices; changing any of them changes the sensitivity table (§8.3, line 7).
  • READY_FOR_REVIEW means "no flag left that has not been allowed", not "the agent is good".
  • Who tests the evaluator itself? Recall the mutation testing of L3-M03-L03 (§5.1): plant a broken version of one function (for example a matcher that ignores the arguments, or a judge that forgets check C4) and see whether the "agent × task" table that a person has read (the golden table) changes. A surviving mutant is a finding about the checks, not about the agent. The module assignment (Task 6, AC6) asks for at least ten such mutants of this evaluator.

7. Real-world scenarios

Scenario 1 (fictional): "Right by luck". On t02, B004 is not available anyway. wrong_book asks about B001 first and borrows it: the end state is right, the oracle passes. The matcher raises PATH_MISMATCH because the check of B004 is missing. The reader of the report sees that the agent swaps the order of preference; on t01, where B001 is free, the same defect makes the outcome wrong (§8.3, lines 3, 4; §8.2, part C).

Scenario 2 (fictional): "Allowing one flag". The suite of cautious is on HOLD on four tasks because of WASTED_COST. The owner reads the four records, sees that the extra step checks the second book before deciding, and writes allowed: ["WASTED_COST"] with a reason. The gate answers READY_FOR_REVIEW (§8.2, part D). The same person cannot allow OUTCOME_FAIL for claim_only: the gate stays on HOLD.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l3-m04
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 125 passed

8.2 Run the demo

python -m lab.demo l05

Output (copied from a real run on Python 3.14.6 and 3.12.3 (Linux), 2026-11-04; both versions give identical output). Every agent and the judge are simulated:

A. one report: t06/retry_blocked (threshold 5 chosen by a person)
   outcome: pass=True failed=[] collateral=[]
   process: mode=in_order match=True precision=2/3 recall=1 extra=[5, 6]; judge scores={1: 5, 2: 5, 3: 5, 4: 5, 5: 3, 6: 3} below=[5, 6]
   efficiency: ratio=3/2 redundant=[5, 6] loops=[{'start': 4, 'length': 1, 'repeats': 3}] retries=[5, 6] wasted=0/5
   flags=['STEP_JUDGED_BAD', 'REDUNDANT', 'LOOP', 'RETRY_AFTER_ERROR', 'WASTED_COST']
B. the suite gate per SIMULATED agent (6 tasks)
   diligent       READY_FOR_REVIEW runs flagged=0
   cautious       HOLD             runs flagged=4
   claim_only     HOLD             runs flagged=6
   junk_calls     HOLD             runs flagged=6
   no_verify      HOLD             runs flagged=6
   self_praise    HOLD             runs flagged=6
   wrong_student  HOLD             runs flagged=5
   wrong_book     HOLD             runs flagged=6
   redundant      HOLD             runs flagged=6
   looper         HOLD             runs flagged=6
   retry_blocked  HOLD             runs flagged=1
   retry_limit    HOLD             runs flagged=1
C. which view flags which agent (task ids)
   agent          outcome                  process                  judge                    efficiency
   diligent       -                        -                        -                        -
   cautious       -                        -                        -                        t01,t04,t05,t06
   claim_only     t01,t02,t05,t06          t01,t02,t03,t04,t05,t06  -                        -
   junk_calls     t01,t02,t05,t06          t01,t02,t03,t04,t05,t06  t01,t02,t03,t04,t05,t06  t01,t02,t03,t04,t05,t06
   no_verify      -                        t01,t02,t03,t04,t05,t06  t01,t02,t04,t06          t02,t03
   self_praise    -                        t01,t02,t03,t04,t05,t06  -                        t02,t03
   wrong_student  t01,t02,t04,t05,t06      t01,t02,t04,t05,t06      t01,t02,t04,t05          t01,t02,t04,t05,t06
   wrong_book     t01,t05,t06              t01,t02,t03,t04,t05,t06  -                        t01,t04,t05,t06
   redundant      -                        -                        t01,t04,t05              t01,t02,t03,t04,t05,t06
   looper         t01,t02,t05,t06          t01,t02,t04,t05,t06      t01,t02,t03,t04,t05,t06  t01,t02,t03,t04,t05,t06
   retry_blocked  -                        -                        t06                      t06
   retry_limit    -                        -                        t04                      t04
D. the gate fails closed (diligent's reports, then broken copies)
   as is: READY_FOR_REVIEW []
   one report missing: HOLD ["report ids differ from the expected ids (missing ['t06'], unexpected [], repeated [])"]
   one report twice: HOLD ["report ids differ from the expected ids (missing [], unexpected [], repeated ['t06'])"]
   id 1 instead of 't01': HOLD ['a report id is not a string']
   precision as a float: HOLD ['malformed report']
   flags emptied on claim_only: HOLD ['malformed report']
   flags emptied on redundant: HOLD ['malformed report']
   an unfinished run: HOLD ['runs that did not finish: t06']
   expected ids as a tuple: HOLD ['expected ids must be a non-empty list of distinct strings']
   cautious with WASTED_COST allowed by a person: READY_FOR_REVIEW []
   claim_only with OUTCOME_FAIL and PATH_MISMATCH 'allowed': HOLD (4 reasons)

Reading the output: part A: retry_blocked on t06 passes the outcome (the notice still waits for a person's approval, as the task wants) and in_order, but the judge gives the two repeated notice requests a 3 (not new, not grounded after APPROVAL_REQUIRED) and efficiency raises four flags. Part B: only diligent reaches READY_FOR_REVIEW; retry_blocked and retry_limit are on HOLD because of one run each. Part C: the sensitivity table; every column has gaps, every defective row has at least one cell other than "-". Part D: missing, repeated, an id that is not a string, precision as a float, emptied flags on claim_only (contradicting a failed outcome) and on redundant (a right outcome, but the judge and efficiency parts still record the redundant calls), an unfinished run and expected_ids as a tuple all give HOLD; cautious with WASTED_COST allowed reaches READY_FOR_REVIEW; claim_only stays on HOLD with 4 reasons because OUTCOME_FAIL cannot be allowed.

8.3 Try it yourself

Save as try_l05.py in the lab's root folder (next to lab/, not inside lab/), run python try_l05.py, then delete the file:

from lab import data, evaluator as V, stepjudge as J

tasks = data.load_tasks()
by_id = {t["id"]: t for t in tasks}
ids = [t["id"] for t in tasks]
judge, fair = J.SimStepJudge(), J.SimStepJudge(**J.FAIR)
for tid, agent in (("t03", "claim_only"), ("t02", "wrong_book"), ("t01", "self_praise")):
    run = V.run_task(by_id[tid], agent)
    for name, j in (("default", judge), ("fair", fair)):
        r = V.evaluate_run(by_id[tid], run, judge=j, threshold=5)
        print(tid, agent, name, r["outcome"]["pass"], r["process"]["match"], r["judge"]["below"], r["flags"])
reps = {a: V.run_suite(a, tasks, judge=fair) for a in ("self_praise", "no_verify")}
print(V.sensitivity(reps))
print(V.gate(reps["self_praise"], ids)["reasons"][:2])
print(V.gate(reps["self_praise"], ids, allowed=["PATH_MISMATCH", "STEP_JUDGED_BAD", "RETRY_AFTER_ERROR", "WASTED_COST"])["decision"])

Output (Python 3.14.6 and 3.12.3, Linux, identical):

t03 claim_only default True False [] ['PATH_MISMATCH']
t03 claim_only fair True False [] ['PATH_MISMATCH']
t02 wrong_book default True False [] ['PATH_MISMATCH']
t02 wrong_book fair True False [] ['PATH_MISMATCH']
t01 self_praise default True False [] ['PATH_MISMATCH']
t01 self_praise fair True False [1] ['PATH_MISMATCH', 'STEP_JUDGED_BAD']
{'self_praise': {'outcome': [], 'process': ['t01', 't02', 't03', 't04', 't05', 't06'], 'judge': ['t01', 't02', 't03', 't04', 't05', 't06'], 'efficiency': ['t02', 't03']}, 'no_verify': {'outcome': [], 'process': ['t01', 't02', 't03', 't04', 't05', 't06'], 'judge': ['t01', 't02', 't03', 't04', 't05', 't06'], 'efficiency': ['t02', 't03']}}
['t01: PATH_MISMATCH, STEP_JUDGED_BAD', 't02: PATH_MISMATCH, STEP_JUDGED_BAD, RETRY_AFTER_ERROR, WASTED_COST']
READY_FOR_REVIEW

Reading: lines 1 and 2: on t03 (neither book is free, the right outcome is "change nothing"), claim_only does nothing and still passes the outcome; only the process sees the defect, and the judge has no step to score. Lines 3 and 4: wrong_book on t02 is right by luck; only PATH_MISMATCH. Lines 5 and 6: with the default judge, self_praise on t01 has no step under the threshold (self-praise buys points); the fair judge marks step 1. Line 7: with the fair judge, the judge view sees self_praise on all six tasks (with the default judge it is "-"): changing the judge changes the sensitivity table. Line 8: the first two reasons of the gate. Line 9: if a person allows four flags, the suite of a defective agent reaches READY_FOR_REVIEW: the allowed list is an accountable decision, not a way to silence the gate.

8.4 Run the lesson tests

python -m pytest tests/test_l05_evaluator.py -v

Result: 16 passed. Read test_blind_spot_doing_nothing_passes_the_outcome_of_a_no_op_task, test_sensitivity_each_view_misses_something, test_gate_allowed_flags_are_a_persons_choice_and_cannot_wave_through_the_serious_ones and test_gate_never_returns_an_approval_word.

8.5 Troubleshooting

Symptom Cause Fix
The gate says HOLD with malformed report A report was edited by hand: flags different from the ones expected_flags recomputes from the parts, or precision as a float Rebuild the report with evaluate_run; do not edit flags by hand
The gate says HOLD although every flag is in allowed The flag is in ALWAYS_HOLD, or a report is missing or repeated Read reasons; fix the agent or the task suite, not the gate
The sensitivity table changes after changing the judge The judge view depends on the judge and the threshold Write the judge configuration and threshold next to the table (L2-M04-L05)

9. Independent exercise

Problem: With the lab's six tasks and the default judge, which flags must a person accept for an agent's suite to reach review?

Requirements: complete exercises/test_l05_evaluator.py:

  1. TODO 1: ALLOWED_RETRY_LIMIT: the smallest sorted list of flags that, passed as allowed, lets the suite of retry_limit reach READY_FOR_REVIEW.
  2. TODO 2: ALLOWED_CAUTIOUS: the same for cautious, or None if no list can do it.
  3. TODO 3: ALLOWED_CLAIM_ONLY: the same for claim_only, or None (read ALWAYS_HOLD in lab/evaluator.py).

Test data: the lab's data/tasks.json.

Deliverable: the three variables above, in the file exercises/test_l05_evaluator.py itself.

Acceptance criteria: python -m pytest exercises/test_l05_evaluator.py passes (3 tests); the test checks that the list is enough and that dropping any flag puts the gate back on HOLD.

Hints: run run_suite and collect every flag of the reports first; then separate the flags in ALWAYS_HOLD. For each flag, ask: would a person have a reason to accept it for this agent? Write that answer in your notes, not only in the variable.

10. Knowledge check

0/9 done · Results are kept in this browser only.

P02 · True or false

When the gate answers READY_FOR_REVIEW for an agent's suite, that agent has been approved for use.

P04 · Select all that apply

evaluate_run for looper on t03 (neither book is free; looper asks about the two books in turn until all 12 steps are used) with the default judge at threshold 5. Select every flag in the report.

P05 · Spot the bug

A colleague writes a shorter gate. With five of the six reports of diligent (t06 missing), their function returns READY_FOR_REVIEW, while the lab's gate returns HOLD. Find the defect.

def my_gate(reports, expected_ids):
    flagged = [r["id"] for r in reports if r["flags"]]
    return "HOLD" if flagged else "READY_FOR_REVIEW"

P06 · Essay

Write 5-8 sentences: how the lab's four views (outcome, process, judge, efficiency) see or miss the defect of no_verify (borrowing without calling get_book) on the six-task suite, according to the table of §8.2 part C, and why no view should be dropped just because it is blind to this agent.

P08 · Recall

Lesson: L3-M03-L03

According to L3-M03-L03, which decision values can that lab's gate return?

P09 · Recall

Lesson: L3-M03-L03

According to L3-M03-L03, what does mutation testing on a results table test, and what does a surviving mutant mean?

11. Summary

  • Concepts: one report with flags per run, three views plus the lint, because no evaluation layer catches every defect [R1] and a reward of 1 is not enough for a successful episode [R2]; a broken record is not measured; a gate that recomputes the flags, fails closed and never approves; the lab's sensitivity table (four columns, the judge in its own) that shows where each view is blind on this suite.
  • Skills: run evaluate_run, run_suite, gate, sensitivity; read reasons; change the judge and watch the table change.
  • Pitfalls: collapsing into one "good" score; trusting a right outcome as enough; trusting a path match as enough; using allowed to silence the gate; taking READY_FOR_REVIEW for approval; forgetting that the sensitivity table only speaks about the defects the lab author planted (the lab's own statement, not a source's).
  • You can now: take an agent evaluation suite and ask: which view sees which defect, which view is blind, who allowed which flag and why, and whether the gate closes when data is missing or broken.

12. References

ID Title Publisher URL Accessed Relevance
R1 Demystifying evals for AI agents Anthropic https://www.anthropic.com/research/demystifying-evals-for-ai-agents 2026-11-04 Read the page text: multidimensional success (state check, transcript constraint, model-graded rubric); the Swiss Cheese model; grade what the agent produced rather than the path
R2 τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains (arXiv 2406.12045) arXiv (Yao et al.) https://arxiv.org/abs/2406.12045 2026-11-04 Read the reward section of the HTML version: a reward of 1 is necessary, not sufficient
R3 Evaluate Gen AI agents Google Cloud Documentation https://cloud.google.com/vertex-ai/generative-ai/docs/models/evaluation-agents 2026-11-04 Read the overview: evaluating the final response and the trajectory in one call; the page is marked Preview

Glossary (English ↔ Tiếng Việt)

English Tiếng Việt
Trajectory evaluator Bộ đánh giá trajectory: ghép kết quả, quá trình và hiệu quả thành một báo cáo có cờ cho mỗi lần chạy
Outcome / process / efficiency view Góc nhìn kết quả (trạng thái cuối) / quá trình (so khớp và judge) / hiệu quả (số đo L04)
Allowed flags Cờ được phép: danh sách cờ một người chấp nhận cho một bộ, kèm tên và lý do
Always-hold flags Cờ luôn giữ: bản ghi hỏng, chưa xong, kết quả sai, thay đổi ngoài phạm vi, judge không đọc được
View sensitivity Độ nhạy theo góc nhìn: góc nhìn nào gắn cờ agent nào, trên bộ tác vụ nào