Recursive Harness Engineering · Part 4 of 4

Closing the loop: a program that improves an agent harness

This article is for engineers who already evaluate an AI agent or workflow and want to automate the next step: letting a coding agent propose fixes. The fixes must not overfit to the evaluation tasks, and they must not pass the checks without doing the task. A harness is the code around a language model: its prompts, tools, control flow and checks. You will learn how to build an improvement loop while the model stays fixed. A coding agent reads failed runs and edits a copy of the harness, an evaluator scores each copy on tasks the agent cannot see, and a rule decides whether the edit is a real improvement or run-to-run noise.

The article explains the ideas first: what closing the loop means, which parts it has, and seven steps for setting one up. Two worked examples then show the steps on real runs. In one, a support assistant, the loop tried six fixes and kept three, and the share of held-out test runs passed rose from 44% to 90%. In the other, an assistant that turns questions into SQL, it repaired one fault behind many wrong answers. The share of held-out test runs passed rose from 58% to 90% in one campaign and 100% in another, and a further run of the loop lowered the cost of each answer by a quarter. Both examples are public. A section after them shows how to replay their saved runs without an API key, and how to run the loop on your own harness. The last sections cover what goes wrong, when a loop is worth building, and what would make it recursive.

This is Part 4 of Recursive Harness Engineering, a series that takes one customer-support assistant from a design on paper to a loop that improves it. Part 1 designs the harness, Part 2 shows that a workflow with no agent passes the same tests at a fraction of the cost, and Part 3 builds an evaluator that finds where that workflow fails. This part gives the failures to a program. You do not need the earlier parts: where this article builds on them, it recaps what you need.

What closing the loop means

Improving a harness by hand follows a cycle. You read failed runs, guess the cause, edit a prompt or some code, run the evaluation again, and decide whether to keep the edit. Even with an automated evaluation, a person takes the result of one round and starts the next.

The loop is closed when that result starts the next round by itself. A program reads the failures, writes the change, measures it and applies a rule that keeps or drops it. Your work moves from writing edits to designing the process: which goal it has, which tasks and checks measure it, what it may change, and what counts as an improvement.

The figure shows four ways to share the work. It calls whoever writes the changes, a person or a program, the improver.

Four ways to improve a harness and who does each of four jobs. By hand: a person writes the change, a program measures it, a person decides, and a person improves the improver. Assisted: a program writes and measures, a person decides. Closed loop, marked: a program writes, measures and decides by a rule; a person still improves the improver. Recursive: programs do all four jobs, including improving the improver. People set the goal and the limits at every level.Four ways to improve a harness and who does each of four jobs. By hand: a person writes the change, a program measures it, a person decides, and a person improves the improver. Assisted: a program writes and measures, a person decides. Closed loop, marked: a program writes, measures and decides by a rule; a person still improves the improver. Recursive: programs do all four jobs, including improving the improver. People set the goal and the limits at every level.

Each row gives one more job to a program. LangChain describes the second row: its agents read failed traces and suggest changes, and a person approves each one. Edits to the harness raised its coding agent from 52.8% to 66.5% on Terminal-Bench 2.0 with the same model. This article is about the third row.

Three names from this area appear in the article, and I use them like this:

NameWhat it means here
Closed-loop AI engineeringA fixed program improves a harness in rounds, without a person passing each result to the next change. The examples in this article do this.
Recursive harness engineeringExtending that loop so later campaigns also change how the harness is improved (the improver, its instructions, or a library of fixes) and test that it helps. This series builds toward it.
Recursive self-improvementThe general, strict case in which any system improves the process that improves it, not only an agent harness.

The four parts of the loop

Every automated improvement loop separates four jobs: who writes a change, who measures it, who decides whether to keep it, and where the record lives.

  • The improver proposes a change. Today it is usually a coding agent that receives a copy of the harness and edits the files directly.
  • The evaluator measures the change. It runs the edited harness on tasks, captures what happened and grades each run with checks.
  • The adoption rule decides. It compares the edited harness against the current one on the same tasks, then keeps the edit or drops it. An edit is dropped either because it makes things worse or because there is not enough evidence that it helped.
  • The ledger records every proposal: what changed, its scores, and the reason it was kept or dropped.

Each edited copy of the harness is a candidate. When the rule keeps a candidate, it becomes the current harness. The next candidate is built from it and compared with it, not with the harness the campaign started from. When the rule drops one, the improver receives the previous harness again, along with the history of earlier attempts. One pass through the four parts is a round, and a complete series of rounds, from the starting harness to the final score, is a campaign.

The evaluation tasks are split into three sets. The improver reads failures on development tasks in full so it can diagnose them. Validation tasks decide whether a candidate is kept, and the improver never sees them. Test tasks are scored once, after the campaign stops, on the starting harness and the final one. Step 2 explains why a loop needs three sets, and when two are enough.

One round of the loop. The improver edits a copy of the current harness. The candidate is checked for validity and screened on development tasks, then scored on validation tasks, and the rule keeps it or drops it; either way a row goes to the ledger. From development tasks the improver gets failed checks, sample runs and traces. From validation tasks it gets only the decision and its reasons. Test tasks send nothing back and are scored once after the last round.One round of the loop. The improver edits a copy of the current harness. The candidate is checked for validity and screened on development tasks, then scored on validation tasks, and the rule keeps it or drops it; either way a row goes to the ledger. From development tasks the improver gets failed checks, sample runs and traces. From validation tasks it gets only the decision and its reasons. Test tasks send nothing back and are scored once after the last round.

