TAI BUI
Back to curriculum
CapstonePython

Critic Loop

A critic that says "looks good" on round one is broken. So is a critic that always says "needs work". The useful one converges, and you have to engineer that convergence.

TIME: ~90 minutesPREREQUISITES: Phase 19 lessons 50-53

Learning Objectives

  • Score a paper draft across five fixed dimensions: clarity, novelty, evidence, methodology, related-work.
  • Apply each round's critique as a structured revision diff rather than a freeform rewrite.
  • Detect convergence by comparing scores across rounds; stop on plateau, target met, or budget exhausted.
  • Cap rounds with a max-iteration budget so a non-converging critic does not run forever.
  • Emit a per-round trace so the dashboard or the next stage can render the score trajectory.

Why five fixed dimensions

A structured critique here is a score vector: one number each for clarity, novelty, evidence, methodology, and related-work. A freeform critic returns a paragraph of suggestions instead, and the next round's revision treats that paragraph as ambient context. Nobody can verify whether the rewrite addressed the criticism, because the criticism never had a shape.

Five dimensions give the harness a contract.

Mermaid diagram

The harness records every dimension in every round. A revision that raises clarity but tanks evidence shows up as a regression on evidence in the trace, and the target rule refuses to call that success. The plateau check is coarser: it looks only at the mean. A model-only critic cannot offer either guarantee.

Check: Why five fixed dimensions0/2
1. In a structured critique, what is a score vector?Define
2. Why does a paragraph of freeform critique make the next revision hard to check?Explain

The Critique shape

Mermaid diagram

A Suggestion carries the dimension it improves, the section it targets, and an edit instruction the reviser can apply. The reviser is a callable too. The code here ships a deterministic reviser that maps each edit name to a fixed operation, and a model-driven reviser would read the same field as a prompt. The contract stays the same either way.

Check: The Critique shape0/3
1. What does a single Suggestion tell the reviser?Define
2. Why does each Suggestion name a dimension, a section and an edit instead of describing a fix in prose?Explain
3. Why can a model-driven critic replace the deterministic one without changing the loop?Explain

Convergence rules, in order

The critic loop terminates when any one of three conditions fires.

Mermaid diagram

Target is the strictest rule: all five dimensions (clarity, novelty, evidence, methodology, related_work) must reach >= target_score (default 8.0) before the loop returns success. A high mean with one weak dimension does not count. Plateau compares the current round's mean to the previous round's mean. If no round-over-round gain exceeds plateau_epsilon (default 0.1) across plateau_window (default 2) consecutive comparisons, the loop exits with plateau. That needs three trace entries, so plateau can fire at round three at the earliest. Budget is a hard cap on rounds (default 5), and the loop exits with budget when it runs out.

The order matters: target beats plateau, and plateau beats budget. If round three hits the target on the same iteration that would also trigger a plateau, the result is target, not plateau.

Check: Convergence rules, in order0/10
1. What must be true for the target rule to stop the loop with success?Define
2. What does the plateau rule detect?Define
3. What is the budget in this loop?Define
4. Why does the target rule check all five dimensions and not just the mean?Explain
5. With the default `plateau_window` of 2 and `plateau_epsilon` of 0.1, what is the earliest round at which `plateau` can fire?Apply
6. At round 4 the critique has all five scores at 8.0 or above, and the means of rounds 2, 3 and 4 differ by less than 0.1. What does the loop return?Apply
7. A test critic returns a mean of 5.0, 5.05, 5.07 and 5.08 on rounds 1 to 4, paired with a reviser that changes nothing. Settings: plateau_epsilon 0.1, plateau_window 2, target 9.0, max_rounds 5. How does the loop end?Apply
8. A critic returns the same scores every round, all below target, and a reviser changes nothing. The loop runs with max_rounds=2. How does it end?Apply
9. With target_score 8.0, a trace shows a mean of 8.65 at round 3, yet the loop kept running to round 5. The scores at round 3 were clarity 7.23 and four others at 9.0. What explains this?Analyze
10. Design A stops with success when the mean is at least 8.0. Design B stops when every dimension is at least 8.0. A draft scores 10, 10, 10, 10 and 5. What happens?Analyze

Why plateau detection runs over two rounds

Plateau detection waits for two consecutive flat comparisons because one flat step can be a revision that happened to change little. The shipped scorer, deterministic_score, is a pure function of the paper, so the same draft always gets the same scores. Any change in the mean comes from the paper changing, not from scoring noise. A drop in the mean counts as flat too, since only a gain larger than plateau_epsilon resets the check. Requiring two in a row means the draft has stalled across several revisions, not just one.

Check: Why plateau detection runs over two rounds0/3
1. Why does plateau need two consecutive flat comparisons by default instead of one?Explain
2. Why does a falling mean count toward a plateau?Explain
3. A teammate sets plateau_window to 1 to save rounds. What risk does this add?Analyze

The deterministic critic in this lesson

This lesson does not call a model. The shipped critic is a callable that scores a draft from structural signals on a MiniPaper: average section body length (clarity), figure and citation counts (evidence), an originality_tag field (novelty), and the presence of method and related-work sections (methodology, related-work). The reviser knows how to push each score upward.

text
clarity      grows when the average section body length increases
novelty      grows when originality_tag is set to "high"
evidence     grows when a section's figure_refs is non-empty
methodology  grows when a section titled "Method" exists with body
related-work grows when a section titled "Related Work" exists with body

