Module L3-M04 exercises: a trajectory evaluation suite for ThuVien Mini v2, from the record and the matcher to the calibrated step judge, efficiency and a gate that fails closed

Study time
≈ 4 h (estimate)
Updated
2026-11-04
Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Estimated time: ~4 hours for someone who has finished the five independent exercises of L01-L05 (an estimate, not measured with real learners). Main tools: lab.trace, lab.match, lab.stepjudge, lab.calibrate, lab.efficiency, lab.evaluator, lab.agents in code-labs/l3-m04. Every agent, task, tool, cost (cu, a made-up cost unit), time (ticks, a made-up time unit), score, label and result in the lab is simulated (deterministic functions written by the lab author): no model call, no real server, no API key needed; the step judge is a checklist, not a model; tools run only in memory and in a temporary folder.

Main hands-on exercise

Business context

The ThuVien Mini team (fictional) is moving the library assistant to ThuVien Mini v2 for a new school: student S0101, other books, and the same six tasks (lend the first choice or the second, keep a note, queue a notice when it is approved). A colleague's ticket says: "every v2 task ends in the right state, so the agents are fine". That line does not say whether an agent checked before borrowing, asked the same thing three times, retried a call that was blocked, or praised itself to a judge. You need to build a trajectory evaluation suite for v2 with its reports, and then answer: what does this suite catch, and what does it not yet prove?

The problem

An end-state oracle is blind to an agent that borrowed without checking and was lucky; an in_order matcher allows extra calls; a step judge can be bought with a self-claim; an efficiency measure gives an agent that does nothing a clean sheet; a gate can be talked into letting a defect through with one line of configuration. Your job is to measure each view separately under the fixed configuration below, say what each view does not prove, and let a person record the threshold and the final decision. The lint, matcher, judge, measures and gate only flag; the gate fails closed and can only answer HOLD or READY_FOR_REVIEW; every real effect needs a person's approval.

Input data

The lab's data is in code-labs/l3-m04/data/ (tasks.json, step_labels.json, arg_rules.json, judge_policy.json, tools.json, books.json, documents.json) and is fictional; do not edit lab/, data/, tests/ or exercises/. You write yourself every data file of the trajectory_suite/ package.

Fixed configuration (so that every submission is reproducible and comparable):

Item Value
Tasks (Task 1) tasks_v2.json: the six tasks v01 to v06 taken from the lab's t01 to t06 (data/tasks.json), with every identifier changed by the mapping table below (id tNN becomes vNN); keep the structure, checks, scope, setup, the reference paths and the mode in_order; edit goal, params, every book, student and note name and the approval key by the table
Step labels (Task 1) step_labels_v2.json: the lab's 30 labels (data/step_labels.json) with id hNN changed to wNN and the run tNN/agent changed to vNN/agent; the same index, human, split and why
Agents and runs (all tasks) the 12 agents of lab.agents.DEFECTS in that order, each run once on the six tasks with lab.evaluator.run_all(tasks, list(DEFECTS)): 72 runs
Matching (Task 2) the first reference path of each task (reference.paths[0], the only one), the lab's default argument rules (data/arg_rules.json); "counted calls" means lab.match.counted_calls(trajectory)
Step judge (Task 3) the default judge lab.stepjudge.SimStepJudge() and the fair judge SimStepJudge(**FAIR); every label is judged once with lab.calibrate.label_items; dev sweep for thresholds 1 to 5
Threshold (Tasks 3 and 5) value 5, written in review.json together with the name of one person and a reason, and read only through lab.calibrate.policy_threshold (a missing name or ci, auto, script, judge, default is refused)
Evaluator (Tasks 4 and 5) lab.evaluator.run_suite(agent, tasks, runs=runs, threshold=5) with the default judge; gate(reports, ids) with an empty allowed
Reproduction (Task 6) Six Markdown reports and table.json, plus expected_v2.json, review.json and notes/decisions.md; no timestamps, no Python version

The mapping table (apply it simultaneously, to the original text, everywhere it occurs, including goal, note names and the approval key; B003 becomes B002 and does not then become B006):

