Multi-step workflow tests

Study time
≈ 2 h (estimate)
Needs
L3-M03-L01
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-M03 · Duration: ~120 minutes (estimate, including the independent exercise) · Previous: L01 (scenarios and the end-state oracle) · Next: L03

1. Introduction

A multi-step task rarely has a single path. The first book may be out on loan, the student may already have a book, the notes folder may be full, a notice may need a person's approval. Each fork is a branch the agent must handle correctly, and a "happy path" scenario touches only one branch.

This lesson teaches how to treat a workflow as a graph, measure how many of its edges a scenario suite passes through, check a few rules about the process, and ask whether the suite notices the known defects. The product: a suite of eleven scenarios that covers all seventeen reachable edges of the ThuVien Mini (fictional) workflow, three process rules, and a table showing which scenario notices which defect of the eleven simulated defective agents. Every agent in the lab is a simulated program; no model is called.

2. Learning objectives

  1. Describe a workflow as a graph of nodes, NODE:outcome edges and unreachable branches. Read: §4.1, §5.1.
  2. Compute the edge coverage of a scenario suite and read the list of missing edges. Practice: §8.2 (parts A and B), §8.3 (lines 1 and 2).
  3. Run the three process rules and explain why a run with the right end state can still break a rule. Practice: §8.2 (part D), §8.3 (lines 3 and 4). Read: §4.2.
  4. Read the "which scenario notices which defect" table and state what it does not prove. Practice: §8.2 (part C). Read: §6.1.
  5. Predict the missing edges of a small suite and choose the fewest extra scenarios. Practice: §9.

