5D Library › Retrieval-Augmented Generation Geometry, Reciprocal Rank Fusion and Multi-Agent Error Cascades · 中文

Chapter 4. Multi-Agent Pipelines: Error Cascades and the Verifier-Gated Absorbing Markov Chain

92 % to the tenth power

Hand a complex task to a chain of agents: one retrieves, one plans, one writes code, one calls tools… Each step on its own is fairly reliable. The trouble is the chaining: without an outside check, an error at any step travels all the way to the end. This chapter first computes the cost of chaining, then looks at two remedies — several agents voting, and a verifier after every step — at how much each recovers, and at what each depends on.

Chaining and voting

Calculation

The cost of chaining. With LL steps, each right with probability pp, and no checks, end-to-end success is pLp^L. If each step is done by three agents and settled by majority vote, and their errors are independent, a step succeeds with q=p3+3p2(1−p)q = p^3 + 3p^2(1-p). If a share cc of steps are “hard cases” on which all three fail together, the vote can do nothing about them.

Calculation

# Chapter 4. p08: Error cascades in serial and voting agent pipelines.
# A. Serial chain of L steps, each correct with probability p, no checks:
#    end-to-end success p^L (any error propagates to the end).
# B. Each step done by three agents and decided by majority vote. With
#    independent errors a step succeeds with q = p^3 + 3 p^2 (1 - p).
#    Correlated errors: with probability c a step is a shared "hard case"
#    on which all three fail together; otherwise each agent is right with
#    p / (1 - c), so that one agent's overall accuracy is still p.
#    Simulated: 20,000 ten-step chains for each c.
import random

def maj3(p):
    return p ** 3 + 3 * p * p * (1 - p)