In the lab In v2
B001 B005
B002 B006
B003 B002
B004 B004 (unchanged)
S0042 S0101
S0007 S0099
loan_s0042 loan_s0101
notice-s0042-b001 notice-s0101-b005

Signature of a run (one cell of table.json, key agent/vNN): the six fields [outcome.pass, process.match, precision, recall, judge.below, flags] of the report that run_suite returns, where precision and recall are written as text of a reduced fraction ("3/4", "1") or null when they are None. Every table in the reports has one row per agent in the order of DEFECTS and one column per task v01 to v06; a fraction is written reduced (3/4; a whole number without a denominator), None as -.

Tasks

  1. Records and redaction (L01). Write tasks_v2.json and step_labels_v2.json by the table. Report traces.md: a 12-row table agent | lint errors | warnings | redactions | unfinished runs over each agent's six runs: the number of lint_trace findings of level error; the warnings as CODE xN (codes in alphabetical order, separated by commas, or none); the total number of entries in redact(trajectory)["redactions"]; the number of runs whose stop_reason is not final.
  2. Matching (L02). Write in mine.py two functions over the counted calls calls of a run and the path path, with same(ref, call) deciding whether a reference call and a counted call match (in the reports same is lab.match.call_matches(ref, call, rules) with the default rules):
    • edit_distance(calls, path, same): the edit distance (Levenshtein), the smallest number of insertions, deletions and replacements of one call that turn one list into the other; 0 when the run is the path.
    • first_divergence(calls, path, same): compare position by position from position 0: when the run runs out of calls before the path ends, return ("missing", k) with k the position in the path; when call k does not match path[k], return ("wrong", calls[k]["index"]) (the step index in the record); when the path ends and the run still has calls, return ("extra", calls[len(path)]["index"]); None when the run matches the path exactly.
    • Both raise ValueError when calls or path is not a list. Report matching.md with four tables: (i) the in_order cell: Y or N, a space, p= and the precision, a space, r= and the recall, - when undefined (for example Y p=3/4 r=1 is a match with precision 3/4 and recall 1; N p=- r=0 is no match, precision None, recall 0); (ii) "runs that match, per mode": for each agent the number of tasks (of 6) that match under each mode, columns in the order of lab.match.MODES; (iii) the edit distance; (iv) the first divergence, cell kind@n or -.
  3. Step judge (L03). Report judge.md with one part per judge (default, then fair), each with: the line Unreadable verdicts dropped: <label ids or none>.; the dev sweep table threshold | tp | fp | fn | tn | agreement | kappa | false accept | false reject; the line Suggestion with a false-accept cap of 1/10: <x>; with a cap of 1/2: <y>. (from suggest_threshold, None when no threshold qualifies); the line Test split at the person's threshold 5: tp a, fp b, fn c, tn d; kappa k; false accept f.. Then the probe table of the default judge on the 30 labelled steps (probe with pad, claim, late; columns probe | up | same | down | dropped | mean change) and the line Threshold in use: 5, chosen by <the name in review.json>.. In review.json you write the threshold {value, chosen_by, reason} as a person's decision, not a test's or CI's.
  4. Efficiency (L04). Report efficiency.md: a 12 × 6 table whose cell is the step ratio of the report, a space, then the efficiency flags of the report, each cut to its first three letters and joined by + (OVE, RED, LOO, RET, WAS, UNC), or ok when there is none.
  5. Evaluator and gate (L05). Report evaluator.md: a 12-row table agent | gate | runs flagged | outcome | process | judge | efficiency (the gate decision; the number of reports with at least one flag; for each view the tasks of sensitivity, separated by commas, or -); four lines Blind for <view>: <agents>. (views in the order outcome, process, judge, efficiency; only the 10 defective agents, without diligent and cautious; none when empty); the line Defective agents seen by at least one view: N of 10.; the line Person's decision on file: ... from the decision field of review.json (none (the gate decides nothing) when it is null).
  6. Mutations, the golden table and reproduction. Generate table.json (72 signatures). Read each cell once and then write it into expected_v2.json (the golden table). Write check_suite() returning the sorted list of cells that differ from the golden table, and check_gate() returning the list of fixed gate cases that fail; the cases are at least: diligent gives READY_FOR_REVIEW; a missing report, a repeated report, a non-string id, a malformed report (recall as a float), an unfinished run, the flags removed from a failing run (claim_only) and from two agents with a right outcome (redundant, retry_blocked), expected_ids as a tuple and an outcome failure listed in allowed each give HOLD; and no output contains APPROVED. Report mutation.md: No mismatch with the pinned table (72 cells). (or the mismatching cells) and Gate cases failing: none (or their names). Write build_trajectory_suite.py, which generates seven files in the output folder (six reports and table.json; every figure comes from lab and mine, none typed by hand), and test_build_trajectory_suite.py, which checks AC1-AC6 on the text of the reports you generated. Write notes/decisions.md with exactly five sections: Records and redaction, Matching, Step judge, Mutations, What the suite does not prove (a submission in Vietnamese uses the section names of the Vietnamese version). The Mutations section lists at least ten broken versions of the lab (the matcher, argument rules, the judge, the parser, the efficiency measures, the outcome, the lint or the evaluator) that you installed, which the golden table or check_gate() killed and which survived, with the reason. The last section answers: how far can this suite be trusted, and what is it not yet usable for.

