~/satyajit

Agent harnesses: four of them, one local model, and where the tokens went

mdjsonmcp

2026-07-08 · 18 min · agents · harness

A 2:19 narrated explainer, drawn in code. Every number and picture in it is this article's own; the sources are below.

› transcript

Every coding agent runs this loop. The model asks for a tool, the harness runs it, the result goes back in. Everything outside the model is the harness. So what happens if you keep the model and swap the harness? Hi, I'm Nib. I ran four open source coding harnesses against one local model and counted every token. Thirteen small repositories, each with a test suite that fails until the bug is fixed. Each harness gets the same prompt, twice per task, inside a sandbox. A proxy in the middle forces the same sampling and logs every request. llama.cpp serves it, and reuses any prompt prefix it has already seen. And one model behind all of it, quantised to fit a single twenty-four gigabyte card. Twenty six runs per harness. And almost all of them pass. pi and OpenCode solve every task. The other two miss one each. The difference starts before any history. OpenCode's first request carries ten tools and a long system prompt. pi's carries four. That prefix rides along on every request, so a whole run grows to match. OpenCode sends about four times pi's prompt for the same fixes. Locally the cache hides most of it. On a metered API it does not. Price cache reads at a tenth, and OpenCode costs three times what pi does. Aider has no tools. The model reads a map of the repository and names the files it wants. In the second request it writes search and replace blocks, and Aider applies them. Fewest tokens of all four. But the file contents arrive late, so only half its prompt is reused from cache. The most expensive run was a failure. mini-swe-agent went round sixty times on one task, two thirds of everything it sent. Only the step limit stopped it. On harder benchmarks the harness moves the score too. Here, on one model, a searched harness beats Claude Code's own. On work a strong model can do, the harness sets the bill, not the score. Look at what it sends every time, and at what stops it. Same model, same tasks, a four times spread in tokens. Thanks for watching! Every source is in the full article. I'm Nib. Bye!

Why read this

Notabletop 60%

Four open harnesses metered on one local model over 13 tasks: same success, 4x spread in prompt tokens, and the design choice behind each gap.

  • Original analysis
  • Runs on a consumer GPU
  • Widely used

Agents & harnessesPractitioner teardown

How this was scored
Is it new?
1 of 3: An incremental tweak
Can I trust it?
2 of 3: Measures key facts from files, code or configs
Can I run it?
2 of 3: Open code or weights with real limits
Will I understand it?
2 of 3: Mechanism from first principles with figures
Can I act on it?
2 of 3: A concrete recipe, numbers or comparison
Will it last?
2 of 3: A reference for a year or more
Does it affect many?
2 of 3: A widely used model, tool or lab release
Only here?
2 of 3: A teardown or measurement few others did

Score 65 of 100, ranked 306 of 773 rated articles. Each question is answered 0–3 by hand, and a 3 is rare. How articles are scored

A base model predicts tokens. Everything an agent does past that (reading a repo, running a test, deciding it is finished) happens in the program wrapped around it. Lilian Weng calls that program the harness, and her post Harness Engineering for Self-Improvement argues that "the layer between the raw model and the real-world context seems to be as important as the model's raw intelligence."

This site has now read the code of a dozen harnesses. What it had not done is hold the model still and swap the harness. So I did: one model on one GPU, four open-source coding harnesses, the same thirteen tasks, and a proxy in the middle counting every token. On tasks this size the harness barely changed whether the work got done. It changed what the work cost by a factor of four, and each gap traces to one design decision you can point at in the harness's own source.

A flow diagram: USER INPUT flows into MODEL INFERENCE, which branches to either AGENT RESPONSE or TOOL CALLS; TOOL CALLS loops back into MODEL INFERENCE.
The loop every harness implements: inference returns either a final answer or tool calls, and tool results feed the next inference (OpenAI's Codex agent post, via Lilian Weng's post).

Seven decisions every harness makes