Look at the arrows that return to the improver. Development tasks return the failures of the current harness in full: failed checks, sample replies and traces, the records of what the harness did at each point. Validation returns the decision and its reasons, such as the size of the gain and the number of tasks that got better or worse. Test tasks return nothing. The less the improver learns from a set of tasks, the more that set’s score says about tasks nobody has seen.

Setting up and running a campaign takes seven steps, which the next sections follow in order. The first four fix the model, splits, limits and adoption rule before the first proposal, and the last three run the loop, score the test tasks once and review the changes.

Step 1: hold the model and the evaluator fixed

If the model, its reasoning budget or the checks change between proposals, you cannot tell whether a score moved because of the edit or because the experiment itself changed. Everything outside the harness stays fixed from the first candidate to the last: the model and its settings, the tasks, the checks, and the improver itself.

Fix two measures as well, because the rest of the article uses them. Success is each task’s share of passed runs, averaged over tasks; a run passes only when every check passes. Critical violations, such as an unauthorized or duplicate refund, are counted separately, because one of them matters even when the average is high.

The steps below take their small examples from an online-shop support assistant that issues refunds and changes account settings. The first worked example describes it in full.

Step 2: split the tasks three ways

An automated loop makes many more keep-or-drop decisions than an engineer reviewing one pull request, and every decision risks fitting the harness to the tasks that judge it. Optimized prompts show how large this effect is: in one study they scored 5.8 to 13.2 points lower on a test set than on the validation set that selected them.

So each set gets one job:

SetIts job, and what the improver gets from it
DevelopmentDiagnosis. The improver reads every failed run in full.
ValidationSelection. The rule decides on these tasks, and the improver gets only the decision and its reasons.
TestThe final measurement, once, after the last round. The improver gets nothing.

Tasks that already shaped your harness belong in development, because they can no longer act as unseen checks. Validation and test tasks should be new, and should mix the same kinds of request in the same proportions.

Why three sets, and when two are enough

For tuning a few settings, two sets are the standard answer: choose on one, report on the other. Whether two are enough for a loop depends on how much the improver can read and how freely it can write.

Test tasks are always needed. Whatever chose the final harness, you measure it on tasks that played no part in the choice. One question remains: may the tasks that the improver reads also decide what is kept?

They may when the thing being chosen is small. A sweep over a retrieval cutoff reads one score for each setting. One number cannot hold the details of a task. An engineer who compares two designs written by hand, or reviews one patch line by line, is in the same position: the change is too small to be fitted to the tasks, and a person reads the result. Choose on the development tasks, then measure the chosen version once on the test tasks.

With a coding agent in a loop, the weights are fixed, but the code is still fitted to the examples. The agent reads each request and its trace in full, and it can write any code. An agent that reads a complaint about a damaged blanket can add a special case for blankets, or copy the customer’s wording into the prompt. On the development tasks, such a shortcut scores as well as a real repair, because it was written from those tasks. Validation tasks ask the question that development tasks cannot answer: does the change also help on requests the improver could not read?

Validation tasks do not replace test tasks. The improver learns the decision and its reasons after every round, and its next proposal takes them into account. Over many rounds the search fits the validation tasks too, more slowly. That is the gap the study above measured.

What is chosen, and from whatSets
A few numeric settings, such as a retrieval cutoff, chosen from scores onlyDevelopment and test
One of a few designs or patches that an engineer wrote, chosen by reading failures and scoresDevelopment and test
Code and prompts that an agent writes over many rounds, from full requests and traces, with no human reviewDevelopment, validation and test

An online experiment can take the place of the test set. If you choose offline and then compare the chosen harness with the current one on new production traffic, that comparison is your final measurement, as long as its results did not influence the choice.

A first loop can also run on two sets and select on the development tasks. The test score at the end is still a measurement on tasks that chose nothing. What you lose is the check during the search: a shortcut is kept, later candidates build on it, and you find out once, at the end.

The third set has a cost: every task you hide is one that the improver cannot learn from.

Step 3: limit what the improver can read and change

If the improver can read the validation tasks, it can write rules for them. If it can edit the checks, it can pass without solving the task. In the Darwin Gödel Machine, an agent that was asked to stop inventing tool calls reached a perfect score by removing the log entries that the detector looked for. The detector itself was hidden from it, and it had been told to leave those entries alone.

Instructions not to cheat are a weak defense. On one task that OpenAI’s o3 tended to cheat on, METR found that it planned to cheat in 80% of runs under the original prompt and in 70% to 95% under four prompts that discouraged it. Hiding the checks works better, but it has a cost: in ImpossibleBench, cheating fell to near zero once the model could not see the tests, and its honest results got somewhat worse too. So build the limit into the improver’s workspace, and give it good feedback in exchange.

Two areas. Inside the improver's temporary directory: the brief with its rules, the failing development tasks with failed checks and sample runs, every development run in full, the history of earlier candidates and decisions, reference material with the shop policy and the environment's API, and a copy of the current harness. Outside it: validation tasks and their runs, test tasks, the checks' code, the ledger, and the model and its settings. The improver has file tools only and no tool that runs commands; a read outside the directory is refused and logged. Only the harness copy leaves the directory, as the candidate.Two areas. Inside the improver's temporary directory: the brief with its rules, the failing development tasks with failed checks and sample runs, every development run in full, the history of earlier candidates and decisions, reference material with the shop policy and the environment's API, and a copy of the current harness. Outside it: validation tasks and their runs, test tasks, the checks' code, the ledger, and the model and its settings. The improver has file tools only and no tool that runs commands; a read outside the directory is refused and logged. Only the harness copy leaves the directory, as the candidate.