Deliverables

trajectory_suite/
  __init__.py                    (file rỗng)
  mine.py                        (Nhiệm vụ 2: edit_distance, first_divergence)
  tasks_v2.json                  (Nhiệm vụ 1)
  step_labels_v2.json            (Nhiệm vụ 1)
  review.json                    (Nhiệm vụ 3: ngưỡng và quyết định của một người)
  expected_v2.json               (Nhiệm vụ 6: bảng vàng 72 ô)
  build_trajectory_suite.py      (Nhiệm vụ 6; chạy: python -m trajectory_suite.build_trajectory_suite <thư mục ra>)
  test_build_trajectory_suite.py (Nhiệm vụ 6; chạy: python -m pytest trajectory_suite)
  notes/
    decisions.md                 (năm mục)

Put the trajectory_suite/ folder inside code-labs/l3-m04 so that import lab works. Run from the lab folder. Use relative imports inside the package (from . import mine). Do not create or edit any file under .github/; every tool runs in a temporary folder (tempfile), and every temporary file you create must be deleted.

Acceptance criteria (mandatory)

# Criterion How it is checked
AC1 tasks_v2.json has 6 tasks v01 to v06, every params.student is S0101, no S0042 or B001 remains, the reference paths have 3, 4, 2, 2, 4, 4 calls and validate_path returns [] for each; step_labels_v2.json has 30 labels, 15 with human true, every run starting with v0; traces.md has 12 rows, lint errors is 0 for every agent, the warnings of junk_calls are CALL_BAD_ARGS x18 (3 broken calls × 6 tasks), looper has 6 unfinished runs, diligent has 0 unfinished runs and 3 redactions (the notice messages of v05 and v06, private; the long description of B006 in v03, cut) your test reads the text of the report; the grader runs it again
AC2 edit_distance and first_divergence are right at the edges (two empty lists give 0; one extra call in the middle gives 1; two swapped calls give 2; a run matching the path gives None; a run that stops early gives ("missing", <the first path position without a call>), an empty run ("missing", 0); one call in front gives ("wrong", 1) although the rest is in order; a list replaced by text or None is a ValueError); matching.md has Y p=1 r=1 in all six diligent cells, cautious/v01 = Y p=3/4 r=1, no_verify/v01 = N p=1 r=2/3, claim_only/v01 = N p=- r=0; in table.json the cell wrong_student/v04 has precision 1/3 and recall 1/2; the mode-count rows ` redundant
AC3 judge.md, default judge: the dev row ` 5
AC4 efficiency.md: retry_limit/v04 = 2 OVE+RED+LOO+RET+WAS (4 calls against a path of 2; it retries borrow_book twice under new idempotency keys after LIMIT); all six claim_only cells are 0 ok (doing nothing gets a clean sheet); cautious/v01 = 4/3 WAS (the extra check of B006); looper/v03 = 6 OVE+RED+LOO+WAS (12 calls against a path of 2); retry_blocked/v06 = 3/2 RED+LOO+RET+WAS, and your test checks that wasted_cost of this run is 0 cu and 2 ticks (the blocked send_notice calls cost 0 cu but 1 tick each) the test reads the text of the report and recomputes the one run
AC5 evaluator.md has 12 rows and only diligent is READY_FOR_REVIEW; the lines Blind for outcome: no_verify, self_praise, redundant, retry_blocked, retry_limit., Blind for process: redundant, retry_blocked, retry_limit., Blind for judge: claim_only, self_praise, wrong_book., Blind for efficiency: claim_only. and Defective agents seen by at least one view: 10 of 10.; the person's decision line is none (the gate decides nothing) when decision in review.json is null, and no report contains an approval word; check_gate() returns [] the test reads the text of the report and runs check_gate()
AC6 table.json has exactly 72 cells and equals expected_v2.json; check_suite() returns []; mutation.md has No mismatch with the pinned table (72 cells). and Gate cases failing: none; decisions.md section Mutations has at least ten broken versions, each marked killed or survived with a reason; running again gives exactly seven files (compared byte by byte) with no timestamps, Python version or CR characters, and nothing written outside the output folder; every report says it is SIMULATED (or is the golden-table report) and names no vendor or model; python -m pytest trajectory_suite passes; decisions.md has all five sections in order, every fraction in it appears in the reports, no ranking words ("best", "should use", "recommended") run twice and compare; the grader reads decisions.md against the rubric

