Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Worked example · 20 min · revision 2

Single-Pass Versus Agentic: A Measured Comparison

Run a single-pass, an agentic and a routed pipeline on the same 20 labelled questions, record each answer and its calls, break the results down by question type, test the paired differences with an exact sign test and a bootstrap interval, and read what the numbers do and do not show.

Contentsand lesson path

What you will learn

  • Compare agentic RAG with a single-pass pipeline on answer quality, latency and cost, and choose per query type.

Prerequisites: RAG Foundations, Agent Loops & ReAct

01. The problem

You now have every part of an agentic retriever: tools (lesson 2), decomposition (lesson 3) and a grading loop (lesson 4). The practice project asks for the decision that follows: is it worth it, and for which questions? This worked example answers that for the lab fixture with a comparison you can rerun, and shows how to read the result without claiming more than 20 questions can support.

Three systems answer every question:

  • single is the single pass: one document search (k = 3) and one answer call. It has no database or web tool, like the pipeline from RAG Foundations.
  • agentic asks the planner first. Questions with a plan (multi-hop or database questions) go to the executor from lesson 3; all others go to the grading loop from lesson 4.
  • routed uses the same planning call as a router. Questions with a plan go to the executor; all others take the single pass.

Each system records its answer, its total model and tool calls, and the calls that had to run one after another. Answers come from the FAKE components of the earlier lessons, so the run is deterministic. You need: the agentic-lab folder from lessons 2 to 4, with the fixture restored by python make_fixture.py.

02. Step 1: Label the questions

The set has 20 questions: 11 about the docs (one of them unanswerable), 4 that need the database and 5 multi-hop questions. Each has the strings that a correct answer must contain. An empty list marks a question that must be refused, so that abstaining counts as correct there and as a miss everywhere else. Every system is scored against the same labels; changing a label after seeing results would bias the comparison, so freeze the file before you run anything.

Python · eval_set.py
"""20 labelled questions: (id, type, question, strings a correct answer contains)."""
EVAL = [
    ("q01", "docs", "How many times are failed jobs retried by default?", ["3 times"]),
    ("q02", "docs", "What is the default timeout for a job?", ["15 minutes"]),
    ("q03", "docs", "How many requests per minute may each token make?", ["60"]),
    ("q04", "docs", "Which Python version does Larkspur need?", ["3.11"]),
    ("q05", "docs", "What is the default number of workers?", ["4"]),
    ("q06", "docs", "How long does a job stay in the dead-letter queue?", ["14 days"]),
    ("q07", "docs", "Which time zone do schedules use by default?", ["UTC"]),
    ("q08", "docs", "Which command migrates the state to version 3?", ["migrate"]),
    ("q09", "docs", "How long is a parked run kept before it is removed?",
     ["14 days"]),
    ("q10", "docs", "Can Larkspur run jobs on a GPU?", []),  # [] = must abstain
    ("q11", "docs", "Which command empties the parked jobs queue?", ["dlq purge"]),
    ("q12", "sql", "How many billing-sync runs failed in October 2026?", ["3 failed"]),
    ("q13", "sql", "How many nightly-report runs failed in October 2026?",
     ["1 failed"]),
    ("q14", "sql", "Which office is Chen Wei in?", ["Singapore"]),
    ("q15", "sql", "Who leads the Platform team?", ["Ana Lima"]),
    ("q16", "multi-hop", "Where is the lead of the team that owns nightly-report"
     " based?", ["Singapore"]),
    ("q17", "multi-hop", "Where is the lead of the team that owns invoice-export"
     " based?", ["Manchester"]),
    ("q18", "multi-hop", "How many times did the job that copies card payments into"
     " the ledger fail in October 2026?", ["had 3 failed"]),
    ("q19", "multi-hop", "How many times did the job that builds the sales report"
     " fail in October 2026?", ["had 1 failed"]),
    ("q20", "multi-hop", "How many failed runs did billing-sync and invoice-export"
     " each have in October 2026?", ["had 3 failed", "had 0"]),
]

03. Step 2: Three systems behind one interface

systems.py gives each design the same signature: a question in, a dict with the answer, the calls and the calls in sequence out. The single pass uses the lesson 4 grader as its generator, so all three systems read evidence the same way and differ only in how they retrieve it. That keeps the comparison about retrieval, which is the decision being made.

Python · systems.py
"""Three ways to answer a question, each reporting its calls."""
import asyncio

from corrective import corrective
from decompose import answer as decompose
from grader import grade
from planner import fake_plan
from tools import fetch

SCOPE, QUIET = "acme:staff", (lambda _: None)


def single_pass(question: str) -> dict:
    """One search, one answer call. FAKE generator: quotes a supporting sentence."""
    for hit in fetch("search_docs", {"query": question, "k": 3}, SCOPE)["hits"]:
        if (g := grade(question, hit["text"]))["sufficient"]:
            return {"answer": f"{g['support']} [{hit['id']}]", "calls": 2, "serial": 2}
    return {"answer": "ABSTAIN: not in the retrieved passages", "calls": 2, "serial": 2}


def has_plan(question: str) -> bool:
    try:
        fake_plan(question)
        return True
    except ValueError:
        return False