The figure shows one way to do it. The improver works in a temporary directory that holds what it may see and nothing else. Three controls apply in each round:

  1. Confined tools. The improver can read, search and edit files in that directory. It cannot leave it, and it has no tool that runs commands.
  2. Selective copy-back. Only the edited harness returns to the loop, with a short note on what changed and why. Edits to anything else are discarded.
  3. A check before any run. A candidate is rejected if it changes nothing, repeats an earlier one, swaps the model, imports a network library, or contains text copied from a development task. Dropbox found its prompt optimizer copying keywords and whole phrases from the examples into prompts, so this last check is worth having.

These controls cover the moment of editing. When the evaluator runs a candidate later, that code needs its own sandbox, or it can open the files you hid.

Step 4: decide in advance what counts as an improvement

Two questions are easy to mix up:

  • Is this harness good enough for users? A release rule answers it with absolute requirements, such as “90% of tasks pass every run”.
  • Is this candidate a better starting point than the current harness? The loop’s adoption rule answers it by comparing the two.

A release rule asks whether a result will hold on new tasks, so it needs many tasks to agree. A round of the loop asks less: is the gain on these tasks real, and did anything break?

A loop needs the second rule because early candidates are far from any release requirement. In the first worked example, the starting workflow passes 47% of the validation runs. The first candidate reaches 66%. That is progress, and a 90% release rule would reject it.

Choose what to improve and what to hold

“Better” needs a metric. Part 3 measured every harness on three: success, cost per task and latency. A loop can improve any one of them, and the other two do not stay still by themselves. So decide before the first round what the campaign improves and what it must hold:

  • Improve success, hold cost and latency. The harness fails too often. A candidate may not make it more expensive or slower than a limit you set.
  • Improve cost or latency, hold success. The harness is good enough and too expensive or too slow. A candidate must be cheaper or faster and must not pass fewer runs.
  • Collect the frontier as well. Whatever the objective, a campaign can also report every harness for which no other harness is at least as good on all three metrics and better on one. This set is the frontier, and you can choose from it later.

The metric a campaign improves is its objective. The improver’s instructions name it, and the adoption rule tests it. The first worked example and the first part of the second use success as the objective. The second example then runs the same loop on cost and on latency.

Why a higher score is not enough

A rule that keeps whatever scores higher is wrong in three ways:

  • Noise. Language models give different answers on repeated runs, so the same harness scores differently each time.
  • Picking the winner. The best of several noisy scores is too high on average. If ten candidates are all equally good, the best-looking one is expected to score about 1.5 standard errors above its true value (Smith and Winkler).
  • Averages. A higher average can hide tasks that got worse.

The figure shows the third case with made-up numbers. All three candidates raise the average by the same amount.

An illustration with 32 validation tasks and three runs each. Candidate A: 4 tasks go from 0 to 3 passed runs, the rest are unchanged; kept, the tasks are fixed in every run. Candidate B: 8 tasks go from 0 to 3 and 4 go from 3 to 0; dropped, four tasks are broken. Candidate C: 12 tasks each gain one passed run and none gets worse; kept, a broad gain. All three gain 12.5 points on average.An illustration with 32 validation tasks and three runs each. Candidate A: 4 tasks go from 0 to 3 passed runs, the rest are unchanged; kept, the tasks are fixed in every run. Candidate B: 8 tasks go from 0 to 3 and 4 go from 3 to 0; dropped, four tasks are broken. Candidate C: 12 tasks each gain one passed run and none gets worse; kept, a broad gain. All three gain 12.5 points on average.

An adoption rule you can use

Compare the candidate with the current harness on the same validation tasks, run by run. With success as the objective, keep it only if all three conditions hold:

  1. Nothing that worked is broken. No new critical violation, no release requirement that the current harness meets and the candidate misses, and no task that passed every run and now fails every run. Candidate B fails here.
  2. The gain is larger than the noise between runs. The next subsection shows how to test this. Candidates A and C pass.
  3. The other metrics hold. Set a limit on how much each metric that is not the objective may get worse. A limit can be, for example, at most 1,000 more tokens per task.

How to tell a gain from run noise

The same harness gives different results when you run it again. So a candidate can pass more runs than the current harness without being better. The rule asks one question: how often would a gain this large appear if the edit changed nothing?

Start with one task. It ran three times with the current harness and failed every time. It ran three times with the candidate and passed every time. Together that is six runs: three fails and three passes.

Now suppose the edit changed nothing. Then the candidate is the same harness as the current one, and these are six runs of one harness. Three of the six passed. With one harness, nothing ties those three passes to the candidate’s runs. They could have fallen on any three of the six.

Number the runs: 1, 2 and 3 were made with the current harness, and 4, 5 and 6 with the candidate. The three passes could have fallen on runs 1, 2 and 3, or on runs 1, 2 and 4, and so on:

123 124 125 126 134 135 136 145 146 156 234 235 236 245 246 256 345 346 356 456

That is 20 possibilities. They are equally likely under one assumption: the six runs are independent and made under the same conditions, so that nothing except the harness distinguishes run 4 from run 1. The result we measured is the last one, 456: all three passes on the candidate’s runs. So if the edit changed nothing, we would see this result in 1 case of 20. That is rare enough to conclude that the edit did change something.

The assumption fails when the two sets of runs differ in something other than the harness, such as the model version, a warm cache or data left by an earlier run. Step 1 exists to rule that out.