Grading rubric (100 points)

Dimension 0 1 2 3 Weight
Records and redaction (AC1) Does not meet AC1 Tasks exist but an identifier is left unmapped or the lint is not run Meets AC1; tells lint errors from warnings As level 2, and states that the lint checks shape and consistency, not truth (a forged but consistent record passes), that the secret pattern finds only one shape, and that the record is written by the harness, not by the agent 15
Matching (AC2) Does not meet AC2 Has the in_order table but no per-mode counts Meets AC2; both mine functions are right at the edges As level 2, and states that in_order is blind to extra calls (redundant matches on 6 of 6), that subset passes an agent that does nothing, that the reference path is one person's opinion (cautious), and that first_divergence reports every position after one call in front as wrong while the edit distance is 1 20
Step judge (AC3) Does not meet AC3 Has a sweep but takes the threshold from the sweep rather than from a person Meets AC3; kappa computed by hand, unreadable verdicts listed apart, the threshold read through policy_threshold As level 2, and states that the biases are invented parameters, that the 30 labels come from one fictional reviewer (one label moves every rate), that no threshold meets either cap, and that a judge which never fails a good step on this set can still let bad ones through 20
Efficiency (AC4) Does not meet AC4 Has ratios but no flags Meets AC4; explains the retry_blocked/v06 cell from ticks As level 2, and states that efficiency is not quality (claim_only is 0 ok), that a necessary repeat is flagged too, that cu and ticks are made-up units, and that a single reference path charges cautious for a valid extra step 15
Evaluator and gate (AC5) Does not meet AC5 Has a gate per agent but no sensitivity table Meets AC5; the gate fails closed, no approval word, the decision left to a person As level 2, and explains which view is blind to which agent and why only the combination sees 10 of 10, that retry_blocked and retry_limit are seen on one task each, and that an allowed list can let a defect through 15
Mutations, golden table and reproduction (AC6) Does not meet AC6 Has a golden table but copied it from run results without reading, or reports typed by hand Meets AC6; at least ten broken versions with a conclusion each; a script generates every report and running again gives the same files As level 2, explains why each survivor survives and which agent or task would kill it, and the tests catch deliberate faults (changing one golden cell, swapping two tasks, setting the person to ci, writing a timestamp) 15

The score of each dimension = (level reached / 3) × weight. Mapping to the module: practical = Records and redaction + Matching + Efficiency (50); applied QA analysis = Step judge + Evaluator and gate + Mutations, golden table and reproduction (50).

Hints

