◆ SafeZone AI Learn
Learn/ Reinforcement Learning/ Search to Agentic RL · lesson 4 of 8

Reasoning loops

Spending compute at inference instead of training: self-consistency's exact voting math, generate→critique→refine loops and when self-critique actually works, and the cost accounting that decides between a loop, a bigger model, and fine-tuning.

The last chapter improved a model by editing its weights. This one improves answers without touching a single weight: sample more, critique, refine, vote — spending inference-time compute instead of training-time compute. These patterns went from prompt-engineering folklore to a central scaling axis of the field (OpenAI’s o-series and every “thinking mode” since are this idea, industrialized via RL — the chapter ends where that begins). The playground’s Reasoning Lab lets you wire the patterns yourself; this chapter supplies the theory of when they work, the math of when they fail, and the accounting that decides if they’re worth it.

The frame: an inference-time policy

A reasoning loop is a tiny program whose primitive operation is an LLM call: generators propose, critics score, refiners rewrite, aggregators select. In RL vocabulary the graph is a policy over calls — state = the working answer and its critiques; actions = which node runs next; the critic’s verdict is a learned (and noisy) reward signal steering control flow. That framing earns the chapter its place in this track, and it makes one thing obvious immediately: everything depends on the quality of that reward signal. Hold the thought; it is the chapter’s spine.

Self-consistency: the exact mathematics of majority voting

The simplest pattern needs no critic at all: sample kk independent chains of thought (temperature > 0), take the majority answer. If each sample is correct independently with probability pp, the vote’s accuracy is a binomial tail:

Pmaj(p,k)  =  ∑j=⌈k/2⌉k(kj) pj(1−p)k−jP_{\text{maj}}(p, k) \;=\; \sum_{j = \lceil k/2 \rceil}^{k} \binom{k}{j}\, p^j (1-p)^{k-j}

— Condorcet’s jury theorem, 1785, now running on GPUs. Its two regimes are the whole strategy in one formula, and you should feel them:

Above p = 0.5, voting amplifies competence: at p = 0.65, eleven samples reach ~0.85 and the curve steepens toward a step function as k grows. Below p = 0.5, the same mechanism amplifies error with equal enthusiasm — a model that is systematically wrong becomes confidently, consensually wrong. Sweep k and watch the S-curve sharpen around the red line: sampling more is a magnifier of whatever is already true, never a source of correctness. Fine print the widget’s independence assumption hides: real chains share the model’s biases, so effective k is smaller than nominal k — and voting needs answers that can be matched (numbers, options); free-form outputs need a selector, which reintroduces a judge.

The economics follow directly: compute scales linearly in kk while the curve flattens exponentially, so self-consistency is spectacular for the first few samples on tasks where pp is middling, and pure waste once the curve saturates — or worse than waste below the line. Diagnosis before dosage: estimate pp first.

Critique and refine: Self-Refine, Reflexion, and the verifier gap

The second family adds the critic: generate → critique → refine, looping until the critic passes the answer or a budget runs out (exactly the loop you can wire in the Lab, with the critic’s ✓/✗ routing the graph). Two canonical instances frame the design space: Self-Refine (the same model critiques its own output within one episode) and Reflexion (critiques persist as memory across episodes — the agent accumulates lessons, an inference-time cousin of learning).

When does the loop actually converge to better answers? The honest empirical record reduces to one principle — the generator–verifier gap:

A critique loop helps exactly when verifying is easier than generating — when the critic’s effective accuracy on this task exceeds the generator’s.

That’s why the wins concentrate where verification has traction: code (run the tests — a critic with p≈1p \approx 1), math with checkable steps, format and constraint compliance, retrieval-grounded factuality. And why the failures concentrate where verification is as hard as generation: the same model re-reading its own open-ended reasoning mostly re-likes it (its errors and its judgements are correlated — the independence failure again, now within one model), so intrinsic self-correction on open-ended tasks reliably underdelivers (Huang et al.). The practical corollaries, each one buildable in the Lab: make critics external (tools, tests, retrieval) where possible; make them specialized and decomposed (a relevance critic and a correctness critic beat one vague “is this good?” prompt); and bound the loop — refinement oscillates or drifts stylistically after a few iterations, so cap it and keep the best-so-far rather than the last.

The accounting: loop vs bigger model vs fine-tune

Inference-time compute is a purchase, and it competes with two other line items. The decision discipline:

OptionCost profileBuys youReach for it when
Reasoning loop / votingper-query, k×–10k× tokensaccuracy on verifiable tasks, no trainingtraffic is low or queries are high-value; verifier exists
Bigger modelper-query, higher unit pricebroad capability, no engineeringthe base model’s p is simply too low for loops to save
Fine-tune (last chapter)one-off training, cheap inferenceconsistent style/format/domain at scalethe same transformation runs on every query, forever

Rules of thumb that survive contact: measure the cost per quality point (tokens spent ÷ accuracy gained) before shipping a loop; a loop that quadruples cost for two points loses to a one-off fine-tune if the volume is high — and the hybrid (distil the loop’s outputs into the weights via SFT, last chapter’s machinery) is often the endgame: run the expensive loop offline, train the cheap model on its wins.

Where this ends: training the loop into the weights

Everything above treats the model as fixed. The current frontier closes the circle with this track’s RL: generate many chains, reward the ones that reach verified answers, and update the policy — outcome- and process-reward RL (PPO/GRPO-style, the previous chapters’ engines) that moves the reasoning into the weights, so the deployed model spends its inference compute more effectively. Reasoning models are, literally, reasoning loops distilled by reinforcement learning — which is why this chapter sits in an RL track, and why the skills compose: the graph you wire by hand in the Lab today is the training curriculum of the reasoning models you’ll study in the LLM track.

Exercises

Work these before the next chapter

  1. Derive the two regimes: show ddkPmaj\frac{d}{dk} P_{\text{maj}} has the sign of (p−12)(p - \tfrac12) for large k (or argue via the law of large numbers: the sample mean concentrates at p, and the vote asks whether p > ½). Verify both against the widget at p = 0.45 and p = 0.65.
    Solution

    Worked solutions are part of Premium — unlock all of them for £5/month →

  2. 4 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →

References

  • X. Wang et al., “Self-Consistency Improves Chain of Thought Reasoning in Language Models”, ICLR 2023.
  • A. Madaan et al., “Self-Refine: Iterative Refinement with Self-Feedback”, NeurIPS 2023; N. Shinn et al., “Reflexion: Language Agents with Verbal Reinforcement Learning”, NeurIPS 2023.
  • J. Huang et al., “Large Language Models Cannot Self-Correct Reasoning Yet”, ICLR 2024 — the negative result that defines the verifier gap.
  • H. Lightman et al., “Let’s Verify Step by Step”, 2023 — process reward models.
  • C. Snell et al., “Scaling LLM Test-Time Compute Optimally Can Be More Effective than Scaling Model Parameters”, 2024 — the accounting, done at scale.
  • Z. Shao et al., “DeepSeekMath: Pushing the Limits of Mathematical Reasoning”, 2024 — GRPO, the bridge to training-time reasoning.
Wire generator, critic and refiner nodes into a live graph in the Reasoning Lab and watch every intermediate output stream through it. Open the playground →