One task has six runs: runs 1, 2 and 3 with the current harness, which all failed, and runs 4, 5 and 6 with the candidate, which all passed. If both are the same harness, the three passes could have fallen on any three of the six runs. The figure draws all 20 possibilities as rows of six squares with three filled. In only one of them are all three passes on the candidate's runs, and that one is the measured result.One task has six runs: runs 1, 2 and 3 with the current harness, which all failed, and runs 4, 5 and 6 with the candidate, which all passed. If both are the same harness, the three passes could have fallen on any three of the six runs. The figure draws all 20 possibilities as rows of six squares with three filled. In only one of them are all three passes on the candidate's runs, and that one is the measured result.

A weaker result gives a different count. Take a task that passed two runs of three before and passes all three now, so that its six runs hold five passes and one fail. With one harness, the single fail could have fallen on any of the six runs. In three cases of six it falls on a run of the current harness, which is what we measured. That happens half of the time, so this task is no evidence.

The rule does the same count for all tasks together. This is a permutation test: it goes through every way to relabel the runs inside each task, and it counts how often the candidate ends up with at least as many passed runs as it really has. Keep the candidate only if that happens in at most 5% of cases.

For Candidate A, four tasks went from three fails to three passes. One such task appears by chance in 1 case of 20, and four of them together in 1 case of 160,000, so that gain is not noise. Many small gains add up in the same way. Candidate C’s twelve tasks each gained one run, and chance gives all twelve gains in about 1 case of 4,000.

The first condition uses the same count in the other direction. A task that passed every run and now fails every run is a loss that chance gives in 1 case of 20, so the rule calls it broken. A task that lost one run of three is not broken: chance does that half of the time.

This rule needs tasks with stable results. If many tasks pass about half of their runs, three runs cannot separate a loss from noise, and the remedy is more runs for each task.

A noise check finds that out before the first round. Run the starting harness on the validation tasks twice and give both sets of runs to the rule. They come from the same code, so the answer must be “not enough evidence”. If the rule keeps or rejects one of them, it is too easy to satisfy on these tasks.

Other tests look at whole tasks and not at single runs. They count how many tasks got better and how many got worse. The sign test and the Wilcoxon signed-rank test work this way, and Demšar (2006) compares them. They ask whether the change will help on new tasks, and they need about six changed tasks before they can say yes, so they would drop Candidate A. Use such a test for a release decision. A round of the loop asks only whether the gain on these tasks is real.

When the objective is cost or latency

The same rule works with the roles exchanged. Success becomes a metric to hold, and the objective takes its place in the second condition:

  1. Nothing that worked is broken, as before.
  2. Success holds. The lower end of the interval of the difference in success must stay above a margin you accept, for example −2 points.
  3. The objective is lower by more than chance. The whole interval of the difference in cost, or in latency, must lie below zero. To get the interval, draw the tasks at random with replacement, compute the difference, and repeat a few thousand times; the interval is the middle 95% of these differences.

Cost per task changes between two runs of the same harness, because the model writes answers of different length. So run the noise check with the objective you chose: the starting harness against a second run of itself must not count as cheaper. Latency also depends on when you measure it. Run the current harness and the candidate at about the same time, or you compare the load on the provider at two different hours.

Before you start the loop

Two more decisions belong here, before any result can influence them:

  • Screen cheaply. Score a candidate on the development tasks first, and send it to validation only if it beats the current harness there. Each use of the validation set makes it a little less independent.
  • Set the budget and the stop. For example: at most eight candidates, a spending limit, and a stop after three drops in a row. With success as the objective, also stop when no development task fails. Do not stop because a validation score peaked; that is picking the winner again.

Step 5: run the loop with feedback the improver can act on

A small script runs each round. It gives the improver a copy of the current harness and its development failures, checks the candidate that comes back, scores it on the development tasks and, if it improved there, on the validation tasks. It applies the adoption rule, writes the ledger row and starts the next round.

How useful the candidates are depends on what the improver reads. Here is one failing development task from the support assistant:

A customer asks to turn off marketing emails and to refund a blanket. The reply confirms only the refund. With a score, 0 of 2 runs passed, the improver can conclude only that something is wrong. With the failed checks, the database was not updated and the reply omits the emails, it can conclude that the second request was lost. With the trace, kind refund and settings marketing emails off, it can conclude that the model understood both requests and the code read only the kind.A customer asks to turn off marketing emails and to refund a blanket. The reply confirms only the refund. With a score, 0 of 2 runs passed, the improver can conclude only that something is wrong. With the failed checks, the database was not updated and the reply omits the emails, it can conclude that the second request was lost. With the trace, kind refund and settings marketing emails off, it can conclude that the model understood both requests and the code read only the kind.

Each row tells the improver more about the same failure. Only the trace separates “the model misread the message” from “the model read it correctly and the code ignored half of it”, and those need different fixes.

The whole-harness optimizer Meta-Harness measured this difference on a text-classification task (Table 3). When the improver saw code and scores, the median candidate reached 34.6% accuracy, whereas adding run summaries gave 34.9% and giving it the raw traces reached 50.0%.

These practices help:

  • Show the failures of the current harness in full, with inputs, failed checks and traces.
  • Show what happened to dropped candidates too, including their failed development runs. The second worked example below shows what happens without this.
  • Describe the environment: which operations are allowed, which are blocked, what the policy says. Otherwise the improver uses a candidate to find out.
  • Ask for one change with one reason. A candidate with a single idea can be understood, and its effect can be attributed.

Do not ask the improver to predict what its change will break. In one study, an agent that edits a coding agent’s harness predicted the tasks its edits would fix about five times better than chance, and the tasks they would break only twice as well. That is why the evaluator and the rule are separate parts.

Step 6: stop, then score the test tasks once

When the loop stops, its validation score is too high, because the final harness was chosen for it. Score the test tasks now, once, for the starting harness and the final one, and report that difference. If the campaign collects a frontier, score every harness in that set, because a person will choose among them.

