Psychosonic Lab · Experiment 08

Does a cheap first try pay off?

Replaying agent-smith's escalation ladder over answers the models already gave

agent-smith can send a job to the cheapest model first and climb to a stronger one only when the answer breaks: empty, cut off, or not valid JSON or Python. It is a tempting rule, because the cheap answer is often fine. The catch is that the check is mechanical. It can tell a broken answer from a whole one, not a right answer from a wrong one. We replayed the ladder over 156 answers our gym had already graded, to see what that costs.

Run on 2026-10-26 · macOS 27.0.1 · Apple M3 Pro, 36 GB · agent-smith 800aba5 · Agent Gym 34ad639
Code: agent-smith on GitHub

01

The question

01.1

What is being asked

If a job goes to the cheapest model first and climbs only when the answer fails a mechanical check, how often does the climb stop on a wrong answer? Does it matter which rung the ladder starts on?

01.2

Why it matters

The ladder was added to agent-smith on 2026-10-20 and has so far only been smoke tested. A default is hard to take back once work runs through it, so it is worth knowing first what a cheap first try gives up.

01.3

What counts as right

A climb ends on the first rung whose answer passes the check. It ends right when the gym's hidden tests passed that answer.

02

Method

02.1

The ladder

Four rungs, cheapest first: T0 is Llama 3.2 3B on this Mac, T1 is gpt-oss 20B on this Mac, T2 is GLM 5.3 on Z.ai's flat-rate plan, and T3 is Gemini Pro. Each kind of job has a rung it starts on. The check, check_output in cascade.py, fails an answer that is empty, cut off, JSON that does not parse, or Python that does not parse. Nothing else.

02.2

The answers

Agent Gym kept the first answer each model gave on each of its one-shot tasks, and graded it with hidden tests. The replay uses those answers, so it calls no model and costs nothing to run. Experiment 05 shows how the gym grades.

02.3

The replay

cascade-replay.py runs the check on every kept answer from the four models. Then, for each task and each of four ladders, it climbs: it takes the start rung's latest answer, stops if the check passes it, and moves up a rung if not. The ladders start at T0, at T1 and at T2, and the fourth is T2 alone, no ladder at all. The check is copied into the script, and the script refuses to run if the copy no longer matches agent-smith's own.

02.4

What cannot be replayed

A climb that reaches a rung the gym never ran on that task is left out. So is a graded answer whose file the gym did not keep, because the check cannot be run on it.

03

Materials

03.1

The script

One file of Python, 216 lines, standard library only. It reads the gym's task and run files and writes three files. It runs no model and no answer. It is shown in full below with its checksum.

03.2

agent-smith

The ladder is open source, at github.com/negativetime/agent-smith-plugin. This run checked its copy of the check against commit 800aba5.

03.3

The data

answers.csv has one row per kept answer: the task, the rung, the model, the gym's grade, what the check said, and a fingerprint of the answer. ladders.csv has one row per task and ladder. The answers themselves are not published.

cascade-replay.py 216 lines · sha256 e7b224fc678f59509e2d939052c42ca08369ca591727678ad5760462030e8a8a
Show the script in full
#!/usr/bin/env python3
"""Replay agent-smith's escalation ladder over answers a model already gave, with no model calls.

agent-smith's --cascade (github.com/negativetime/agent-smith-plugin, scripts/cascade.py)
sends a prompt to the cheapest rung first and climbs to the next only when the answer
fails a mechanical gate: empty, cut off, JSON that will not parse, Python that will not
parse. The gate cannot tell a right answer from a wrong one that is well formed. This
script measures what that costs, using answers our Agent Gym kept from earlier runs of
the same models on the same tasks, each already graded by the gym's hidden tests.

For every one-shot task and every rung it reads each kept first answer (L0), runs the
gate on it (check_output, copied below from cascade.py), and writes:

    answers.csv  one row per kept answer: task, rung, model, run, the gym's grade, its seconds, the gate
    ladders.csv  one row per task and ladder: the rung the climb stopped on, and whether
                 the answer it stopped on was right. Each rung uses its LATEST kept answer.
                 A climb that reaches a rung with no answer for that task is "untested".
                 Its seconds are the gym's timing of each rung's kept answer, added up.
    meta.json    the rung map, the ladders, and the gate's source check

A rung's answer counts as no answer (the gate fails it as empty) when the gym recorded
that none arrived: a timeout, an API error, a model that spent its whole budget thinking.
A graded answer whose file the gym did not keep is listed as "not kept" and left out of
the ladders, because the gate cannot be run on it.

Usage:
    python3 -I cascade-replay.py TASKS RUNS OUT
    python3 -I cascade-replay.py TASKS RUNS OUT --plugin ~/.claude/skills/agent-smith
"""
import argparse
import ast
import csv
import glob
import hashlib
import inspect
import json
import os
import sys

