Measuring a Pattern Against a Baseline
Compare a workflow pattern with a simpler baseline on the same cases: run each case several times, report pass rates and their paired difference with intervals, price tokens and measure p50 and p95 latency, and adopt the complex pattern only when its gain is worth the cost.
Contentsand lesson path
On this page
- The Discipline of Baseline Comparison: Justifying Architectural Complexity
- Building an Automated Pattern Benchmark Suite
- Lab: One Run Versus Repeated, Paired Runs
- Practice
- Apply it
- Review prompt
Lessons of Workflow & Planning Patterns
- Workflows Versus Agents: A Decision Guide Concept · 15 min
- Chaining, Routing and Parallel Calls Worked example · 25 min
- Lab: Plan, Execute, Replan Lab · 25 min
- Reflection Loops That Actually Help Worked example · 20 min
- Measuring a Pattern Against a Baseline Lab · 20 min
- Check: Pick the Pattern Knowledge check · 8 questions
What you will learn
- Decide between a fixed workflow and an autonomous agent for a task and justify the choice with reliability, latency and cost.
- Add an evaluator-optimizer (reflection) loop with an explicit quality criterion and iteration cap, and measure whether it improves results.
Prerequisites: Agent Loops & ReAct
01. The Discipline of Baseline Comparison: Justifying Architectural Complexity
Teams often add complex agent designs without measuring whether they help. They add multi-agent committees, planners and reflection loops before checking whether one prompt with structured output, or a two-step chain, would do the job. The extra parts cost more tokens, add latency, fail in new ways and are harder to debug.
So follow one rule: do not ship an agent pattern that you have not measured against a simpler baseline. The baseline is the control group of your experiment: the simplest design that could work, run on the same cases.
Each pattern sits at a different point in the trade-off between accuracy, cost and latency. A fixed prompt chain is fast and cheap with predictable latency, but it struggles with tasks whose steps cannot be fixed in advance. A Plan-and-Execute agent adds task breakdown and replanning, which can raise accuracy on complex tasks at the price of more LLM calls. An evaluator-optimizer reflection loop (the name comes from Anthropic's Building effective agents) can improve quality on hard cases, but every round adds an evaluation call and a generation call, so tokens and latency go up. How much each pattern gains, and at what price, is what you have to measure on your own tasks.
Without measurements, design discussions come down to opinion. An engineer may feel that a planning loop is more capable, while a product manager complains that answers are too slow. Numbers from a representative set of test cases settle the question: how much more often does the pattern pass, and what does that cost in tokens and time?
To make a choice you can defend, run every candidate pattern on the same set of cases under the same conditions, and record pass rate, token usage, latency and cost for each.
02. Building an Automated Pattern Benchmark Suite
To compare patterns fairly, run every candidate on the same fixed set of multi-step tasks. Each test case gives an input, the mock tools the pattern may call, and a pass/fail check written in code.
The pass rate alone is not enough. Three more numbers decide whether a pattern is usable in production: tail latency (the p95 and p99 response times, which 5% and 1% of requests exceed), the total input and output tokens, and how much the token cost varies from run to run. A pattern with a high pass rate can still be unusable in a real-time application if one request in twenty takes far longer than users will wait.
The benchmark compares three patterns. In the lab below they are simulated by seeded fakes; in your own harness they are your real pipelines:
-
Fixed prompt chain, the baseline. Two fixed steps: the first extracts the entities and parameters, the second writes the recommendation in one generation call.
-
Plan-and-execute. It splits the goal into sub-tasks, calls the tools one after another, and combines the results.
-
Plan-execute plus reflection. It does the same, then checks the first answer with a code validator and, if the check finds a problem, revises the answer against a rubric.
Two rules decide whether the comparison means anything. First, LLM runs are not deterministic, so one run per case measures luck as much as the pattern: run each case several times (k = 3 to 5) and use more cases (50 or more for a decision that matters). Second, compare patterns paired on the same cases and report the difference with an interval, not two bare pass rates. A difference of 9/10 against 6/10 sounds large, but a Fisher exact test gives p = 0.30 for it, and "+30%" there means 30 percentage points, a 50% relative gain. Recommend the complex pattern only when the interval for the difference excludes zero or the gap is large enough to matter even at its low end.
The harness below does this. It resamples whole cases (bootstrap), because runs of the same case are not independent, prices input and output tokens separately, and reports p50 and p95 latency rather than an average.
"""Compare each pattern with the baseline on the same cases, k runs per case."""
import argparse
import random
import statistics
from runners import PATTERNS, make_cases, run_once
PRICE_IN, PRICE_OUT = 2.50, 10.00 # dollars per million tokens (illustrative)
def bootstrap(values, reps=2000):
"""95% interval for the mean, resampling cases (runs of a case move together)."""
rng = random.Random(0)
means = sorted(statistics.fmean(rng.choices(values, k=len(values)))
for _ in range(reps))
return means[int(0.025 * reps)], means[int(0.975 * reps) - 1]
p = argparse.ArgumentParser()
p.add_argument("--cases", type=int, default=10)
p.add_argument("--reps", type=int, default=5)
p.add_argument("--seed", type=int, default=1)
args = p.parse_args()
cases = make_cases(args.cases)
per_case = {} # pattern -> list of per-case pass rates, same case order
print(f"{args.cases} cases x {args.reps} runs, seed {args.seed}")
print(f"{'pattern':<13}{'pass':>6}{'95% interval':>14}{'p50 s':>7}{'p95 s':>7}"
f"{'tokens':>8}{'$/task':>9}")
for name in PATTERNS:
runs = [[run_once(name, c, r, args.seed) for r in range(args.reps)] for c in cases]
rates = [sum(x["passed"] for x in rs) / len(rs) for rs in runs]
per_case[name] = rates
flat = [x for rs in runs for x in rs]
lat = statistics.quantiles([x["latency_s"] for x in flat], n=20)
tokens = statistics.fmean(x["input_tokens"] + x["output_tokens"] for x in flat)
cost = statistics.fmean(x["input_tokens"] * PRICE_IN + x["output_tokens"]
* PRICE_OUT for x in flat) / 1e6
low, high = bootstrap(rates)
print(f"{name:<13}{statistics.fmean(rates):>6.0%} [{low:>4.0%} - {high:>4.0%}]"
f"{lat[9]:>7.1f}{lat[18]:>7.1f}{tokens:>8,.0f}{cost:>9.4f}")
base = per_case["fixed chain"]
for name in list(PATTERNS)[1:]:
diffs = [a - b for a, b in zip(per_case[name], base)]
low, high = bootstrap(diffs)
verdict = "better" if low > 0 else "not shown to differ at this sample size"
print(f"{name} vs fixed chain: {statistics.fmean(diffs) * 100:+.0f} points "
f"[{low * 100:+.0f}, {high * 100:+.0f}]\n -> {verdict}")03. Lab: One Run Versus Repeated, Paired Runs
You will compare a fixed chain, plan-and-execute, and plan-and-execute with reflection, first the way many teams do it (10 cases, one run each) and then with repeated, paired runs.
You need: Python 3.12 or later; standard library only. Tested with Python 3.12.13 to 3.14.7, which all print identical output. Create a folder pattern-bench, save bench.py from above and runners.py below into it. The runners are seeded fakes: each pattern has a true pass rate that falls with case difficulty, and each run reports tokens and a simulated latency instead of sleeping, so the lab runs in under a second and prints the same numbers every time. The latencies, token counts and prices in the outputs below come from the fake, not from a measurement; they show the shape of a real report. In a real harness you would call your pipelines and time each call with time.perf_counter(). Because the true rates are known (plan+reflect is about 20 points better than the fixed chain on these cases), you can see which measurements find the truth.
"""Seeded fake runners for three patterns. Each run reports pass/fail, tokens and
a simulated latency, so the lab is offline and prints the same numbers each time."""
import random
PATTERNS = { # base pass rate, drop per unit of difficulty, tokens in/out, seconds
"fixed chain": (0.85, 0.50, 800, 150, 1.8),
"plan-execute": (0.90, 0.35, 2400, 400, 4.2),
"plan+reflect": (0.95, 0.30, 3500, 600, 6.0),
}
def make_cases(n, seed=7):
rng = random.Random(f"cases|{seed}")
return [{"id": f"c{i:02d}", "difficulty": round(rng.random(), 2)}
for i in range(n)]
def run_once(pattern, case, rep, seed):
base, slope, tin, tout, secs = PATTERNS[pattern]
rng = random.Random(f"{pattern}|{case['id']}|{rep}|{seed}")
tail = 2.0 if rng.random() < 0.05 else 1.0 # occasional slow run
return {"passed": rng.random() < base - slope * case["difficulty"],
"input_tokens": int(tin * rng.uniform(0.8, 1.2)),
"output_tokens": int(tout * rng.uniform(0.8, 1.2)),
"latency_s": secs * rng.uniform(0.85, 1.25) * tail}Step 1: one run per case, two seeds. This is the design behind a typical "9/10 versus 6/10" claim.
python3 bench.py --reps 110 cases x 1 runs, seed 1
pattern pass 95% interval p50 s p95 s tokens $/task
fixed chain 60% [ 30% - 90%] 1.7 2.2 990 0.0036
plan-execute 80% [ 50% - 100%] 4.5 12.5 2,896 0.0102
plan+reflect 80% [ 50% - 100%] 6.3 7.5 4,123 0.0148
plan-execute vs fixed chain: +20 points [-20, +60]
-> not shown to differ at this sample size
plan+reflect vs fixed chain: +20 points [+0, +50]
-> not shown to differ at this sample sizepython3 bench.py --reps 1 --seed 210 cases x 1 runs, seed 2
pattern pass 95% interval p50 s p95 s tokens $/task
fixed chain 50% [ 20% - 80%] 1.9 2.2 997 0.0036
plan-execute 80% [ 50% - 100%] 4.6 5.3 2,906 0.0102
plan+reflect 80% [ 50% - 100%] 6.3 7.1 4,138 0.0150
plan-execute vs fixed chain: +30 points [-10, +70]
-> not shown to differ at this sample size
plan+reflect vs fixed chain: +30 points [+0, +60]
-> not shown to differ at this sample sizeSame patterns, same cases, different luck: the baseline scores 60% then 50%, and plan-execute ties plan+reflect both times although its true rate is lower. Each pass-rate interval is 50 to 60 points wide, and no difference interval lies above zero. With only 10 runs per pattern, one slow plan-execute run (10.2 s) pushes its p95 to 12.5 s, longer than any run took: with so few values, statistics.quantiles (default method exclusive) extrapolates past the largest one.
Step 2: five runs per case. Run the default settings: 10 cases, each run five times, so each pattern gets 50 runs.
python3 bench.py10 cases x 5 runs, seed 1
pattern pass 95% interval p50 s p95 s tokens $/task
fixed chain 64% [ 52% - 74%] 1.9 2.2 940 0.0034
plan-execute 74% [ 58% - 86%] 4.7 8.4 2,775 0.0099
plan+reflect 80% [ 66% - 92%] 6.3 9.6 4,112 0.0149
plan-execute vs fixed chain: +10 points [-4, +22]
-> not shown to differ at this sample size
plan+reflect vs fixed chain: +16 points [+2, +30]
-> betterStep 3: more cases. Run 60 cases, five runs each, so each pattern gets 300 runs.
python3 bench.py --cases 6060 cases x 5 runs, seed 1
pattern pass 95% interval p50 s p95 s tokens $/task
fixed chain 66% [ 60% - 71%] 1.9 3.3 951 0.0035
plan-execute 73% [ 67% - 78%] 4.6 7.5 2,815 0.0100
plan+reflect 84% [ 79% - 88%] 6.4 7.5 4,086 0.0147
plan-execute vs fixed chain: +7 points [+1, +13]
-> better
plan+reflect vs fixed chain: +18 points [+12, +24]
-> betterWith five runs per case, plan+reflect separates from the baseline (+16 points, interval +2 to +30) but plan-execute does not. With 60 cases both differences exclude zero and the intervals are narrow enough to plan with: plan+reflect is about 18 points better for about four times the cost per task and more than three times the median latency. That is the trade-off to take to a decision, and it is very different from what a single 10-case run suggested. Ten cases is also too few for the bootstrap to be precise, so treat the step 2 intervals as rough.
04. Practice
05. Apply it
Before you adopt a more complex pattern in production, benchmark it like this:
- Collect realistic tasks that include the failure modes you see in production, not only happy paths, and aim for 50 or more cases before a decision that matters.
- Record three kinds of metric: accuracy (pass rate with an interval), efficiency (input and output tokens priced separately) and user experience (p50 and p95 latency).
- Run every case several times and compare patterns on the same cases; decide on the interval of the difference, not on two point estimates.
- Expect trade-offs: a more complex pattern is rarely better on every metric. Adopt it only when its gain, even at the low end of the interval, is worth its extra cost and latency for your use case.
- Route by difficulty: a fast classifier can send simple queries to a cheap prompt chain and keep the expensive reflection loop for the hard ones. Benchmark the routed system too.
- Re-run the benchmark on every major release or model upgrade, to catch regressions before users see them.
Measured this way, a decision to add complexity rests on numbers rather than on how capable a pattern feels. Share the benchmark results with the people who decide, so they can see the latency and cost of each option next to its accuracy.
06. Review prompt
Explain why you measure a simple baseline before you adopt a more complex pattern. Explain why one run of 10 cases cannot rank two patterns, describe how repeated runs and a paired interval fix that, and define three criteria for deciding when pattern complexity is justified.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.