if __name__ == "__main__":
    print("A. serial chain, p^L")
    print("     p      L = 3    L = 5    L = 10   L = 20")
    for p in (0.99, 0.95, 0.92, 0.85):
        print("   {:.2f}   ".format(p) + "".join(
            "  {:.4f} ".format(p ** l) for l in (3, 5, 10, 20)))
    print("   0.92^10 = {:.4f}".format(0.92 ** 10))
    print("\nB. majority of three agents per step, p = 0.92, L = 10")
    rng = random.Random(61008)
    print("   shared hard cases c   step accuracy   chain success")
    for c in (0.0, 0.02, 0.04, 0.08):
        p_easy = min(0.92 / (1 - c), 1.0)
        ok_chains = 0
        ok_steps = 0
        for _ in range(200000 // 10):
            ok = True
            for _ in range(10):
                if rng.random() < c:
                    step = False
                else:
                    votes = sum(rng.random() < p_easy for _ in range(3))
                    step = votes >= 2
                ok_steps += step
                ok = ok and step
            ok_chains += ok
        print("        {:4.2f}               {:.4f}         {:.4f}".format(
            c, ok_steps / 200000, ok_chains / 20000))
    print("   independent formula: step {:.4f}, chain {:.4f}".format(
        maj3(0.92), maj3(0.92) ** 10))
    print("\nReading: 92 % per step leaves 43.4 % after ten steps. Voting")
    print("by three independent agents lifts each step to about 98 % and")
    print("the chain to about 83 %, but only while their errors are")
    print("independent: once some cases defeat all three together, the")
    print("vote cannot recover them and the chain falls back towards the")
    print("serial figure.")
# A. serial chain, p^L
#      p      L = 3    L = 5    L = 10   L = 20
#    0.99     0.9703   0.9510   0.9044   0.8179
#    0.95     0.8574   0.7738   0.5987   0.3585
#    0.92     0.7787   0.6591   0.4344   0.1887
#    0.85     0.6141   0.4437   0.1969   0.0388
#    0.92^10 = 0.4344
#
# B. majority of three agents per step, p = 0.92, L = 10
#    shared hard cases c   step accuracy   chain success
#         0.00               0.9819         0.8337
#         0.02               0.9692         0.7337
#         0.04               0.9546         0.6252
#         0.08               0.9201         0.4355
#    independent formula: step 0.9818, chain 0.8324
#
# Reading: 92 % per step leaves 43.4 % after ten steps. Voting
# by three independent agents lifts each step to about 98 % and
# the chain to about 83 %, but only while their errors are
# independent: once some cases defeat all three together, the
# vote cannot recover them and the chain falls back towards the
# serial figure.

With p=0.92p = 0.92 and L=10L = 10, 0.9210=0.43440.92^{10} = 0.4344: each step 92 % reliable, and fewer than half of ten-step runs succeed. At 20 steps only 0.1887 remains. Even at 99 % a step, twenty steps leave 0.8179.

With three agents voting and independent errors, a step succeeds 0.9818 of the time and a ten-step chain 0.8324 by the formula (simulated 0.8337). But that rests on independence: if just 2 % of steps are hard cases common to all three, chain success drops to 0.7337; at 8 %, to 0.4355, almost back to the 0.4344 of no vote at all. Three copies of the same model voting tend to make highly correlated errors, and the gain from the vote is then far smaller than the independent figure suggests (Ladha 1992).

Verifier gating: an absorbing Markov chain

Calculation

A verifier in the loop. After every attempt a verifier catches errors with sensitivity ss and wrongly rejects correct results with false-alarm rate ff; a rejected attempt is redone, up to nn times per step, after which the whole task is escalated to a person. An error that passes is a “silent failure”: the task carries on, but its result is already wrong. Per attempt: a=p(1−f),b=(1−p)(1−s),r=pf+(1−p)s,a = p(1-f),\quad b = (1-p)(1-s),\quad r = pf + (1-p)s , for passing correctly, passing wrongly and redoing. With G=(1−rn)/(1−r)G = (1-r^n)/(1-r), success is (aG)L(aG)^L, escalation 1−(1−rn)L1-(1-r^n)^L, and the expected number of attempts ∑i<L(1−rn)iG\sum_{i<L}(1-r^n)^i G. The same numbers follow from the absorbing chain’s fundamental matrix N=(I−Q)−1N = (I-Q)^{-1} (Kemeny and Snell 1960).

Calculation

# Chapter 4. p09: A verifier in the loop as an absorbing Markov chain.
# L = 10 steps, each attempt right with p = 0.92. After every attempt a
# verifier passes or rejects it: it catches a wrong attempt with
# sensitivity s and wrongly rejects a right one with false-alarm rate f.
# A rejected attempt is retried, up to n attempts per step; if all n are
# rejected the run stops and is escalated to a person. A wrong attempt
# that passes is a silent failure: the run goes on, but its result is
# wrong. Per attempt:
#     accept right a = p (1 - f), accept wrong b = (1 - p)(1 - s),
#     retry r = p f + (1 - p) s,   G = (1 - r^n) / (1 - r).
# Closed form: success (a G)^L, escalation 1 - (1 - r^n)^L, expected
# attempts sum_i (1 - r^n)^i G. The same numbers are recomputed from the
# fundamental matrix N = (I - Q)^(-1) of the absorbing chain whose
# transient states are (step, attempt, already wrong?).
L, P = 10, 0.92

def closed(s, f, n):
    a, r = P * (1 - f), P * f + (1 - P) * s
    g = (1 - r ** n) / (1 - r) if r < 1 else n
    esc = r ** n
    return ((a * g) ** L, 1 - (1 - esc) ** L,
            sum((1 - esc) ** i * g for i in range(L)))

def fundamental(s, f, n):
    a, b = P * (1 - f), (1 - P) * (1 - s)
    r = P * f + (1 - P) * s
    states = [(i, j, t) for i in range(L) for j in range(n) for t in (0, 1)]
    ix = {st: k for k, st in enumerate(states)}
    m = len(states)
    q = [[0.0] * m for _ in range(m)]
    win = [0.0] * m
    for (i, j, t), k in ix.items():
        if j + 1 < n:
            q[k][ix[(i, j + 1, t)]] += r
        if i + 1 < L:
            q[k][ix[(i + 1, 0, t)]] += a
            q[k][ix[(i + 1, 0, 1)]] += b
        elif t == 0:
            win[k] += a
    def solve(rhs):
        mat = [[(1.0 if x == y else 0.0) - q[x][y] for y in range(m)]
               + [rhs[x]] for x in range(m)]
        for c in range(m):
            piv = max(range(c, m), key=lambda z: abs(mat[z][c]))
            mat[c], mat[piv] = mat[piv], mat[c]
            for z in range(m):
                if z != c and mat[z][c]:
                    fct = mat[z][c] / mat[c][c]
                    mat[z] = [u - fct * v for u, v in zip(mat[z], mat[c])]
        return [mat[z][m] / mat[z][z] for z in range(m)]
    start = ix[(0, 0, 0)]
    return solve(win)[start], solve([1.0] * m)[start]

if __name__ == "__main__":
    print("   verifier          s     f     n   success   escalated"
          "  attempts")
    cases = (("none", 0.0, 0.0, 1), ("code check", 1.0, 0.0, 3),
             ("code check", 1.0, 0.0, 10), ("good judge", 0.8, 0.05, 3),
             ("weak judge", 0.5, 0.10, 3), ("strict judge", 0.8, 0.30, 3))
    worst = 0.0
    for name, s, f, n in cases:
        succ, esc, tot = closed(s, f, n)
        fs, ft = fundamental(s, f, n)
        worst = max(worst, abs(fs - succ), abs(ft - tot))
        print("   {:<15} {:4.2f}  {:4.2f}  {:3d}   {:.4f}    {:.4f}"
              "    {:6.2f}".format(name, s, f, n, succ, esc, tot))
    print("   largest gap, closed form vs fundamental matrix: {:.1e}"
          .format(worst))
    print("   exact checker, n = 3: escalation per step 0.08^3 = {:.2e}"
          .format(0.08 ** 3))
    print("\nReading: an exact, independent checker turns 43 % into")
    print("better than 99 % for under 11 attempts over ten steps: errors are")
    print("caught and retried instead of propagated, and the residual")
    print("risk falls geometrically with each allowed retry. A judge that")
    print("misses a fifth of errors keeps silent failures in the chain;")
    print("one that rejects too much spends attempts and escalates.")
#    verifier          s     f     n   success   escalated  attempts
#    none            0.00  0.00    1   0.4344    0.0000     10.00
#    code check      1.00  0.00    3   0.9949    0.0051     10.84
#    code check      1.00  0.00   10   1.0000    0.0000     10.87
#    good judge      0.80  0.05    3   0.8231    0.0132     11.15
#    weak judge      0.50  0.10    3   0.6097    0.0228     11.38
#    strict judge    0.80  0.30    3   0.5239    0.3303     12.23
#    largest gap, closed form vs fundamental matrix: 7.1e-15
#    exact checker, n = 3: escalation per step 0.08^3 = 5.12e-04
#
# Reading: an exact, independent checker turns 43 % into
# better than 99 % for under 11 attempts over ten steps: errors are
# caught and retried instead of propagated, and the residual
# risk falls geometrically with each allowed retry. A judge that
# misses a fifth of errors keeps silent failures in the chain;
# one that rejects too much spends attempts and escalates.

The program computes every row both ways; the largest gap between the closed form and the fundamental matrix is 7.1e-15, each checking the other. With no verifier, success is 0.4344. A deterministic, independent code check (s=1s = 1, f=0f = 0) with up to three attempts per step lifts success to 0.9949 for only 10.84 attempts over ten steps; allowing ten, it reaches 1.0000 for 10.87 attempts. The remaining risk falls geometrically with each allowed retry: with up to three attempts a step, the per-step escalation probability is 0.0830.08^3. This is the outline’s “exponential gain in reliability” — and its premise is that the verifier is deterministic and independent.

With a language model as judge, things change: a “good judge” with sensitivity 0.8 and false-alarm rate 0.05 brings success to 0.8231, the remaining gap being silent failures it let through; a “weak judge” with sensitivity only 0.5 reaches 0.6097; a “strict judge” with a false-alarm rate of 0.30 sends so many correct results back that success is only 0.5239, with three runs in ten escalated.

Success of a ten-step chain: no verifier, three-way voting (independent and correlated errors), a deterministic code check, and language-model judges.

Note

What “deterministic” means. A code check comes close to the ideal because its judgement does not depend on the generator: unit tests, type checks, schema validation, numerical reconciliation. Steps that can be written as such checks should be; for steps only a model can judge, the judge’s sensitivity and false-alarm rate must be measured, not assumed.

Hypothesis · not established

The author’s hypothesis (not yet tested): in real multi-step agent tasks, adding deterministic checks (tests, validation, reconciliation) to at least half the steps raises end-to-end success by more than replacing each step’s generator with a stronger model does. What would show it wrong: on a pre-registered task set, the paired gain from changing the generator exceeds the gain from adding checks.

Summary

Chaining compounds error: a ten-step chain of 92 %-reliable steps succeeds only 43.4 % of the time. Three-way voting works only while errors are independent; with many shared hard cases the gain disappears. A deterministic, independent check after each step turns failures from “propagated” into “redone” and lifts the ten-step chain above 99 % at almost no extra cost; a language-model judge is limited by its sensitivity and false-alarm rate — the errors it passes stay in the chain, and an over-strict judge sends correct results back too.

References

Kemeny, John G., and J. Laurie Snell. 1960. Finite Markov Chains. Van Nostrand.
Ladha, Krishna K. 1992. “The Condorcet Jury Theorem, Free Speech, and Correlated Votes.” American Journal of Political Science 36 (3): 617–34.

Fan, Y. (2026). Retrieval-Augmented Generation Geometry, Reciprocal Rank Fusion and Multi-Agent Error Cascades: High-Dimensional Concentration of Measure, Hybrid Lexical-Dense Retrieval Bounds and Verifier-Gated Fixed Points [检索增强生成几何、倒数秩融合与多智能体误差级联] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090170 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).