# The ladder's rungs (cascade.py, 2026-10-20) and the gym label each one's answers are under.
# T3 in the ladder is Gemini Pro through the Gemini CLI; the gym ran Gemini Pro through the API.
RUNGS = {"T0": ("llama3.2:3b", "llama3.2-3b"), "T1": ("gpt-oss:20b", "gpt-oss-20b"),
         "T2": ("glm-5.3 on z.ai", "zai-glm-5.3"), "T3": ("Gemini Pro", "gemini-pro")}
# Notes the gym writes when no answer arrived (timeout, API error, a model that spent its
# whole budget thinking). The live ladder would see an empty reply and climb.
NO_ANSWER = ("task-timeout", "gen-error", "gen-timeout", "harness-error", "gen-empty")
PAID = {"T2", "T3"}   # flat-rate plans already paid for, but not free and not on this Mac
LADDERS = {"from T0": ["T0", "T1", "T2", "T3"], "from T1": ["T1", "T2", "T3"],
           "from T2": ["T2", "T3"], "T2 only": ["T2"]}


# ---- copied from cascade.py; --plugin checks the copy still matches -----------------

def _strip_fence(text):
    s = text.strip()
    if not s.startswith("```"):
        return s
    lines = s.splitlines()[1:]
    if lines and lines[-1].strip().startswith("```"):
        lines = lines[:-1]
    return "\n".join(lines).strip()


def check_output(text, finish_reason=None, want_json=False, want_python=False,
                 extra=()):
    """Return None when the output passes every mechanical gate, else a short reason.

    `extra` is a sequence of callables (text) -> reason-or-None, for gates that live in
    gemini.py (the agentic-non-answer detector)."""
    if not text or not text.strip():
        return "empty"
    if finish_reason in ("length", "max_tokens", "MAX_TOKENS"):
        return "truncated"
    if want_json:
        try:
            json.loads(_strip_fence(text))
        except ValueError:
            return "bad-json"
    if want_python:
        import ast
        try:
            ast.parse(_strip_fence(text))
        except SyntaxError as e:
            return f"py-syntax (line {e.lineno})"
    for fn in extra:
        why = fn(text)
        if why:
            return why
    return None

# ---- end of copy --------------------------------------------------------------------