If you look at the test score, change something and run again, the test set has become a validation set, and you need new tasks for the next measurement.

Report the cost next to the gain. In the first example, the evaluation cost more than three times as much as the improver.

Step 7: read the changes before you use them

A kept candidate is a proposal that passed your checks. Read it as you would read a colleague’s pull request, and ask:

  • Does it solve the problem or the tasks? Look for names, phrases and special cases that come from the development tasks.
  • Which kinds of request got worse? Break the scores down by kind.
  • Does it still hold after a model change? The harness was tuned with one model. Measure the old and the new harness again when the model changes.

Read the dropped candidates as well. They show whether the improver had no more useful ideas, or proposed changes whose gain your runs could not separate from noise.

Expect to reject some of what a loop keeps. In a Google report on speeding up its Agent Development Kit, an agent proposed six optimizations in an unattended run, and two of them shipped after the maintainer’s review.

Worked example 1: six fixes, three kept

This campaign ran the seven steps on the online-shop support assistant from Part 1 and Part 2. It issues refunds, changes addresses and account settings, and must hold any refund above $200 until a supervisor decides. The loop starts from its simplest design, a workflow with no agent: one model call reads the customer’s message into fields such as the kind of request and the amount, and ordinary code looks up the order, applies the shop’s rules and writes the reply.

The setup, step by step:

  • Fixed (step 1). The model in the harness is OpenAI gpt-6.2-sol with low reasoning effort. The checks read the shop’s database after the run, the refunds that were issued, and the facts the reply must contain. The improver is the same model with medium reasoning effort. It starts fresh in each round and knows about earlier rounds only what the loop gives it.
  • Tasks (step 2). Three sets: development, validation and test. Two would not be enough here. The improver reads every failed development run in full and can write any code, so it could fit a change to the tasks it read. The validation tasks check each change on tasks it did not read, and no person reviews a change before the rule decides.
  • Limits (step 3). The improver worked in a directory with the workflow, the failed development runs and the shop’s policy. The check before any run rejected none of its six candidates.
  • Rule (step 4). Success is the objective. A candidate may add at most 1,000 tokens per task to the roughly 480 the workflow starts with. The loop stops after three drops in a row.

The 112 tasks are split across the three sets as follows:

SetTasks, runs and who sees them
Development48 tasks the workflow was built and tested on, 2 runs each. The improver sees them in full.
Validation32 new tasks, 3 runs each. The evaluator sees them; the improver gets the decision.
Test32 new tasks, 3 runs each. The evaluator sees them once, after the loop stops.

The validation set and the test set each hold 8 standard requests and 6 tasks in each of four harder groups: vague requests that leave out a detail such as the order number, two requests in one message, policy questions, and unusual requests such as a password reset.

The starting workflow passes every run of the 8 standard validation requests and has no critical violations. Most of its failures have three causes: it handles one request per message, it has no path for policy questions, and it asks for an order number even when the customer named a product that appears in only one of their orders.

The next figure is the general figure of one round, filled in with the first candidate.

The round of the general figure with the first candidate from the support assistant. The improver reads a development failure: a customer asks about the refund policy and the reply asks for an email address. It returns a candidate that answers policy questions from the shop's rules. The validity check passes it. On the development tasks the share of passed runs rises from 54 to 71 percent. On the validation tasks it rises from 47 to 66 percent, with 6 tasks better and none worse. The rule keeps it, and the improver learns the decision and its reason. Candidate 1 becomes the current harness, and the ledger records the change, its scores and the reason. After six candidates the loop stops. On the test tasks the start scores 44 percent and the final harness 90 percent.The round of the general figure with the first candidate from the support assistant. The improver reads a development failure: a customer asks about the refund policy and the reply asks for an email address. It returns a candidate that answers policy questions from the shop's rules. The validity check passes it. On the development tasks the share of passed runs rises from 54 to 71 percent. On the validation tasks it rises from 47 to 66 percent, with 6 tasks better and none worse. The rule keeps it, and the improver learns the decision and its reason. Candidate 1 becomes the current harness, and the ledger records the change, its scores and the reason. After six candidates the loop stops. On the test tasks the start scores 44 percent and the final harness 90 percent.

The loop proposed six candidates and stopped after three in a row were not kept. Each kept candidate became the current harness. So candidate 2 was built from candidate 1 and compared with it, candidate 3 with candidate 2, and the last three with candidate 3:

CandidateCompared with, and the result on the validation tasks
1. Answer policy questionsThe start. 47% → 66% of runs passed. 6 tasks better, 0 worse. Kept
2. Find the order by the product nameCandidate 1. 66% → 74%. 3 better, 1 worse. Kept
3. Handle several requests in one messageCandidate 2. 74% → 92%. 6 better, 0 worse. Kept
4. Answer questions about order and refund statusCandidate 3. 92% → 94%. 2 better, 1 worse. Not kept
5. Send requests to change an email address to a colleagueCandidate 3. 92% → 82%. 1 better, 5 worse. Not kept
6. A separate check for status questionsCandidate 3. 92% → 94%. 2 better, 1 worse. Not kept

The scores by kind of request show what the three kept candidates left in the final harness:

Share of validation runs passed, by kind of request, for the start and the final harness. Standard requests, 8 tasks: 100% for both. Policy questions, 6 tasks: 0% at the start, 100% in the final harness, from candidate 1. Vague requests, 6 tasks: 50% at the start, 100% in the final harness, from candidate 2. Two requests in one message, 6 tasks: 0% at the start, 94% in the final harness, from candidate 3. Unusual requests, 6 tasks: 67% at the start, 61% in the final harness.Share of validation runs passed, by kind of request, for the start and the final harness. Standard requests, 8 tasks: 100% for both. Policy questions, 6 tasks: 0% at the start, 100% in the final harness, from candidate 1. Vague requests, 6 tasks: 50% at the start, 100% in the final harness, from candidate 2. Two requests in one message, 6 tasks: 0% at the start, 94% in the final harness, from candidate 3. Unusual requests, 6 tasks: 67% at the start, 61% in the final harness.

Each kept candidate repaired one kind of request.

  • Candidates 1 and 3 improved all six tasks of their kind and made no task worse.
  • Candidate 2 is the case that a count of tasks would drop. Three vague requests went from failing every run to passing every run, and one unusual request lost one run of three. An edit that changes nothing gives a gain this large in 2 cases of 1,000, so the rule kept it. That count is higher than for three such tasks alone because the single failed run can land on the current harness under a relabeling, offsetting a failed run on one of the vague requests.

The three others show the two ways a candidate fails.

  • Candidates 4 and 6 reached 94%, the highest validation scores of the campaign. Each improved two tasks and made one worse, and an edit that changes nothing gives a gain that large in 32 cases of 100. The rule treats it as noise.
  • Candidate 5 broke a task that had passed every run, and four more tasks lost runs. The first condition rejects it.

Candidates 4 and 6 show why the loop does not keep the highest score. A harness chosen for its score on 32 tasks is partly chosen for its luck on them.

On the 32 test tasks, the share of passed runs rose from 44% to 90%, a gain of 46 points with an interval from 29 to 63. Fifteen tasks got better and none got worse. Policy questions went from 0% to 94%, which is 17 of 18 runs, messages with two requests from 0% to 100% and vague requests from 50% to 100%. Standard and unusual requests did not change.

The gain has two limits. The final harness passes all three runs on 88% of the test tasks. The release rule asks for 90%, so this harness is a better starting point and not yet one to release. It also uses more of the model: 948 tokens per task against 477, which is inside the limit, and $0.0023 per task against $0.0012. The campaign itself cost $4.01: $0.88 for the improver’s six proposals and $3.13 for the evaluation.

Worked example 2: one fault behind many failures

The first example had several separate causes of failure. This harness has one. It turns a question such as “How many orders are still pending?” into one SQL query on a simulated shop database. A check compares the rows it returns with the rows of a reference query.

The database has one property that is common in real ones: the stored values differ from everyday words. A pending order is stored as pending_payment, a delivered one as delivered_complete, the Netherlands as NLD. The starting harness shows the model the table definitions, without the stored values. So the model writes a valid query with a wrong word in it. Asked for pending orders, it wrote:

SELECT COUNT(*) AS pending_orders
FROM orders
WHERE status = 'pending';

The database runs this query without an error and returns 0. The correct answer was 22. The harness may run read-only queries to look the values up, but at the start it does not use this.

The setup follows the first example: the same model for the harness and the improver, the same limits on the improver, and the same adoption rule. There are 24 development, 36 validation and 36 test questions, and each runs three times.

Two campaigns, two fixes

A campaign depends on chance: the improver may propose a different change each time. So I ran the loop twice from the same starting harness.

  • The first campaign kept its second candidate. The first one tried to list the stored values with a database function that the sandbox blocks. Every development run failed, and the candidate was dropped before validation. The second one drafts the query, checks whether its words exist in the database, and asks the model again only if one does not. Validation rose from 77% to 98% with 9 questions better and none worse, and test from 58% to 90%. The campaign cost $1.16.
  • The second campaign kept its first candidate. It collects the short text values with one ordinary query and puts them in the prompt. Validation rose from 77% to 100%, again with 9 questions better and none worse, and test from 58% to 100%. The campaign cost $1.09.

Both campaigns stopped because no development task failed any more. They found the same cause and repaired it in two different ways, with different results. One campaign is one sample of what a loop can do, so run more than one before you judge it.

The first campaign’s harness passed 98% of the validation runs and 90% of the test runs. Report the 90%, as step 6 says: the harness was selected on the validation questions.

Does feedback change what the improver finds? A control

Step 5 claims that the candidates depend on what the improver reads. A control tests a claim like this: run the same loop and take one thing away. Here that thing is the feedback, which is everything the loop returns to the improver after a round: the failed development runs with their failed checks and traces, and the decision and its reasons for every earlier candidate.

In two more campaigns the improver got the harness, its instructions, the reference material and its own earlier notes. It got no failed runs, no scores and no stated decisions. It could still see that the harness had not changed. The figure shows what the improver tried in all four campaigns.

What the improver tried in each SQL campaign. First campaign: candidate 1 listed stored values with a blocked function and was dropped; candidate 2 checked the query's words after drafting it and was kept, 90% on test. Second campaign: candidate 1 listed stored values and was kept, 100% on test. Control 1: candidate 1 listed stored values with a blocked function; candidates 2 and 3 added prompt advice on joins and totals, then on dates and NULLs; none kept. Control 2: candidate 1 listed stored values with a blocked function; candidate 2 repaired queries that do not compile; candidate 3 added prompt advice on joins and columns; none kept.What the improver tried in each SQL campaign. First campaign: candidate 1 listed stored values with a blocked function and was dropped; candidate 2 checked the query's words after drafting it and was kept, 90% on test. Second campaign: candidate 1 listed stored values and was kept, 100% on test. Control 1: candidate 1 listed stored values with a blocked function; candidates 2 and 3 added prompt advice on joins and totals, then on dates and NULLs; none kept. Control 2: candidate 1 listed stored values with a blocked function; candidate 2 repaired queries that do not compile; candidate 3 added prompt advice on joins and columns; none kept.