3. Required knowledge and tools

  • L3-M03-L01 (scenarios, the oracle, execute), L3-M01-L02 (the loop and stop conditions), L3-M02-L04 (the tool layer's error codes: LIMIT, BUDGET, APPROVAL_REQUIRED). Code lab code-labs/l3-m03, only pytest is needed.
  • Separating the meanings. In this lesson a workflow is the graph of steps in data/workflow.json that the simulated agent follows; with a real agent the steps are chosen by the model and the graph is only the tester's model of it. It differs from a "workflow" in the sense of an automation that runs on a schedule. An edge is a pair (node, outcome of the call at that node). Edge coverage is the share of reachable edges that at least one scenario passed through. A process rule is a constraint on order or on the number of calls, different from the end-state checks of L01.
  • The old policy still stands: offline, simulated, no model call. Coverage and rules only flag; a person decides whether an uncovered edge needs a new scenario or is an unreachable edge.

4. Concept explanations

4.1 A workflow is a graph and the suite must cover it

The lab's workflow has seven nodes that call a tool or branch (A to D, N, S, M) and seven final nodes. Each tool node has an on table that maps the outcome to the next node: get_book gives available, unavailable or NOT_FOUND; the other tools give ok or an error code such as LIMIT. Edges are named NODE:outcome, for example A:unavailable or N:BUDGET. The workflow has 19 named edges; 17 of them are reachable.

The idea of coverage is borrowed from code testing. The Wikipedia page on code coverage lists edge coverage (has every edge of the control-flow graph been executed) and branch coverage (have both the true and the false branch of each conditional been executed) [R4]. Here the "graph" is the task's workflow rather than source code, and "executed" means an agent passed through. The two edges B:NOT_AVAILABLE and D:NOT_AVAILABLE are unreachable for a single agent: get_book has just reported the book free, so borrow_book can only report it gone after a concurrent change that the lab does not simulate. The workflow file records the reason for each such edge; a person decides whether to accept the reason.

Diagram of the ThuVien Mini workflow: node A asks get_book for the first choice; if the book is free it goes to node B, which borrows the first choice; if it is out or does not exist it goes to node C, which asks about the second choice. B succeeding goes to node N, which saves a note; B hitting LIMIT stops with nothing changed. C finding the book free goes to node D, which borrows the second choice; if it is out or does not exist it stops. D succeeding goes to N, D hitting LIMIT stops. N succeeding goes to the branching node S, which asks whether a notice is needed; N hitting LIMIT or BUDGET ends done but without the note. S false ends done; S true goes to node M, which sends a notice; M succeeding ends done with the notice queued, M hitting APPROVAL_REQUIRED leaves the notice waiting for a person.
Diagram: A workflow is a graph and the suite must cover it

4.2 The end state is not enough: rules about the process

Anthropic's article advises grading what the agent produced rather than the path it took [R3]; AppWorld chose state-based evaluation over comparing each step with a reference solution [R2]. The lab follows that for the score. But some things are not in the end state: an agent that borrows a book without asking get_book first can still reach the right state, retrying a blocked call forever wastes budget, borrowing twice produces a failed call. The lab keeps three explicit rules, each with a reason: R1 a borrow_book call needs an earlier get_book call with the same book_id; R2 no more than one borrow_book call; R3 after a tool is blocked with APPROVAL_REQUIRED, that same tool is not called again. A process rule does not change the score; it is reported separately for the reader.

5. Technical deep dive

5.1 The suite, the coverage and the "who notices which defect" table

workflow.execute(sc, agent_name) runs one scenario in a temporary folder and returns everything the later lessons need: the message, the start and end states, the history, the edges taken (edges), the grade (grade, L03), the oracle verdict, the rule violations (rules), label problems (labels) and the reconcile result of the effect log. observed_edges reads the edges from the runner's history: the node label the agent attached to the action plus the real tool result. The branching node S is not a tool call; its edge is inferred from the scenario's notify input. label_problems checks that the label matches the real tool name and, because nodes A and C share get_book (and B and D share borrow_book), that the call's book_id is the book the node asks about; a lying label would fake coverage.

coverage(workflow, seen_edges) returns {covered, missing, unreachable, rate}, where rate is an exact fraction over the reachable edges. check_rules returns violations {rule, step, message}. The lab has eleven simulated defective agents, each carrying exactly one known defect (claim_only, skip_note, no_fallback, wrong_book, wrong_student, wrong_note, overreach, no_verify, double_borrow, retry_limit, retry_blocked). The suite notices a defect when the defective agent's result differs from the diligent agent's on at least one scenario: a different level, a different score or a different set of violated rules. The result table (part C of the demo) is a map showing which scenario is needed for which defect; the defect retry_blocked is noticed only by scenario s11, so dropping s11 loses the ability to see it.

6. QA perspective

6.1 What coverage and the defect table do not say

  • An edge that was passed through says only that the branch ran, not that it ran well. Scenario s09 passes through N:BUDGET but only the message and the state say how the agent handled it.
  • An "unreachable" edge is a decision by a person, not by a function. If the environment had two agents borrowing the same book, these two edges would be reachable and the coverage would drop.
  • The node label is the agent's own claim. The lab checks that the label matches the tool name, but a real agent has no label; with a real agent the edges must be inferred from the tool history and results.
  • The eleven defects were invented by the lab author. The "who notices which defect" table says where the suite is strong against known defects; it says nothing about defects nobody thought of. The idea is close to mutation testing: a test suite is judged by how many mutants it kills, and a surviving mutant shows where the tests are weak [R5].
  • The simulated agents are deterministic, so one run is enough. With a real agent that has randomness, τ-bench proposes pass^k to measure consistency over k independent trials [R1]; this module does not measure that.

7. Real-world scenarios

Scenario 1 (fictional): "Happy path only". A team keeps only the first eight scenarios (s01 to s08). This set covers 13 of the 17 reachable edges and misses N:BUDGET, S:true, M:ok, M:APPROVAL_REQUIRED: the whole notice branch and the out-of-budget branch. The retry_blocked agent (which asks again for a blocked notice) is not noticed.

Scenario 2 (fictional): "Right result, wrong process". The no_verify agent borrows the first book directly without asking get_book. In scenario s01 the end state is right and the grade level is full, but rule R1 reports one violation at step 1. The person reading decides whether that is a process defect to fix or something to accept.

8. Hands-on tutorial

8.1 Setup

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

8.2 Run the demo

python -m lab.demo l02

Output (copied from a real run on Python 3.14.6 and 3.12 (3.12.14 macOS, 3.12.3 Linux), 2026-11-04; the two versions give identical output). Every agent is simulated:

A. workflow: 19 declared edges, 17 reachable, unreachable=['B:NOT_AVAILABLE', 'D:NOT_AVAILABLE']
   suite of 11 scenarios: covered=17 missing=[] rate=1
B. first 8 scenarios only: rate=13/17 missing=['N:BUDGET', 'S:true', 'M:ok', 'M:APPROVAL_REQUIRED']
C. which scenarios notice each SIMULATED defect (result differs from the diligent agent)
   claim_only: ['s01', 's02', 's03', 's04', 's05', 's06', 's07', 's08', 's09', 's10', 's11']
   skip_note: ['s01', 's02', 's03', 's10', 's11']
   no_fallback: ['s02', 's03', 's04', 's05', 's07']
   wrong_book: ['s01', 's06', 's08', 's09', 's10', 's11']
   wrong_student: ['s01', 's02', 's03', 's06', 's07', 's08', 's09', 's10', 's11']
   wrong_note: ['s01', 's02', 's03', 's10', 's11']
   overreach: ['s01', 's02', 's03', 's10']
   no_verify: ['s01', 's02', 's03', 's04', 's05', 's06', 's07', 's08', 's09', 's10', 's11']
   double_borrow: ['s01', 's02', 's03', 's10']
   retry_limit: ['s06', 's07']
   retry_blocked: ['s11']
D. process rules (no_verify, double_borrow, retry_blocked)
   no_verify on s01: level=full rules=['R1']
   double_borrow on s01: level=full rules=['R2']
   retry_blocked on s11: level=full rules=['R3']

Reading the output: part A: 19 edges, 17 reachable, the suite of eleven scenarios covers all of them. Part B: the first eight scenarios cover 13/17. Part C: claim_only is noticed by every scenario, retry_blocked only by s11, retry_limit only by s06 and s07, the two scenarios where the borrow call returns LIMIT. Part D: three agents have the right end state (level full) but each breaks exactly one rule.

8.3 Try it yourself

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

from lab import agents as A, scenario as S, workflow as W

scs = S.load_scenarios()
wf = A.load_workflow()
print(len(A.edges(wf)), A.edges(wf, reachable_only=True)[:4])
runs = W.run_suite("diligent", scs[:5])
cov = W.coverage(wf, [e for r in runs for e in r["edges"]])
print(cov["rate"], cov["missing"])
r = W.execute(scs[0], "no_verify")
print(r["grade"]["level"], r["rules"])
r = W.execute(scs[5], "retry_limit")
print(r["stop_reason"], r["steps"], [x["rule"] for x in r["rules"]])

Output (Python 3.14.6 and 3.12, macOS and Linux, identical):

19 ['A:available', 'A:unavailable', 'A:NOT_FOUND', 'B:ok']
10/17 ['B:LIMIT', 'D:LIMIT', 'N:LIMIT', 'N:BUDGET', 'S:true', 'M:ok', 'M:APPROVAL_REQUIRED']
full [{'rule': 'R1', 'step': 1, 'message': 'borrow_book on B001 without get_book first'}]
max_steps 12 ['R2']

Reading: line 1: 19 named edges, the first four reachable ones. Line 2: the first five scenarios cover 10/17 edges, seven edges missing (from B:LIMIT to M:APPROVAL_REQUIRED). Line 3: no_verify on s01 has the right state but breaks R1 at step 1. Line 4: retry_limit on s06 does not stop by itself: it runs all 12 steps, stops on max_steps and breaks R2.

8.4 Run the lesson tests

python -m pytest tests/test_l02_workflow.py -v

Result: 19 passed. Read test_every_edge_is_taken_by_the_suite_and_each_scenario_declares_its_own_edges, test_each_process_rule_catches_its_defect_even_when_the_end_state_is_right and test_a_suite_without_the_fallback_scenarios_cannot_see_no_fallback.

8.5 Troubleshooting

Symptom Cause Fix
ModuleNotFoundError: lab when running try_l02.py The file is inside lab/ or you run from another folder Put the file next to lab/ and run from the lab's root folder
Coverage 1 but a defect still slips through The edge was passed through but no scenario tells the defective agent from the correct one Look at the table in part C; add a scenario where the two agents' results differ

9. Independent exercise

Problem: A team has only four scenarios. Predict which edges they miss, choose the fewest extra scenarios, and say which defects this suite notices.

Requirements: complete exercises/test_l02_workflow.py:

  1. TODO 1: MISSING: the list of reachable edges (in the order of lab.agents.edges) that the diligent agent does not take when it runs only the scenarios in CONF["suite"].
  2. TODO 2: ADD: a list of the lab's scenario ids that, added to the suite, bring coverage to 1 using the fewest extra scenarios.
  3. TODO 3: DETECTED: for each agent in CONF["agents"], True if running that suite gives a result different from the diligent agent's on at least one scenario (level, score or the rules violated).

Test data: exercises/ex_suite.json and the lab's scenarios.

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

Acceptance criteria: python -m pytest exercises/test_l02_workflow.py passes (3 tests), recomputed with lab.workflow. The test does not check whether the extra scenarios make sense to a real user.

Hints: TODO 1: write down the edges of each scenario (see their branches field) and subtract them from the list of reachable edges. TODO 2: for each missing edge, ask which scenarios alone pass through it. TODO 3: a defect is noticed only when the suite has a scenario where that defect changes the result; the three process rules count too.

10. Knowledge check

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

P02 · True or false

Edge coverage of 1 over every reachable edge proves that the scenario suite will notice every defect of the agent.

P04 · Select all that apply

A run (fictional) has these calls, in order: get_book B005; borrow_book B005 for S0123 (ok); borrow_book B005 again with another key (NOT_AVAILABLE); send_notice (APPROVAL_REQUIRED); send_notice again with the same content (APPROVAL_REQUIRED). Select every process rule that check_rules reports as violated.

P05 · Match

Match each workflow edge with the lab scenario (s01 to s11) that is the only one passing through that edge.

P06 · Spot the bug

A colleague's coverage function returns 14/17 = 0.82 for a suite of three lab scenarios, while the lab's coverage returns 8/17. Find the defect.

def coverage_rate(reachable_edges, seen_edges):
    return len(seen_edges) / len(reachable_edges)

P07 · Essay

Write 5-8 sentences (fictional situation): a team wants to drop the two edges B:NOT_AVAILABLE and D:NOT_AVAILABLE from the coverage target because they "never happen". State the reason the workflow file records, the condition that would make these two edges reachable, and who decides.

P09 · Recall

Lesson: L3-M01-L02

According to L3-M01-L02, which stop reason does the lab's loop end with when it has run the maximum number of steps without the agent giving a final answer and with no other stop reason?

11. Summary

  • Concepts: a workflow is a graph; edge coverage measures how many reachable edges the suite passes through [R4]; a process rule is a constraint beyond the end state [R2][R3].
  • Skills: run run_suite, compute coverage, read check_rules, read the "who notices which defect" table.
  • Traps: treating coverage 1 as quality; trusting labels the agent attaches itself; forgetting that an "unreachable" edge is a person's decision; believing the suite notices every defect when it notices only the known ones [R5].
  • Now you can: take a workflow with branches and ask: what are the edges, which edges does the suite pass through, which defects does it really see, and who decides which edges to skip.

12. References

ID Title Publisher URL Accessed Relevance
R1 τ-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 abstract page and the HTML version of the part introducing the pass^k metric; did not read the experiments
R2 AppWorld: A Controllable World of Apps and People for Benchmarking Interactive Coding Agents (arXiv 2407.18901) arXiv (Trivedi et al.) https://arxiv.org/abs/2407.18901 2026-11-04 Read the abstract page and section 3.2 (state-based rather than process-based evaluation); did not read the rest
R3 Demystifying evals for AI agents Anthropic https://www.anthropic.com/research/demystifying-evals-for-ai-agents (via redirect from anthropic.com/engineering/demystifying-evals-for-ai-agents) 2026-11-04 Read the page text: grade the result rather than the path, partial credit
R4 Code coverage Wikipedia https://en.wikipedia.org/wiki/Code_coverage 2026-11-04 Read the section on coverage criteria (edge coverage, branch coverage); did not read the rest. An open encyclopedia, used for the definitions
R5 Mutation testing Wikipedia https://en.wikipedia.org/wiki/Mutation_testing 2026-11-04 Read the section on goals (killed mutants, mutation score) and the part on equivalent mutants; did not read the rest. An open encyclopedia, used for the definitions

Glossary (English ↔ Tiếng Việt)

English Tiếng Việt
Workflow graph Đồ thị workflow: nút (bước) và cạnh (kết quả của lời gọi)
Edge coverage Độ phủ cạnh: tỷ lệ cạnh khả đạt được ít nhất một kịch bản đi qua
Unreachable edge Cạnh không khả đạt: không thể đi tới trong môi trường của lab, ghi kèm lý do
Process rule Luật quá trình: ràng buộc về thứ tự hoặc số lời gọi, ngoài trạng thái cuối
Kill matrix Bảng cho biết kịch bản nào nhận ra lỗi nào