def check_copy(plugin):
    """Compare the two functions above with cascade.py's, character for character."""
    src = open(os.path.join(plugin, "scripts", "cascade.py"), encoding="utf-8").read()
    theirs = {n.name: ast.get_source_segment(src, n) for n in ast.parse(src).body
              if isinstance(n, ast.FunctionDef)}
    for fn in (_strip_fence, check_output):
        if theirs.get(fn.__name__) != inspect.getsource(fn).rstrip("\n"):
            sys.exit(f"{fn.__name__} here no longer matches {plugin}/scripts/cascade.py; copy it again")
    return hashlib.sha256(src.encode("utf-8")).hexdigest()


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("tasks")
    ap.add_argument("runs")
    ap.add_argument("out")
    ap.add_argument("--plugin", help="an agent-smith checkout, to check the gate copy")
    a = ap.parse_args()
    cascade_sha = check_copy(os.path.expanduser(a.plugin)) if a.plugin else None

    tasks = {}
    for name in sorted(os.listdir(a.tasks)):
        p = os.path.join(a.tasks, name, "task.json")
        if os.path.isfile(p):
            t = json.load(open(p, encoding="utf-8"))
            if t.get("mode") == "oneshot":
                tasks[name] = t
    label_to_rung = {lab: rung for rung, (_, lab) in RUNGS.items()}

    answers = []
    for f in sorted(glob.glob(os.path.join(a.runs, "*", "results.jsonl"))):
        run = os.path.basename(os.path.dirname(f))
        for line in open(f, encoding="utf-8"):
            try:
                r = json.loads(line)
            except ValueError:
                continue
            rung, t = label_to_rung.get(r.get("model")), tasks.get(r.get("task"))
            if not rung or not t or r.get("condition") != "L0":
                continue
            graded = r.get("outcome") or ("pass" if r.get("pass") else "fail")
            # A repeated run keeps each repeat in <task>.rep<N>/.
            folders = ([f"{r['task']}.rep{r['rep']}"] if r.get("rep") else []) + [r["task"]]
            path = next((p for d in folders for p in
                         (os.path.join(a.runs, run, r["model"], d, "work", "L0." + t["artifact"]),
                          os.path.join(a.runs, run, r["model"], d, "work", t["artifact"]))
                         if os.path.isfile(p)), None)
            no_answer = graded == "unmeasurable" or any(m in (r.get("note") or "") for m in NO_ANSWER)
            if no_answer:
                text, gate = "", "empty"
            elif path:
                text = open(path, encoding="utf-8", errors="replace").read()
                gate = check_output(text, want_json=t["artifact"].endswith(".json"),
                                    want_python=t["artifact"].endswith(".py")) or "pass"
            else:
                text, gate = "", "not kept"   # graded, but the file is gone: the gate cannot be replayed
            answers.append(dict(task=r["task"], capability=t.get("capability", ""), rung=rung,
                                model=r["model"], run=run, ts=r.get("ts", ""), rep=r.get("rep") or "",
                                graded=graded, seconds=r.get("seconds", ""),
                                gate=gate, kept="yes" if path else "no",
                                sha256=hashlib.sha256(text.encode()).hexdigest() if text else ""))

    latest = {}
    for x in sorted(answers, key=lambda x: (x["run"], x["ts"], str(x["rep"]))):
        if x["gate"] != "not kept":
            latest[(x["task"], x["rung"])] = x

    ladders = []
    for name in sorted(tasks):
        for lname, rungs in LADDERS.items():
            tried, row = [], dict(task=name, ladder=lname)
            for rung in rungs:
                x = latest.get((name, rung))
                if not x:
                    row.update(stopped="untested", at=rung, right="", tried=" ".join(tried))
                    break
                tried.append(rung)
                if x["gate"] == "pass":
                    row.update(stopped="answer", at=rung, right="yes" if x["graded"] == "pass" else "no",
                               tried=" ".join(tried))
                    break
            else:
                row.update(stopped="every rung failed the gate", at="", right="no", tried=" ".join(tried))
            row["paid_rungs"] = sum(1 for r in tried if r in PAID)
            # The time the climb took, as the gym timed each rung's kept answer, one rung after the other.
            secs = [latest[(name, r)]["seconds"] for r in tried]
            row["seconds"] = round(sum(float(x) for x in secs), 1) if secs and all(x != "" for x in secs) else ""
            ladders.append(row)

    os.makedirs(a.out, exist_ok=True)
    write(os.path.join(a.out, "answers.csv"),
          ["task", "capability", "rung", "model", "run", "rep", "graded", "seconds", "gate", "kept", "sha256"], answers)
    write(os.path.join(a.out, "ladders.csv"),
          ["task", "ladder", "stopped", "at", "right", "tried", "paid_rungs", "seconds"], ladders)
    meta = dict(rungs={k: dict(model=m, gym_label=lab) for k, (m, lab) in RUNGS.items()},
                ladders=LADDERS, paid=sorted(PAID), oneshot_tasks=len(tasks),
                gate_copy_checked_against=(dict(file="scripts/cascade.py", sha256=cascade_sha)
                                           if cascade_sha else None))
    with open(os.path.join(a.out, "meta.json"), "w", encoding="utf-8") as f:
        json.dump(meta, f, indent=2)
        f.write("\n")

    for rung in RUNGS:
        xs = [x for x in answers if x["rung"] == rung]
        through = [x for x in xs if x["gate"] == "pass"]
        wrong = sum(1 for x in through if x["graded"] != "pass")
        print(f"{rung} {RUNGS[rung][0]:16} {len(xs):3} answers, {len(through):3} through the gate, "
              f"{wrong:3} of those wrong")
    for lname in LADDERS:
        rs = [r for r in ladders if r["ladder"] == lname and r["stopped"] != "untested"]
        print(f"{lname:8} {len(rs):2} tasks climbed, {sum(r['right'] == 'yes' for r in rs):2} right")


def write(path, cols, rows):
    with open(path, "w", encoding="utf-8", newline="") as f:
        w = csv.DictWriter(f, fieldnames=cols, extrasaction="ignore")
        w.writeheader()
        w.writerows(rows)


if __name__ == "__main__":
    main()
04

Results

Run on 2026-10-26 · macOS 27.0.1 · Apple M3 Pro, 36 GB · agent-smith 800aba5 · Agent Gym 34ad639

What the check let through

RungModelAnswersStopped by the checkLet throughWrong among thoseMedian seconds
T0llama3.2:3b80863
T1gpt-oss:20b65164454
T2glm-5.3 on z.ai56155726
T3Gemini Pro27126215

The check stopped 3 of 156 answers, all of them answers that never arrived. It let through every wrong answer, 19 in all, because each one was well formed.