Both controls began with the right idea: show the model the stored values. Both used the blocked function, as the first campaign had, and lost that candidate.

  • The first campaign saw that every development run had failed, and that the current harness still failed on guessed words. It kept the idea and changed the method.
  • Both controls saw only that their change was gone, and an instruction not to repeat dropped changes. They switched to general SQL advice. They tried six candidates in all and kept none, so test success stayed at 58%. The two controls cost $0.91 and $1.18.

In these campaigns the feedback mattered less for finding the idea than for returning to it after a failed attempt. Two campaigns against two is a small sample. The practical lesson does not depend on it: tell the improver what the environment blocks, and show it the failed runs of the candidate it has just lost.

The same loop with a cost objective and a latency objective

The second campaign ended with a harness that passes every test run. It also costs the most: the stored values make each prompt longer, 650 tokens per question against 414 at the start. So I ran two more campaigns that start from that harness. One has cost per question as its objective and one has the latency of the slowest 5% of runs (p95). Both must hold success.

The cost campaign kept seven of eight candidates. Each one shortened the prompt in a different place: a shorter instruction, a schema without repeated keywords and spaces, shorter hints for the stored values. One candidate was dropped on the development tasks because it was not cheaper there. On the test questions, success stayed at 100% of 108 runs. The cost of one question fell from $0.00186 to $0.00137 and the prompt from 650 to 447 tokens.

The latency campaign kept none of three. The noise check explains why. Two runs of the same harness gave a difference in p95 latency with an interval from −0.37 to +0.07 seconds. The three candidates asked the model for shorter queries or gave it more values in advance, and none moved latency by more than that. With 36 questions and one model call for each, this loop cannot confirm a latency change of a few tenths of a second. A change that removes a model call would be large enough to confirm.

Both new campaigns also collected a frontier, so each scored on test every harness that reached its validation frontier, including candidates that the rule did not keep. Those extra points are two earlier candidates from the cost campaign ($0.00139 and $0.00145, shown unlabeled) and candidates 1 and 3 from the latency campaign (“latency 1” and “latency 3”; candidate 2 did not reach the validation frontier and was not scored on test). With the start and the two harnesses kept earlier, that gives eight harnesses with test scores, placed below by success and cost.

Eight SQL harnesses on the 36 test questions, placed by the share of test runs passed and the cost per question. The start passes 58% at $0.00130. The harness of the first campaign passes 90% at $0.00151. The harness of the second campaign passes 100% at $0.00186. The cost campaign starts from that harness and ends at 100% and $0.00137, 26% cheaper with success held; two of its other candidates lie at $0.00139 and $0.00145. Two candidates of the latency campaign pass 100% at $0.00177 and $0.00193. On these two metrics the frontier holds two harnesses: the start and the final harness of the cost campaign.Eight SQL harnesses on the 36 test questions, placed by the share of test runs passed and the cost per question. The start passes 58% at $0.00130. The harness of the first campaign passes 90% at $0.00151. The harness of the second campaign passes 100% at $0.00186. The cost campaign starts from that harness and ends at 100% and $0.00137, 26% cheaper with success held; two of its other candidates lie at $0.00139 and $0.00145. Two candidates of the latency campaign pass 100% at $0.00177 and $0.00193. On these two metrics the frontier holds two harnesses: the start and the final harness of the cost campaign.

On success and cost, two harnesses are on the frontier: the start, which is the cheapest, and the final harness of the cost campaign. That harness passes more runs than the first campaign’s harness at a lower cost, and it costs less than the second campaign’s harness at the same success. The first candidate of the latency campaign (“latency 1”, at $0.00177) was faster on p95 than both, by less than the measured noise.

Read the result with two cautions. The cost campaign made seven decisions in a row on the same 36 validation questions, and each prompt was shortened for one model. The rule also has no smallest gain: the last kept candidate saved $0.00001 per question. Set a smallest gain that is worth a review.

Limits of both examples

Both examples are small. They use synthetic data and workflows in which code, rather than an agent, chooses the steps. A model wrote the new validation and test support tasks and the SQL questions. Tests check them against the databases, but no person has reviewed the new support tasks.

The SQL results refer to 36 questions about one database whose main difficulty I built in. The cost and latency campaigns are one campaign each.

Run the examples and reuse the loop

The code behind this article is public, in three repositories:

  • harness-evals is the evaluator and the adoption rule. Use it to score your own harness and to compare two versions of it.
  • harness-loop-public is the loop: the improver’s workspace, the rounds and the ledger. It includes the SQL example.
  • agent-harness-lab-public is the support assistant with its tasks and its saved campaign.

Both examples include every saved run, so you can grade them again without an API key. The commands need uv. For the SQL example:

git clone https://github.com/slavadubrov/harness-loop-public
cd harness-loop-public
uv run harness-loop report examples.sql_desk.target:TARGET examples/sql_desk/campaigns/run-1
uv run harness-loop show - examples/sql_desk/campaigns/run-1 002

The first command grades the saved runs of the first SQL campaign and rebuilds its report. The second prints candidate 002, the one this campaign kept: the decision, the improver’s note and the diff. For the support example:

git clone https://github.com/slavadubrov/agent-harness-lab-public
cd agent-harness-lab-public
make loop-regrade

This prints the scores of every candidate, the decisions and the development tasks that still fail.