Weng defines the harness by its job: "the system surrounding a base model that orchestrates execution and decides how the model thinks and plans, calls tools and acts, perceives and manages context, stores artifacts, and evaluates results." Reading harnesses gives a more useful definition, by decision. Every coding agent the site has taken apart answers the same seven questions, and answers them differently.

  1. The loop. What ends a turn, and who decides the task is done. pi ends a run when a response carries no tool call. mini-swe-agent ends it when the model echoes a magic string. Aider has no tool loop: it asks for the files it needs, writes edit blocks in prose, applies them and runs the tests. Codex runs two loops stacked and starts a tool while the model is still streaming.
  2. The tool schema. What the model is offered on every request. It is re-sent whether a tool is called or not, which is the premise of TokenEconomizer.
  3. The edit primitive. Exact string replacement, a patch grammar with a fuzzy matcher (Codex's apply_patch tries four passes of falling strictness), SEARCH/REPLACE blocks in prose, or no edit tool at all and sed through a shell.
  4. Context management. What stays in the prompt as the run grows, what gets summarised and when, and whether the prefix stays byte-stable so a cache can reuse it. The site's prompt-caching teardown read eight harnesses for that alone.
  5. The sandbox. Where model-written commands run. Codex and Claude Code build a bubblewrap jail on Linux; pi and Aider run commands with the permissions of the process.
  6. Planning and sub-agents. A todo tool, a plan mode, a way to fork work into a child with its own context.
  7. Retries and stopping. What happens on a malformed call, a failed request, or a run that will not end.

Weng's own drawing of the coding loop puts names on the first three: observe the repo, plan, search and read, edit, run the tests, read the errors, repeat until done.

A left-to-right pipeline of rounded boxes: Observe repo, Plan, Search/read files, Edit/write patches, Run tests, Inspect errors. A green Done box sits above Run tests; a dashed Repeat arrow returns from Inspect errors back toward Plan.
The coding-harness loop: the agent works a repository the way a developer works an IDE, iterating until the tests pass (Lilian Weng, Harness Engineering for Self-Improvement).

The matrix has the answers for the four harnesses I ran and three the site has read. Pick an axis; open a row for the rest of it and where each answer came from. Where a cell says "not checked", nobody here has read that part of the code.

The experiment

The cleanest way to see what a harness does is to hold everything else still: one model, one server, one task set, one sampling setting. I ran that on beast2, a single RTX 3090.

The model is Qwen3.8-27B (Apache-2.0), the same base weights as the harness adapters piece, as Unsloth's UD-Q4_K_XL GGUF (17.66 GB). llama.cpp's llama-server (build 12559, compiled on the box) serves it with --jinja, so the chat template turns Qwen's XML tool calls into OpenAI JSON, a 65,536-token window and an 8-bit KV cache. Thinking is off. The model card's non-thinking sampling (temperature 0.7, top_p 0.8, top_k 20, presence_penalty 1.5) is forced on every request whatever the harness asked for; Aider asked for temperature 0 and did not get it. One server slot, so requests never shared the GPU. On this setup the server decodes at 39.0 tokens per second.

Four harnesses, all permissively licensed, all able to run headless against an OpenAI-compatible URL:

A metering proxy sits between every harness and the server. It forwards each request unchanged except for the sampling, and logs what the harness sent (messages by role, the tools offered, the system prompt and schemas tokenized by the server's own /tokenize) and what came back: llama.cpp's prompt, cached and completion token counts, its prefill and decode times, every tool call, whether the call named a tool that exists and whether its arguments parsed. That gives the same numbers for every harness without trusting any harness's own accounting.

Thirteen tasks, written for this run and small enough to grade in a second: seven single-file bugs (a slug function, a retry decorator, a CSV total, an arithmetic parser, a word wrapper, a dict merge, a duration parser), two where the symptom and the cause sit in different modules, three features to write from a docstring, and one 30-module package where the report names only a CLI symptom and one line in app/core/ranking.py is wrong. Each is a git repo with a unittest suite. Grading restores the pristine tests before running them, so editing a test never passes. Every harness got the same prompt: the bug report, "check your work with python3 -m unittest", "do not edit anything under tests/". Each harness ran each task twice in a shuffled order, with a 360-second cap per run, every command inside a bubblewrap sandbox where only the job directory was writable.

Everyone passed

HarnessSolvedMedian requestsMedian prompt tokensMedian generatedMedian wall
pi26 / 26510,87644215.6 s
OpenCode26 / 26644,00857523.2 s
mini-swe-agent25 / 265.511,15168626.1 s
Aider25 / 2626,04070426.6 s

Fifty-two runs a harness would not separate success rates that differ by a task or two, and these do not differ by more than one. The tasks are small and Qwen3.8-27B is strong; the card reports it on SWE-bench Pro and Terminal-Bench, not on toy repos. What the table does separate is how each harness got there, and the spread is wide: OpenCode's median run sends four times the prompt tokens pi's does, and Aider gets there in two requests where the others take five or six.

The figure below is the run itself. Pick a task; each harness's first attempt is drawn on one shared scale, one bar per request, split into what llama.cpp served from its prompt cache, what it had to prefill, and what the model generated.

Where OpenCode's tokens go

The gap opens on the first request. Before any history, OpenCode's first agent request is 7,554 tokens (the median over its 26 runs). pi's is 1,636, mini-swe-agent's 1,117 and Aider's 2,955. pi's system prompt is 600 tokens and its four tool schemas 720 more; mini-swe-agent sends a 12-token system prompt, one 65-token bash schema and puts its 820-token instructions in the first user message. OpenCode offers ten tools on every agent request and a much longer system prompt. That prefix rides along on every later request, so a run of six requests pays it six times, and the median OpenCode run ends up at 44,008 prompt tokens to pi's 10,876.

It also makes one request the others do not. Every OpenCode run opened with a short request carrying no tools at all, 641 tokens on the explore task: the session title, generated by the "small model", which I had pointed at the same local model so nothing left the box. That is 26 extra requests over the run, one per task.

Locally the extra prompt was cheap. llama.cpp kept the prefix in its cache, so 90.8% of OpenCode's prompt tokens after the first request were cache hits, and its whole run spent 137 seconds prefilling against pi's 61. Wall time is decode: at 39 tokens a second, generating tokens took 73% to 84% of every harness's wall clock. On a metered API the same prefix costs money even when it hits. At a cache-read price of a tenth of the input rate (the multiplier the harness effect paper bills by), OpenCode's whole run comes to 273,643 input-token equivalents and pi's to 81,674, 3.35 times as much for the same 26 fixes (my arithmetic on the proxy's counts).

None of that makes OpenCode worse. Its ten tools include glob and grep, and on the explore task it found app/core/ranking.py with one glob and six reads, where pi started from a bash listing. A harness built for larger repos than mine carries the tools for them on every request. The cost is a choice, and it shows up on the bill first.

Why Aider made two requests

Aider has no tool loop. Its first request carries a 1,316-token system prompt and a tree-sitter map of the repository; the model reads the map and names the files it wants. Aider adds them and sends a second request, the model writes SEARCH/REPLACE blocks, Aider applies them and runs the test command. Eleven of its 26 runs took exactly two requests. Six took one, where the model wrote an edit straight from the map. The other nine took three to five: another round of files, or the auto-test loop feeding a failing test back, which it does up to three times (max_reflections in base_coder.py).

That makes Aider the lowest in prompt tokens by a wide margin (192,754 for the whole run, against pi's 371,455) and the worst at reusing them. Only 48.4% of its prompt tokens after the first request were cache hits, against 94.9% for pi and 95.9% for mini-swe-agent. Part of the reason is the loop itself: the file contents arrive only in the second request, so its prefix changes early. Part is the layout the prompt-caching teardown read in the code, history before the editable files, so every edit rewrites the tail of the prompt. Priced the same way as above, Aider's run comes to 133,952 input-token equivalents, more than pi's despite half the prompt. It also generates the most per request: whole edit blocks with their context lines, a median 704 tokens a run.

Its one failure is the most instructive line in the log. On the second attempt at the explore task, the model's first and only reply was 43 tokens long and contained a <tool_call> block. Aider offers no tools, so there was nothing to parse: no file request, no edit block. Aider exited after one request having changed nothing. A model tuned for tool-calling harnesses reached for a tool that this harness does not have. The harness adapters piece calls a harness a dialect; this is what speaking the wrong one looks like.

What a stopping rule is worth

mini-swe-agent's failure cost more than all its successes. On the second attempt at the duration parser it ran to the 60-step limit I had set: 60 requests, 318.6 seconds, 614,218 prompt tokens, its context peaking at 18,111. That one run is 67% of all the prompt tokens mini-swe-agent sent across 26 runs. Its own instructions say to finish by echoing COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT; nothing in the harness notices a run going round in circles, so the step limit was the only brake. The first attempt at the same task took 8 requests and 49.5 seconds.

This is the seventh axis of the matrix with a price on it. OpenCode has a doom_loop permission for repeated identical calls. mini-swe-agent stops after three malformed replies in a row, but sixty well-formed ones look like progress to it. I found neither a loop detector nor a step limit in pi's documented defaults, and on these tasks it never needed one: its longest run was 12 requests. Weng's list of how autonomous agents fail includes over-optimism, a model declaring success on a failed experiment. The mirror image is a model that never declares success, and only the harness can stop it.

Tool-call errors were nearly zero

Across 530 tool calls from the three tool-calling harnesses, the proxy saw no call to a tool that did not exist and no arguments that failed to parse, no failed request, and only the one leaked <tool_call> above. That is less a property of the harnesses than of the server: with --jinja, llama.cpp parses Qwen's XML calls into JSON before any harness sees them, so a malformed call becomes plain text rather than a broken call. The harness-level errors were rare too. Aider had three SEARCH blocks that failed to match, all in one run on the intervals task, and recovered to solve it. pi's own event stream marked 10 tool results as errors, all on the roman and durations tasks, where it also counts a command that exits non-zero.

The edit primitive mattered less than I expected. pi's exact {oldText, newText} replacement, OpenCode's edit, mini-swe-agent's sed and heredocs, and Aider's SEARCH/REPLACE all landed their edits on these files. A 27B model copies a five-line function verbatim without trouble. The matchers in Codex and the cost of a failed match matter on larger files and weaker models, and nothing here tested that.

Guardrails live outside the loop

Two of the four harnesses I ran, pi and Aider, execute whatever the model writes with the permissions of the process that started them, and OpenCode's protection is a permission ruleset the harness itself enforces. So the sandbox in this run was mine, not theirs: every agent ran inside bubblewrap with the root filesystem read-only, its own process namespace and only the job directory writable. Weng makes the same point about any agent that can edit the system it runs on: "the permission control and security layers need to live outside this loop." A rule in the prompt is advice to the model. A read-only mount holds whether the model remembers the rule or not, which is why Codex and Claude Code both build one (the Claude Code sandbox is a generated bwrap command line plus two seccomp filters). My proxy did not log the commands themselves, so I cannot say whether any of the 104 runs tried; outside the jail, nothing in pi or Aider would have stopped one.

When the harness is what gets searched

If the program around a model moves the bill this much, and on harder tasks the score, the next step is to let a model write the program. Weng spends the second half of her post on that.

The cleanest case is Meta-Harness (Lee et al., 2026). Its proposer is a coding agent that reads every earlier candidate's source, scores and execution traces from a file system with grep and cat, and writes a new harness; the ones on the Pareto frontier survive. The paper opens with the claim this page is about: changing the harness around a fixed model "can produce a 6× performance gap on the same benchmark." On TerminalBench-2 with Claude Haiku 4.5, the searched harness scores 37.6%, ahead of Goose at 35.5% and Mini-SWE-Agent at 29.8%; Claude Code's harness, at 27.5%, is last of the six.

Two panels. Left: a line chart of best performance against harness evaluations on text classification; Meta-Harness climbs from about 33% to about 57% within 26 evaluations, above TTT-Discover, OpenEvolve, and the ACE, few-shot and zero-shot baselines. Right: a bar chart of TerminalBench-2 pass rate with Claude Haiku 4.5: Meta-Harness 37.6, Goose 35.5, Terminus-KIRA 33.7, Mini-SWE-Agent 29.8, Terminus-2 28.3, Claude Code 27.5.
A model-written harness against hand-written ones. Left: search progress on text classification; right: TerminalBench-2 pass rate, every bar on Claude Haiku 4.5 (Lee et al., Meta-Harness, Figure 1).

Self-Harness (Zhang et al., 2026) runs the same idea on a tighter leash: run the current harness, cluster the failures in its traces, propose bounded edits (validate before concluding, break a loop, change a tool policy), and keep an edit only if a regression run accepts it. Its "loop-breaker" is the brake mini-swe-agent lacked above.

A four-stage cycle. Weakness Mining: run the current harness on tasks, collect execution traces, cluster failure patterns. Harness Proposal: use the failures to propose harness edits like validate-before-conclude, a loop-breaker, a tool-policy update. Proposal Validation: run a regression test and accept or reject each edit. Accepted edits produce an Updated Harness that proceeds to the next iteration; if all are rejected, no update.
Self-Harness: mine failure patterns from traces, propose harness edits, promote only the ones that pass a regression test (Zhang et al., 2026, via Lilian Weng's post).

The result that complicates it is Lin et al. (2026). They split self-improvement into two abilities: writing a useful harness edit, and benefiting from one. The first is flat across model size; in Weng's summary, a 9B proposer writes "a skill procedurally isomorphic to Opus." The second is not. Middle-tier models gain most. Weak models fail to load the harness or load it and do not follow it, and strong models were already near their ceiling.

Two panels. Left, harness-updating is flat in base capability: Qwen3-32B, Qwen3-235B, GPT-OSS-120B, Haiku 4.5, Sonnet 4.6 and Opus 4.6 all score between about 3 and 4.5 points, mean 3.75. Right, harness-benefit is non-monotonic: an inverted U peaking near GPT-OSS-120B at about 9.5 points, with Qwen3-32B near 4 and Opus 4.6 and Sonnet 4.6 near 3.5 to 4.5. Side boxes name two weak-model failure modes, harness activation failure and harness adherence failure, and say strong models reach the performance ceiling.
Writing a harness edit is easy for every model tested; benefiting from one peaks in the middle tier (Lin et al., 2026, Figure 2).

My run sits at the ceiling end of that curve. A strong model on small tasks passes under any of the four harnesses, so the harness shows up only in the bill. The older results Weng surveys point the same way. The Darwin Gödel Machine's self-modified coding agents went from 20% to 50% on SWE-bench Verified and from 14.2% to 30.7% on Polyglot. STOP, which lets a model improve its own scaffolding, helped with GPT-4 and made things worse with GPT-3.5 and Mixtral. Weng's reading: "Recursive structure alone is not enough. The base model must be capable enough to improve the mechanism."

Where I land

For a capable model on well-specified work, pick a harness for what it costs per task and for how it stops, not for its benchmark row. On my tasks pi did the same work as OpenCode for a quarter of the prompt tokens and two thirds of the wall time, because it sends four tools and a short prompt and does nothing else. OpenCode's extra prefix buys search tools I did not need here and would on a real monorepo, and its title request is overhead on every run. Aider is the cheapest in raw tokens and the worst at keeping a cache warm, which flips once a provider bills cache reads. And the run that cost the most was the one a harness let go round 60 times. If I were adding one thing to a harness tomorrow it would be a loop guard, before any new tool.

What this does not show: harder tasks, where a small set of tools may start losing to a large one; weaker models, where Lin et al. say the harness matters most; and anything about Codex or Claude Code, which I read rather than ran. The harness effect paper covers the vendor-scale version of the cost argument, and the compositional generalization post the research end, a harness trained to decompose.

Cite this article

For attribution, please use the following reference or BibTeX:

Satyajit Ghana, "Agent harnesses: four of them, one local model, and where the tokens went", ai.satyajit.si, July 2026.

bibtex
@misc{ghana2026agentharness,
  author = {Satyajit Ghana},
  title  = {Agent harnesses: four of them, one local model, and where the tokens went},
  url    = {https://ai.satyajit.si/articles/agent-harness},
  year   = {2026}
}
share