The exact scoring rules are numeric. Evidence is min(10, 2 + 2 * figure_refs + 1.5 * cites), novelty is 3, 6, or 9 for a low, medium, or high tag, and methodology matches any section whose title starts with "method". The reviser maps each suggestion's edit name to one operation. add-method-section and add-related-work-section append a new MiniSection (or fill an empty body), expand-body and add-figure-and-cite append to an existing section, and bump-originality mutates the paper's originality_tag one step per call (low to medium to high). After round one the harness can watch the score go up, and the tests assert exactly that: the loop reduces the gap.

Check: The deterministic critic in this lesson0/6
1. What makes the lesson's critic deterministic?Define
2. Which reviser edit leaves every section of the paper untouched and changes only a top-level setting on the paper?Explain
3. A draft has one figure reference and two citations across its sections. What is its evidence score under the shipped critic?Apply
4. A draft has a non-empty section titled "Methods". What methodology score does the shipped critic give it?Apply
5. A draft has one section, "Introduction", with the body "short intro", no figures, no citations and a low originality tag. How many suggestions does round one's critique emit?Apply
6. A paper starts with originality_tag "low". The reviser applies bump-originality twice. What is the novelty score afterwards?Apply

The full loop contract

Mermaid diagram

The harness owns the round counter, the trace, and the convergence check. The critic owns the score. The reviser owns the diff. None of the three touches the others' state.

Check: The full loop contract0/1
1. What does the reviser receive as input each round?Define

The Trace output

The trace is the per-round event log. Each round emits one event with the round number, the score vector, the mean, the suggestion count, and the convergence verdict, and the full trace comes back alongside the final draft. A downstream dashboard can render it as a score-per-round chart. The next lesson, the iteration scheduler, reads the trace to decide whether the branch is worth keeping.

Check: The Trace output0/2
1. What does each trace entry contain?Define
2. The next stage must decide whether this revision branch is worth keeping, and a dashboard must chart the run. What should both consume?Design

Budgets that protect against bad critics

A budget is the max-iteration ceiling that stops a bad critic from running the loop forever. With the default settings, a critic whose suggestions never improve the score trips the plateau rule first: the trace shows three rounds, scores flat, verdict plateau. The budget verdict fires when the mean keeps rising by more than plateau_epsilon each round but never reaches the target, so the rounds simply run out. Either way the user reads a flat trace as a critic bug, not a draft bug. Surfacing only the final draft would hide the diagnosis, so the design surfaces the trace first.

Check: Budgets that protect against bad critics0/5
1. Why does the loop need a max-round budget when it already has target and plateau rules?Explain
2. Why does the design surface the trace before the final draft?Explain
3. With default settings, a critic keeps emitting suggestions but the reviser never changes the paper, so every round's scores are identical and the target is never met. How does the loop end?Apply
4. A critic's suggestions raise the mean by about 0.5 every round, but the five dimensions never all reach 8.0 together. With default settings, what does the loop report after round 5?Apply
5. A run ends with verdict plateau at round 3, and the trace shows identical scores in all three rounds. Where should you look first?Analyze
Author's Note

I'd keep the target rule strict even when it feels harsh. A mean can look healthy while evidence quietly drops behind a gain in clarity, and I'd rather the loop refuse to call that success. The rule I'd be slowest to relax is the one that stops a single strong dimension from covering for a weak one.

I'd also bet on the contract over the critic. Today the critic is a deterministic function, but the shape it returns is what the loop depends on, so I'd expect to swap in a model-driven critic or reviser before I changed anything about the loop itself. And when a run goes wrong, I'd read the trace before the final draft, because a flat trace points at the critic before it points at the draft.

How to read the code

code/main.py defines Critique, Suggestion, the Critic and Reviser protocols, CriticLoop, and a make_deterministic_critic_pair factory that returns the deterministic critic with a matching reviser. Minimal MiniPaper and MiniSection shapes are included so the lesson stands alone.

code/tests/test_critic_loop.py covers monotone improvement after round one, target convergence on a tuned draft, plateau detection when the mean is stable, a no-progress critic stopping by plateau or budget within three rounds, suggestion application by the reviser, and trace shape.

Going further

Two extensions a real implementation will want. The first is dimension weights: a workshop paper weights novelty higher than methodology, and a journal weights the inverse, so the convergence check becomes a weighted mean. The second is paired critics, where one critic scores and a second adjudicates the suggestions before the reviser sees them. Both add value, and both compose on the same Critique shape.

The bet is the score vector. Once the critique is structured, every other improvement (a new convergence rule, a dashboard, a paired critic) drops in without changing the loop.

Warm-up0/3
1. You run an automatic revise-and-rescore loop on a draft. What is the simplest safeguard against it running forever when the goal is never reached?Warm-up
2. A scorer rates a draft on five separate criteria, one number each. Compared with one paragraph of feedback, what is the main benefit?Warm-up
3. A scoring function depends only on the draft's contents. You score the same draft twice with no edits in between. What do you expect?Warm-up
Check: Going further0/2
1. A workshop paper should weight novelty above methodology. Which change fits the loop's design?Design
2. You add a second critic that adjudicates suggestions before the reviser sees them. Where does it fit?Design

Code