To run the loop on your own harness, you give the library your tasks in three sets with their checks, the directory that holds the starting harness, and a function that runs a harness directory on a list of tasks. You also supply instructions for the improver and a check that rejects any candidate that changes what must stay fixed. The README of harness-loop-public shows this in about twenty lines. The improver can be any program that edits a directory, so you can use the coding agent you already have. The library confines only its built-in improvers, so confine your own.

What goes wrong in a closed loop

The examples show some of the ways a loop fails. The table adds failures from published work, with the part of the setup that guards against each.

Failure, and where it was seenWhat guards against it
The harness fits the tasks it was searched on. Wang, Zhu and colleagues found no average gain on 34 separate test tasksSeparate validation and test tasks (steps 2 and 6)
Answers from the tasks end up in the harness. Seen at DropboxA check for copied text before any run; reading the change
The candidate passes the check without solving the task. The Darwin Gödel Machine removed the log that revealed the faultChecks and logs the improver cannot reach (step 3)
Noise is kept as progress. For Gideoni and colleagues, an evolved design tied with random search once scores were measured againPaired comparison, repeated runs, a noise check (step 4)
The highest score is not the best harness. Worked example 1, candidates 4 and 6The rule decides, not the score; a stop that does not depend on a validation peak (step 4)
The improver cannot see why it failed. Worked example 2Failed runs of dropped candidates, documented limits (step 5)
The gain costs more than it is worth. The RRSI method (regularized recursive self-improvement) accepts a costlier candidate only for a larger gainA limit on cost, tokens or latency in the rule (step 4)

When a closed loop is worth building

A loop is worth its cost when these are true:

  • You trust the checks. The loop finds every weakness in them. If you would not let the score decide on your own change, do not let it decide on a program’s.
  • A run is cheap and has no real side effects. The harness can work on a copy of the database, without sending real refunds.
  • The harness will be in use long enough to justify the cost of the setup.

Use something simpler when they are not. With a few failures, read the traces and fix them yourself. If only a person can judge the quality, use the assisted form: an agent drafts and a person decides. If only the prompt is wrong, a prompt optimizer such as GEPA edits less and is easier to review.

Before you trust a loop, compare it with something cheaper at the same budget:

  • Run the unchanged harness several times and pick among its answers. Wang, Zhu and colleagues did this on Terminal-Bench 2.1. Where neither method could check its answers with unit tests, it reached 72.3%, against 67.4% for a loop that changed the harness.
  • Try every setting with a script. When the change is a few settings, a plain search is enough. In an experiment on a memory tool, a script tried all 384 configurations in under a second and found the setting that an LLM had proposed.
  • Give the failed runs to an engineer. A person who reads the failed SQL queries of the second example may find the same fix in minutes.

From a closed loop to a recursive one

The loop in this article is not recursive. It improves the support workflow and the SQL assistant. It does not improve itself: the improver, its instructions, the checks and the rule stay as I wrote them. After a kept change, the next step starts from a better harness, but the way changes are proposed and judged is the same. One question separates the two cases: after a change is kept, has the improver itself changed, or the way changes are measured and selected? New failures and a longer history do not count. They are new inputs to the same improver.

After the kept change in the SQL example, the next assistant looked up stored values before it answered. The next improver had the same instructions and the same rule as before. Now take a different change: the improver learns to group failed runs by the first point where the recorded state differs from the expected one. If that change is kept, the next campaign starts with a better way to diagnose failures, also on a harness that has nothing to do with SQL. That is a claim about the improver, and it needs its own experiment.

Published loops differ in how wide a part they may edit. The widest case is the improver itself:

Five kinds of editable part in order: a prompt (GEPA); a playbook of notes kept in context (ACE); code around tools, checks and fixes at tool calls (Beyond Prompts); the whole harness with prompts, tools and control flow (Meta-Harness), marked as this article's case; and the improver itself, the part that writes changes (Hyperagents), marked as recursive. Each step lets a change fix more, and break or game more.Five kinds of editable part in order: a prompt (GEPA); a playbook of notes kept in context (ACE); code around tools, checks and fixes at tool calls (Beyond Prompts); the whole harness with prompts, tools and control flow (Meta-Harness), marked as this article's case; and the improver itself, the part that writes changes (Hyperagents), marked as recursive. Each step lets a change fix more, and break or game more.

Each example in the figure widens what a round may touch. GEPA rewrites only the prompt instructions, and ACE (Agentic Context Engineering) maintains a playbook of notes kept in context instead of changing code. Beyond Prompts limits code edits to checks and fixes at tool calls, while Meta-Harness edits the whole harness (prompts, tools and control flow), which is the scope of this article. Only the rightmost step, Hyperagents, lets the loop rewrite the improver itself.

Between a fixed loop and a loop that edits its own improver lie smaller steps that keep experience from one campaign for the next: a library of fixes that worked, or instructions for the improver that are rewritten after each campaign. These change the improver, so they need an evaluation of their own. Give the old and the new improver the same unseen tasks and the same budget, and compare how much each one gains.

Hyperagents ran such a test. An improver taken from other domains made faster progress early in a new one. In a longer run, its final lead over a fresh start was not statistically significant. Whether improvement can make later improvement faster is still open.

Where to start

You can build a first version in this order. Each stage is useful even if you stop there:

  1. Check your rule on noise. Run your current harness twice and see whether you would have called the second run an improvement.
  2. Group your failures by cause. A loop repairs causes that several tasks share, so start where you see such a group.
  3. Run the assisted form. Give an agent the failed runs and let it draft one change. You decide. Its drafts tell you whether the feedback is good enough.
  4. Close the loop on one harness, with a small budget, a confined workspace and the adoption rule.
  5. Add a control. Run the same loop without feedback, or a simpler method at the same cost, and compare the results on the test tasks.