def agentic(question: str) -> dict:
    if has_plan(question):  # multi-step or database question: plan and execute
        return asyncio.run(decompose(question, log=QUIET))
    r = corrective(question, log=QUIET)  # text question: grade, retry, abstain
    n = 1 + r["calls"]["tool"] + r["calls"]["model"]  # + the planning call
    return {"answer": r["answer"], "calls": n, "serial": n}


def routed(question: str) -> dict:
    if has_plan(question):  # the planning call doubles as the router
        return agentic(question)
    r = single_pass(question)
    return {**r, "calls": r["calls"] + 1, "serial": r["serial"] + 1}  # + router

04. Step 3: Compare in pairs

compare.py runs every system on every question and prints one row per question. Then it reports, per question type, how many answers were correct and the mean calls per question. Finally it compares systems in pairs, question by question, as you did in the retrieval evaluation lab: the exact sign test counts the questions where one system is right and the other is not, and the paired bootstrap resamples the 20 per-question differences 10,000 times for a 95% interval of the accuracy difference. Both functions are the ones from that lab.

Python · compare.py
"""Run the three systems on the 20 labelled questions and compare them in pairs."""
import math
import random

from eval_set import EVAL
from systems import agentic, routed, single_pass


def outcome(text: str, gold: list[str]) -> str:
    """ok, abstain or WRONG; for an unanswerable question, abstaining is ok."""
    if text.startswith("ABSTAIN"):
        return "abstain" if gold else "ok"
    return "ok" if gold and all(g.lower() in text.lower() for g in gold) else "WRONG"


def sign_test(wins: int, losses: int) -> float:
    """Two-sided exact sign test; tied questions are left out."""
    n = wins + losses
    tail = sum(math.comb(n, i) for i in range(min(wins, losses) + 1)) / 2**n
    return min(1.0, 2 * tail) if n else 1.0


def paired_bootstrap(diffs: list[int], rounds: int = 10_000, seed: int = 0):
    rng = random.Random(seed)
    means = sorted(sum(rng.choices(diffs, k=len(diffs))) / len(diffs)
                   for _ in range(rounds))
    return means[int(0.025 * rounds)], means[int(0.975 * rounds) - 1]


SYSTEMS = {"single": single_pass, "agentic": agentic, "routed": routed}
rows = []
print(f"{'id':<5}{'type':<11}" + "".join(f"{s:<15}" for s in SYSTEMS))
for qid, kind, question, gold in EVAL:
    res = {name: run(question) for name, run in SYSTEMS.items()}
    rows.append((kind, {n: (outcome(r["answer"], gold) == "ok", r["calls"],
                            r["serial"]) for n, r in res.items()}))
    cells = [f"{outcome(r['answer'], gold):<8}{r['calls']:>2} calls  "
             for r in res.values()]
    print(f"{qid:<5}{kind:<11}" + "".join(cells))

print("\nper type: correct, mean calls per question (mean calls in sequence)")
for kind in ("docs", "sql", "multi-hop", "all"):
    sel = [r for k, r in rows if kind in (k, "all")]
    cells = []
    for s in SYSTEMS:
        right = sum(r[s][0] for r in sel)
        calls, serial = (sum(r[s][i] for r in sel) / len(sel) for i in (1, 2))
        cells.append(f"{s} {right:>2}/{len(sel):<2} {calls:4.1f} ({serial:.1f})")
    print(f"{kind:<10}" + "  ".join(cells))

for a, b in (("single", "agentic"), ("single", "routed"), ("routed", "agentic")):
    diffs = [r[b][0] - r[a][0] for _, r in rows]  # paired: same question
    wins, losses = diffs.count(1), diffs.count(-1)
    low, high = paired_bootstrap(diffs)
    print(f"{b} vs {a}: {wins} better, {losses} worse, sign test p ="
          f" {sign_test(wins, losses):.3f}, 95% interval [{low:+.2f}, {high:+.2f}]")
Terminal
python compare.py
Expected output
id   type       single         agentic        routed         
q01  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q02  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q03  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q04  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q05  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q06  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q07  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q08  docs       ok       2 calls  ok       4 calls  ok       3 calls  
q09  docs       abstain  2 calls  ok       7 calls  abstain  3 calls  
q10  docs       ok       2 calls  ok       8 calls  ok       3 calls  
q11  docs       abstain  2 calls  ok       9 calls  abstain  3 calls  
q12  sql        abstain  2 calls  ok       4 calls  ok       4 calls  
q13  sql        abstain  2 calls  ok       4 calls  ok       4 calls  
q14  sql        abstain  2 calls  ok       4 calls  ok       4 calls  
q15  sql        WRONG    2 calls  ok       4 calls  ok       4 calls  
q16  multi-hop  abstain  2 calls  ok       6 calls  ok       6 calls  
q17  multi-hop  abstain  2 calls  ok       6 calls  ok       6 calls  
q18  multi-hop  abstain  2 calls  ok       6 calls  ok       6 calls  
q19  multi-hop  abstain  2 calls  ok       6 calls  ok       6 calls  
q20  multi-hop  abstain  2 calls  ok       6 calls  ok       6 calls  