Where each ladder stopped

LadderTasks the replay could finishEnded rightT2 alone, same tasksPaid rung calls
from T07270
from T11614140
from T226212126
T2 only262126

From T0 the climb stopped on the first rung on all 7 tasks it could finish, and ended right on 2. GLM alone got 7 of the same 7 right. Llama 3.2 3B wrote a well formed answer every time, so the check never sent the job up.

From T1 the climb ended right on 14 of 16 tasks and never used a paid rung. GLM alone got 14 of the same tasks right. Here the cheap first try saved the paid calls, but not because the check caught anything: gpt-oss 20B was already as good as GLM at these tasks.

From T2 the climb never reached T3 and ended right on 21 of 26, the same as T2 alone. The check never found a reason to climb past GLM.

How long each ladder took

LadderTasksMedian secondsTotal secondsT2 alone, medianT2 alone, total
from T07329893
from T116682,158231,053
from T226231,300231,300
T2 only26231,300231,300

Seconds are what the gym timed for each rung's kept answer, added up for the rungs a climb tried, one after the other, on the tasks where both the ladder and T2 alone could be finished.

From T1 the climb took 2,158 seconds on its 16 tasks, against 1,053 for GLM alone. It used no paid call, and it took about 2.0 times as long, because gpt-oss 20B on this Mac took a median 54 seconds an answer and GLM, over the network, 26. From T0 the climb was quicker, 29 seconds against 93 on 7 tasks, but it ended right far less often. From T2 it took exactly the time of T2 alone.

A ladder is only as good as its bottom rung, because the check passes a wrong answer as readily as a right one. That is why agent-smith's ladders start at T1 or T2, and by default never at T0: cascade.py says so next to the ladder table, after Llama 3.2 3B scored zero on the gym's two structure tasks.

05

What this shows

05.1

The check stops missing answers, not wrong ones

The only answers the check stopped were ones that never arrived. Every wrong answer that was well formed went through.

05.2

The bottom rung decides

Starting on the smallest model, the climb stopped on its first rung on every task it could finish, and ended right far less often than GLM alone.

05.3

A good bottom rung saves the paid calls

From T1 the climb never used a paid rung and ended right as often as GLM alone, because gpt-oss 20B was already as good at these tasks, not because the check caught anything.

05.4

From T2 it never climbed

Starting on GLM, the climb never reached T3 and matched GLM alone.

05.5

Saving paid calls cost time

The climb that saved the paid calls took longer than sending the job straight to GLM, because the cheap model ran slower on this Mac than GLM did over the network.

06

What this does not show

06.1

Replayed, not run

Each answer is the one a model gave on the day the gym ran it. A live call can give another answer, even at temperature 0. Experiment 05 is about exactly that.

06.2

A gentler check than a live one

The gym keeps an answer after removing code fences and stray prose, so the replayed check saw cleaner text than a live ladder would. A live ladder would call more answers broken and climb more often.

06.3

Small numbers

T0 has kept answers on only 7 tasks, and T1 on 16. The ladders from those rungs are measured on those tasks alone.

06.4

A different route to T3

The ladder reaches Gemini Pro through the Gemini command line tool. The gym's Gemini Pro answers came through the API.

06.5

The latest answer only

The gym ran some tasks several times. The replay climbs on each rung's latest kept answer, which is one answer, not a rate.

06.6

Gym tasks are not real jobs

They are short and checkable by design. Time is the seconds the gym recorded for each kept answer, on different days and under whatever else the Mac was doing, so a climb's time adds numbers that were never measured together. Tokens and money were not measured.

07

Run it yourself

07.1

Try the ladder

python3 scripts/gemini.py --cascade --tag classify "label each line: bug, feature or question"
python3 scripts/cascade.py --report
The report shows, for each kind of job, how often the climb left its start rung.

07.2

Replay it over your own graded answers

python3 -I cascade-replay.py ./tasks ./runs ./out --plugin ~/.claude/skills/agent-smith
It expects the gym's layout: task.json per task, and per run a results.jsonl beside <model>/<task>/work/<artifact>. Point RUNGS at the top of the script at your own models' labels.

07.3

Change the ladders

LADDERS holds the four this page compares. Add the one you are thinking of making a default, and compare it with its top rung alone.

07.4

If yours differs

Send out/ladders.csv to info@psychosonicconsulting.com and we will look.

The Signal

One signal a week. No noise.

A short note on building privacy-first software, plus the day each new app ships. No spam, unsubscribe anytime.

Free · ~1 email a week · your address stays yours · RSS feed