Hint 1: tasks and labelsApply the mapping with one simultaneous replacement (a regular expression with alternatives, longest first, and a dictionary lookup), not with a chain of `replace` calls: after `B002` → `B006`, a later `B003` → `B002` must not be turned into `B006`. Then check that every path still passes `validate_path` and has the same length as in the lab.
Hint 2: matchingThe counted calls come from `lab.match.counted_calls`; a rejected call is not among them, so `junk_calls` has the same matching cells as `claim_only`. For `first_divergence`, write the three cases on paper with a run one call short, one call too many and one call in front before you code them.
Hint 3: the step judgeBuild the dictionary of runs keyed `vNN/agent` from `run_all` and the dictionary of tasks keyed by id, then call `label_items` once per judge. Compute the kappa of one row by hand from tp, fp, fn, tn before comparing with the function.
Hint 4: mutationsInstall a broken version with `monkeypatch` on the lab's module (for example `lab.match.calls`, `lab.data.load_arg_rules`, `lab.efficiency.redundant`, `lab.stepjudge.features`) and then run `check_suite()` and `check_gate()`; remove it after each one. Do not install a broken version that changes nothing and call it a "survivor"; ask whether it can change any cell of the golden table.
Hint 5: testing your own testsAfter the tests are green, try changing one golden cell, swapping two tasks in `tasks_v2.json`, setting `chosen_by` to `ci`, or letting the script write a timestamp: if the tests stay green they are only comparing a report with itself. A good test compares with a figure **derived independently** (a hand calculation), not with the output of the function under test.

Independent challenge (practical challenge)

Less guidance. No need for the trajectory_suite package; use the lab's functions directly on the six original tasks t01 to t06, with the default configuration of lab.evaluator.run_suite (the default judge and the threshold in data/judge_policy.json). Submit one file challenge.md with four answers and how you computed each.

Question Requirement
(a) The smallest set of tasks, among t01 to t06, on which each of the 10 defective agents (all except diligent and cautious) is still flagged by at least one view of sensitivity; give the set and say whether it is the only one of that size
(b) A person puts into allowed every flag that the 12 agents raise and that is not in ALWAYS_HOLD. Which defective agents does the gate then turn READY_FOR_REVIEW, and what do they have in common?
(c) Run evaluate_run with mode="exact" instead of the task's mode in_order. Which of the agents the process view was blind to are now flagged PATH_MISMATCH, on which tasks, and which agent without a defect gets a new PATH_MISMATCH?
(d) Among the 72 reports, the runs flagged WASTED_COST whose wasted cost is 0 cu; give the run and the ticks wasted
Question 0 1 2 3 Weight
(a) Missing Right size, wrong set Right size and set, and says whether it is the only one As level 2, and states the consequence: retry_limit and retry_blocked are each seen on one task only, so dropping that task loses the defect, and a smaller suite is not a better suite 25
(b) Missing One agent missing or extra The whole set right As level 2, and notices that these are exactly the agents the outcome view is blind to, so the ALWAYS_HOLD list is what keeps the others on HOLD; allowed needs a person's name, a reason, and one suite only 25
(c) Missing Names the agents but not the tasks Agents, tasks and the new false alarm right As level 2, and states the price: stricter matching sees the extras but punishes a valid second path (the rigidity Anthropic's article warns about), and the choice of mode is a person's decision 25
(d) Missing Right run but no ticks Right run and ticks As level 2, and explains why: in this tool layer a blocked call costs 0 cu but 1 tick, so a report in cu alone would miss this waste 25

Rules

  • Do not use real data or a real API in your submission. Agents, tasks, tools, the step judge, costs, times, labels and every figure in the lab are simulated; do not infer the behaviour of a real model, judge, vendor, framework or agent.
  • Do not edit lab/, data/, tests/ or exercises/. Put proposed changes in notes/decisions.md.
  • Every tool runs only in the lab's temporary sandbox folder; do not run shell commands, network access or files outside that folder. Every real effect needs a person's approval.
  • Do not change tasks, labels, the threshold, the matching mode or the golden table after seeing results in order to reach a wanted conclusion; if you change them, record the reason and the result before the change.
  • Every figure in a report comes from a script; state the configuration. Do not let the matcher, the judge, the measures or the gate stand in for reading the records.
  • The lint, matcher, judge, measures and gate only flag; the gate fails closed; a person chooses the judge threshold, decides which flags are accepted and makes every real-world decision. Do not create or edit any automated workflow.