per type: correct, mean calls per question (mean calls in sequence)
docs      single  9/11  2.0 (2.0)  agentic 11/11  5.1 (5.1)  routed  9/11  3.0 (3.0)
sql       single  0/4   2.0 (2.0)  agentic  4/4   4.0 (4.0)  routed  4/4   4.0 (4.0)
multi-hop single  0/5   2.0 (2.0)  agentic  5/5   6.0 (5.6)  routed  5/5   6.0 (5.6)
all       single  9/20  2.0 (2.0)  agentic 20/20  5.1 (5.0)  routed 18/20  4.0 (3.9)
agentic vs single: 11 better, 0 worse, sign test p = 0.001, 95% interval [+0.35, +0.75]
routed vs single: 9 better, 0 worse, sign test p = 0.004, 95% interval [+0.25, +0.65]
agentic vs routed: 2 better, 0 worse, sign test p = 0.500, 95% interval [+0.00, +0.25]

05. Step 4: Read the results honestly

The headline is that agentic got all 20 right and single got 9: 11 questions better, none worse, p = 0.001, with an interval of +0.35 to +0.75. Written as a difference in accuracy, that is 55 percentage points (45% to 100%), not 55% and not 122% better. Before you act on it, read the rows:

  • Most of the gap is built into the fixture. 9 of the 11 wins are database and multi-hop questions. The single pass has no database tool, so it could never answer them. The test confirms what the design guaranteed; it says nothing about how well a planner would do on your questions.
  • On documentation questions the systems barely differ. Agentic won 2 of 11: q09 thanks to the rewrite and q11 thanks to the web fallback. Two wins and no losses is p = 0.5 for that subset, which is not evidence either way.
  • Routed keeps most of the gain for less. It matches agentic on every database and multi-hop question and loses only q09 and q11. Agentic against routed is 2 better, 0 worse, p = 0.500, with an interval from 0.00 to +0.25: not distinguishable on this set. Routed makes 4.0 calls per question on average against 5.1 for agentic.
  • Refusals cost the loop its full budget. On q10, which has no answer, single and routed abstain in 2 and 3 calls; agentic abstains too, after 8.
  • Not all misses are equal. The single pass answered q15 (who leads the Platform team?) with Owner: Platform team, a confident wrong answer, while its other misses were abstentions. Count wrong answers and refusals separately; the costs of each differ for your users.
  • Parallel steps save waiting, not calls. Multi-hop questions cost 6.0 calls each, but only 5.6 on average had to wait for each other, because q20 ran its two lookups in one wave.

The decision this supports is a routed design, confirmed on a larger set of real questions. A FAKE planner and grader never make mistakes they were not written to make; a real model will misroute some questions and misjudge some passages, and those errors are what the next comparison must measure.

06. Step 5: Turn calls into latency and cost

Calls are counted, not timed, because the fakes take microseconds. With real models, measure instead of estimating:

  1. Wrap every model and tool call in a timer (time.perf_counter()) and record the duration per call, per question and per system.
  2. Record token usage from each API response. The Anthropic Messages API, for example, returns usage.input_tokens and usage.output_tokens; multiply by the prices on your provider's pricing page.
  3. Report the median and 95th percentile of each question's total time, per question type, not just the mean. Agentic runs vary more, because the number of attempts varies.
  4. Run each configuration several times. Real graders and planners can give different verdicts on the same input, so a single run can make one system look better than it is.

A rough estimate before you have real runs: time per question is about the sum, over the calls in sequence, of the measured time per call. That is why the sequence count matters for latency and the total count for cost.

07. Check your understanding

Practice check · 3 questions

Reading a comparison

Use the expected output from step 3 to answer.

Q1. Agentic answered 20 of 20 and single answered 9 of 20 on the same questions. How should you report the difference?
Q2. Routed beats single on 9 questions and loses none (p = 0.004), but all 9 are database or multi-hop questions. What does that mainly show?
Q3. q10 has no answer anywhere. Single abstains after 2 calls and agentic after 8. What should you take from this?
Practice only: not graded, not saved, not evidence.

08. Apply it

Finish the practice project with this harness:

  1. Replace eval_set.py with your 20 labelled questions from lesson 1 (5 of them multi-hop) and freeze it.
  2. Plug your real single-pass pipeline and your agent into systems.py with the same return format, and add timing and token counts per call.
  3. Run each system three times. Report correct answers per question type, wrong answers and refusals separately, p50 and p95 time and cost per question, and the sign test and bootstrap interval for each pair.
  4. Write a one-paragraph recommendation that names the design for each question type and the measurement that would change your mind.

09. Review prompt

Without looking back:

  1. Why are the three systems compared on the same questions, and what does pairing add to the test?
  2. Which part of the agentic system's lead in this run was guaranteed by the fixture, and which part was measured?
  3. Why does the routed design cost fewer calls, and on which questions does it lose?
  4. How do you turn call counts into latency and cost estimates, and why are both the total and the in-sequence counts needed?
  5. What would you need to see before recommending agentic retrieval for all traffic?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check