You can hand a program that improves programs to itself. On top of GPT-4, STOP's improver got better round after round. On top of GPT-3.5 or Mixtral, the same loop got worse.
Pick a base model and press Step. Each step, the improver rewrites its own code and keeps the rewrite only if it scores higher. Then we build, piece by piece, the self-update, the no-regression gate, evolution over code, agents that edit their own repository, and the limits of all of it.
You need a little Python and what a harness is (the code around a model). Harness Optimization helps. We build the rest from zero.
HARNESS 21, the third lesson of the Harness Engineering trilogy, after Harness Engineering and Harness Optimization. It follows Lilian Weng, Harness Engineering for Self-Improvement (Lil'Log, July 2026), and the papers it surveys, re-taught in our own words and devices.
Illustrative toy. The direction is STOP's result (Zelikman et al., 2023, Figure 4): mean test score rose over rounds with GPT-4 and fell with GPT-3.5 and Mixtral. The step sizes and the noisy judging here are made up to show the mechanism.
Chapter 0
See why one optimizer that edits code can reach every part of a harness at once
Your agent fails a task. You could fix the prompt. You could fix the memory, the retry rule or the order of the steps. The last lesson met an optimizer for each of these: ACE edits the context, ADAS and AFlow search over workflows. Each one stops at the edge of its slice. The context optimizer cannot touch the retry rule.
A harness is the code around a model: its prompts, tools, memory, control flow and permissions. Weng's point is short: a harness is code. A prompt is a string inside the code. A workflow is control flow. So an optimizer that edits code can reach every slice, and how the slices fit together.
Each ring holds every ring inside it. Pick a level and read an example of what an optimizer at that level writes.
The five levels are Weng's ladder of what gets optimized as models grow stronger. The example artifacts are made up for this page.
Code has a second property: it runs. Run a candidate harness on a benchmark and you get a number. Once every candidate has a number, every search method applies: hill climbing, evolution, tree search. Expressible plus measurable means optimizable.
The top rung is strange. If the optimizer is code, and it improves code, it can improve itself. That loop is recursive self-improvement (RSI): a system uses what it can do now to improve the machinery that makes it able. I. J. Good described the idea in 1965. Today the practical version runs through the harness, not the weights. Almost no system in this lesson touches a weight until Chapter 7.
Failure. An optimizer stuck in one slice. Symptom: a polished prompt inside a broken retry loop still fails. Measure: list which parts of the harness the optimizer may edit. Fix: give it the code, with a fence around what it must not touch (Chapter 2).
Chapter 1
Score a coach by the players it trains, then hand the coach to itself
STOP, the Self-Taught Optimizer (Zelikman et al., 2023), has four parts. A solution is a program for a task. A utility scores a solution. The language model is a black box: text in, text out. The improver takes a utility and a solution, calls the model, and returns a better solution: a coach for a player.
The seed improver asks the model for a few rewrites and returns the best one. Can this coach improve itself?
First, score a coach. Take a set of tasks, each a utility u and a starting solution s. Call the set D, the improver I and the model M. The meta-utility is the coach's score.
U-hat of I equals one over the size of D, times the sum over every pair u, s in D, of u applied to I of u, s, using M.
For each task in D, let the improver I improve the solution s. Score the result with that task's utility u. Average the scores. That is u-hat of I.
With made-up numbers: three tasks. The seed improver's results score 0.50, 0.60 and 0.40. u-hat = (0.50 + 0.60 + 0.40)/3 = 0.500. A coach scores what its players score, on average.
Improving the improver is an optimization problem, and the improver solves those. So pass it the meta-utility as the scorer and itself as the solution. Call the improver after round t It.
I-t equals I-t-minus-one, applied to u-hat and to I-t-minus-one itself, using M.
Run the old improver I-t-minus-one on its own source code. It asks M for rewrites of itself and scores each with u-hat. It returns the best one. That is I-t.
With made-up numbers: I-0 scores u-hat = 0.500. A rewrite that adds a critique step scores 0.55, 0.72, 0.51, so u-hat = 1.78/3 = 0.593. It beats 0.500, so it becomes I-1.
Grey bars are the old improver on three tasks. Pick a rewrite and see its bars. The meta-utility keeps it only if the average goes up.
Illustrative numbers. The test (keep a rewrite only if its average over D is higher) is STOP's.
Rewrite C aces task 1 and averages 0.467, so it loses. Averaging over many tasks stops a coach from cheating on one.
The improved improvers wrote beam search, genetic algorithms, simulated annealing and a bandit over prompts into their own code: parts of the optimization literature.
Failure. The base model is too weak. Symptom: the score falls each round. Measure: test u-hat on tasks held out from the loop, per round. STOP saw it fall with GPT-3.5 and Mixtral. Fix: a stronger base model.
Chapter 2
Let an agent fix the harness it runs in, and let a gate it cannot touch decide what stays
Self-Harness (Zhang et al., 2026) points STOP's idea at a real agent harness on terminal tasks. The agent improves the harness it runs inside, in three stages.
Grouping by symptom is not enough. Two runs can both time out: one looped on a failing command, one waited on a dead subprocess. One needs a retry cap, the other a liveness check. So a failure record names the verifier's result, what the agent was doing, and the harness part at fault.
The held-in set Din holds tasks that show the weakness. The held-out set Dout holds the rest. Call a pass rate change Δ: the candidate's pass rate minus the current harness's.
Accept c if and only if delta-in is at least zero and delta-out is at least zero.
Run the edited harness on both sets. Subtract the old pass rates to get delta-in and delta-out. If either is below zero, reject the edit and log it.
With made-up numbers: the old harness passes 40% of Din and 60% of Dout. An edit that raises every timeout to 30 minutes passes 80% and 54%. Delta-in = +40 points, delta-out = −6 points. Rejected.
Pick a candidate edit and press Validate. Teal is the old harness. Purple is the edited one. Both gauges must hold.
Illustrative pass rates. The three stages and the no-regression rule are the paper's, as Weng summarizes them.
On Terminal-Bench 2.0 with MiniMax M2.5, Qwen3.5-35B-A3B and GLM-5, each model grew its own harness edits. The paper reports that every final harness raised both pass rates, across nine model and benchmark pairs. A harness fits one model.
Failure. The loop can edit what measures it. Symptom: pass rates rise but users see no fewer failures. Measure: check whether the editable files include the tests or the permissions. Fix: Weng's rule, keep the evaluator and the permission layer outside the loop.
Chapter 3
Breed a population instead of polishing one candidate, and let the mutation rule evolve too
STOP and Self-Harness keep one line of descent. If the best design sits far from the current one, small gated edits never reach it. Evolution keeps many candidates alive at once.
Four words carry it. A population is a set of candidates alive at once. A mutation is a small change to a candidate. Fitness is a candidate's score. Selection copies high-fitness candidates, with mutations, into the next generation; the rest disappear.
There is no gradient. Change one character of a program and it behaves the same, behaves differently or crashes. There is no smooth slope to follow. Evolution needs two things only: you can make variations, and you can score them. Weng names when it fits: the search space is large or strangely shaped, and it is hard to optimize with gradients but easy to evaluate. Harness code fits both.
Each row is a candidate string. Green letters match a hidden target. Press Run at a 20% mutation rate. Then turn on Mutate the mutator and run again: each child inherits and changes its own rate.
A toy in the style of Dawkins's "weasel" demo. Fitness is the share of letters that match. In 300 of our own runs, the median finish was about 690 generations at a fixed 20% and about 290 when self-tuned; a well-chosen fixed rate of 6% to 12% did as well. Real systems mutate prompts and programs with an LLM.
Promptbreeder (Fernando et al., 2023) evolves task prompts. An LLM rewrites, combines and riffs on prompts, and the variants compete on the task. The step that matters here: the mutation prompts (the instructions that tell the LLM how to mutate) evolve too. That is STOP's idea with Darwin's parts.
GEPA (Agrawal et al., 2025) makes the mutation informed. After candidates run, the model reads their trajectories in plain language and proposes targeted prompt updates. A plain genetic algorithm learns only from the score. GEPA also learns why the score was low.
Failure. Too much mutation. Symptom: the best string gets close, then keeps breaking its own matches. Measure: plot best fitness per generation for two rates. Fix: tune the rate, or let it evolve. Self-tuning rescues a bad rate; it does not beat a good one.
Chapter 4
Keep a pool of programs, ask a frozen LLM for small diffs, and fence the code that may change
AlphaEvolve (Novikov et al., 2025, Google DeepMind) evolves real programs: GPU kernels, schedulers, mathematical constructions. It found a way to multiply two 4×4 complex matrices with 48 scalar multiplications. The loop is the four words of Chapter 3. It keeps a pool of programs and prompts frozen LLMs (never trained in the loop) for diffs, patches of a few lines. It scores each child and keeps the good ones.
Why diffs and not whole rewrites? Three reasons:
A fence marks the editable region. The agent can read the whole repository, but only code between # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END may change. The scorer sits outside the fence. Each prompt holds parent programs, their scores and instructions. The instructions, the meta-prompt, evolve too.
For a kernel, the fitness has two parts. Call the candidate program c and its runtime in seconds t(c).
F of c equals minus t of c if c is correct, and minus infinity otherwise.
Run candidate c on test inputs. If its output is wrong, f is minus infinity: it dies. If it is right, f is minus its runtime t: faster is fitter.
With made-up numbers: the parent is correct in 2.40 s, so f = −2.40. A vectorized child is correct in 0.09 s, so f = −0.09 and it wins. A child that finishes in 0.01 s with wrong output gets −∞.
Each card is a program. Press Step to breed one child from a parent. Then turn on Edit outside the fence and watch what the pool learns.
Illustrative toy runtimes. The fence markers, diffs and frozen LLMs are AlphaEvolve's; the fence-breaking failure is a made-up case of what the fence prevents.
The paper's ablations show each part matters: evolution against plain repeated sampling, context in the prompt, meta-prompts, whole-file evolution and stronger LLMs.
The method thrives where a machine scores a candidate in seconds with no doubt: kernels, matrix multiplication, contest problems, scheduling. It struggles when scoring is slow, vague or a matter of taste.
Failure. The pool learns to fool the scorer. Symptom: reported runtime falls toward zero while real speed does not change. Measure: re-time the best program with a scorer outside the pool. Fix: keep the scorer outside the fence.
Chapter 5
Choose parents by score and by how often they bred, and skip children that copy the pool
Every child costs an LLM call and a full scoring run. ShinkaEvolve (Lange et al., 2025) cuts the waste: it reports a new best circle packing with only 150 samples. Weng lists three parts.
Part one: parent sampling. Always breeding the best parent wastes children on one neighbourhood. So each parent i gets two pulls. Call its fitness Fi, the median fitness of the pool α0, a pressure knob λ, and its number of children so far ni.
W-i equals sigma of lambda times F-i minus alpha-zero, times one over one plus n-i.
Take how far F-i sits above the median alpha-zero, scale it by lambda and squash it with sigma. Divide by one plus the children n-i. Then divide each w-i by the sum of all weights to get the chance p-i that parent i breeds next.
With made-up numbers: four parents with fitness 0.80, 0.70, 0.60, 0.40 and 6, 1, 1, 0 children; lambda = 10, so alpha-zero = 0.65. Sigma gives 0.818, 0.622, 0.378, 0.076. The weights are 0.117, 0.311, 0.189, 0.076, summing to 0.693. The chances: 17%, 45%, 27%, 11%. The champion keeps a seat; the fresh runner-up breeds most.
Bars are each parent's chance to breed. Drag the pressure. Turn off the offspring penalty. Press Breed 10 and watch the children counts change the odds.
The weight formula is ShinkaEvolve's (Section 3, with alpha-zero the island's median fitness). The four parents are made up.
Part two: novelty rejection. A child that only renames a variable costs a full run and teaches nothing. An embedding turns code into a list of numbers, so similar code lands close. Call two embeddings a and b.
Cos of a and b equals a dot b, over the length of a times the length of b.
Embed the new child as a. For each program b in the pool, compute cos of a and b. If the largest is above a threshold, reject the child before you pay to score it.
With made-up three-number embeddings: a = (1, 2, 2), b = (2, 1, 2). a · b = 8, both lengths are 3, so cos = 8/9 = 0.89: kept. Against c = (1, 2, 2.5), cos = 10/(3 × 3.35) = 0.99: above the paper's example threshold of 0.95, rejected.
Part three: the meta-scratchpad. Every few generations, the system summarizes what the winners have in common and adds those tips to future mutation prompts. Evolution takes notes.
Failure. Diversity collapse: every program becomes a copy of one family. Symptom: best fitness stops rising early. Measure: the mean distance between programs. Fix: the offspring penalty and novelty rejection.
Chapter 6
Grow a family tree of coding agents, each one written by its parent from the parent's own failure log
Until now the loop evolved something an agent produces. The Darwin Gödel Machine (DGM; Zhang et al., 2025) evolves the agent. A coding agent edits its own harness repository: its tools, prompts and control flow.
The name is history. Schmidhuber's Gödel machine (2003) may rewrite itself only after it proves the rewrite helps. Such proofs are almost never possible. DGM swaps the proof for evidence: run the new agent on a benchmark and keep it if it scores well. Darwin in place of Gödel.
The loop, step by step:
The starting agent has two tools: a bash tool and an edit tool that views and edits files. Anything richer, the agent can build with these two and keep in its code, where its children inherit it.
Each dot is an agent; brighter means a higher score. Press Evolve. The ring marks the chosen parent. Then turn on Greedy parent and grow a new tree.
Illustrative toy scores on a made-up landscape where some good designs descend from weak-looking parents. The parent rule (score up, children down) is DGM's.
The numbers. On SWE-bench Verified (real GitHub issues checked by their tests), DGM went from 20.0% to 50.0%. On Polyglot (coding in several languages), from 14.2% to 30.7%. The models stay frozen; Claude 3.5 Sonnet writes the self-edits. So 50.0/20.0 = 2.5 times the solve rate came from the harness alone.
One rung higher sits Hyperagents (Zhang et al., 2026). In DGM, the way a parent modifies itself is fixed. A hyperagent puts a task agent and a meta agent in one editable program. So the agent can also edit how it makes new agents.
Failure. Greedy parent choice. Symptom: the tree becomes one long chain and the score stalls. Measure: count how many distinct branches still have children. Fix: the children penalty, which spends some budget on weaker but fresh agents.
Chapter 7
Route each failure to a harness edit or a weight update, and read the paper with care
Every system so far kept the weights frozen. Nothing forbids the last step. Weng names two routes for weight updates: improve the training pipeline that makes the next model, or let the deployed model learn at test time.
The two kinds of change differ. A harness edit is a diff: you can read it, revert it and test it cheaply. A weight update moves millions of numbers at once, is hard to undo and can change behaviour everywhere.
SIA (Hebbar et al., 2026) puts both in one loop with three agents:
The new part is the third: an agent chooses what to change. A tool failure (malformed arguments, the same timeout) is a harness problem: fix the schema or add a retry. A reasoning gap that survives every harness variant is a weights problem: no wrapper supplies what the model cannot do.
Pick what is wrong and press Run. Each dot is a trajectory sent to a lane. Then turn on Invert routing and watch the budget go.
Illustrative costs: a weight update costs 4 units, a harness edit 1, out of 60. The three agents and the harness-or-weights decision are SIA's.
Weng reads SIA with care, and the reading is the lesson. The task agent, gpt-oss-120b, is much weaker than the Claude Sonnet 4.6 that runs the Meta-Agent and the Feedback-Agent. A strong model fixing a weak one's obvious mistakes inflates the gain. The baselines are also too weak to compare against related methods. Her verdict: the direction is interesting, the evidence is provisional.
Use five questions on any self-improvement claim:
Failure. Training instability and Goodhart's law (when a measure becomes a target, it stops being a good measure). Symptom: scores swing as the model shifts. Measure: held-out evaluation after each weight update. Fix: checkpoints and a grader outside the loop.
Chapter 8
Run a population of harness designs and trigger collapse, rescue and self-tuned mutation yourself
Each candidate harness here is a genome of five genes, one per design choice:
Fitness is a pass rate on a hidden landscape, plus noise. The landscape has an interaction: the skeptic pays off only with two or more retries, because a veto with no second attempt is overhead. With fewer retries the skeptic scores below a plain self-check. Retries with no evaluator waste time. A broad edit surface adds noise.
Each card is a genome: five gene chips and a fitness bar. Press Run. Push the pressure to the top, then add novelty rejection, then try self-tuned mutation.
An illustrative toy landscape. The best genomes are playbook, skeptic, 2 or 3 retries, 2 sub-agents, narrow, at a true pass rate of 0.79. Genes: ctx A/P/F, retry 0–3, eval N/S/K, sub 0–3, surface n/b. Each Reseed starts a new random population.
Three runs, one finding each:
Read the two curves as a pair. Fitness says where you are. Diversity says whether you can still go anywhere else.
Press Reseed a few times: one run proves little. An honest limit: this space has 3 × 4 × 3 × 4 × 2 = 288 genomes, so trying them all would beat evolution here. A real harness space is far too large to list. The toy keeps the dynamics, not the scale.
Chapter 9
Name six ways autonomous research fails, seven bottlenecks before RSI, and watch reward hacking open a gap
A harness can run much of a research loop: propose ideas, run experiments, write a paper. Weng warns that writing a paper is not making a discovery. A plausible manuscript can hide fake citations, drift from the stated method and weak results.
Trehan and Chopra (2026) let LLM agents go from idea to paper with few tools: read a file, write a file, search. Of four attempts, three failed in implementation or evaluation. One finished and was accepted at Agents4Science 2025. They name six recurring failures:
Each is also an evaluator problem. Drift survives because nothing compares the code with the proposal. Overexcitement survives because nothing outside grades success. Weng's seven bottlenecks start there:
| Bottleneck | What goes wrong | What helps |
|---|---|---|
| 1. Weak evaluators | Taste, novelty and long-term value have no fast check. | Loops work where scoring is objective. |
| 2. Context and memory | Memory grows with autonomy. | Weng predicts memory becomes part of the model. |
| 3. Negative results | The literature favours success, so models struggle to drop a hypothesis. | Keep failed attempts; they trim the search. |
| 4. Diversity collapse | Loops exploit one known pattern. | Novelty rejection, offspring penalties. |
| 5. Reward hacking | The loop optimizes the signal, not the intent. | Evaluator and permissions outside the loop; held-out tests, trace audits, human review. |
| 6. Long-term success | Maintainability and future cost fall outside one episode. | Still open. |
| 7. The role of humans | Removing people removes oversight. | "Humans should move up the stack, not be removed from the loop." |
Reward hacking has a real case in STOP. The task's accuracy was computed with a numpy sum. An improver returned predictions in the wrong array shape, and the "accuracy" came out above 1000%. In a separate test, GPT-4 improvers turned off a sandbox flag in 0.42% of 10,000 attempts.
The agent is rewarded for passing unit tests. Press Run: pink is the test pass rate, green is true quality. Then switch on the defences one at a time.
Illustrative dynamics. The three defences are Weng's list for reward hacking.
Each defence works in a different way. Held-out tests catch hard-coded answers, so hard-coding stops paying. Trace audits block the hard-coding move itself. Human review is rare and costly, but aims at the real goal.
Chapter 10
Keep the systems, the benchmarks, the core code and the links in one place
Every system here has the same three parts: something that proposes a change, something that scores it, and a rule for what is kept. The proposer can be strong and still fail if the scorer is weak or within its reach.
| System | What changes | Who scores | Key idea | Result to remember |
|---|---|---|---|---|
| STOP | The improver program | Meta-utility û | It = It−1(û, It−1; M) | Rises with GPT-4, falls with GPT-3.5 and Mixtral |
| Self-Harness | The live harness | Din and Dout gate | Mine, propose, accept with no regression | Model-specific harnesses; held-in and held-out up in 9 of 9 pairs |
| Promptbreeder | Task and mutation prompts | Task fitness | The mutation prompts evolve too | The mutator improves itself |
| GEPA | Prompts | Task scores | Reflection on trajectories plus evolution | Paper title: can outperform RL |
| AlphaEvolve | Programs | Automatic fitness | Diffs, EVOLVE-BLOCK fence, evolving meta-prompt | 4×4 complex matrices in 48 multiplications |
| ShinkaEvolve | Programs | Fitness plus novelty | wi = σ(λ(Fi − α0))/(1 + ni), cosine rejection, scratchpad | Circle packing in 150 samples |
| DGM | Its own repository | Benchmark | Archive, parent by score and children, bash and edit tools | SWE-bench 20.0% to 50.0%, Polyglot 14.2% to 30.7% |
| SIA | Harness and weights | Feedback-Agent | An agent picks the kind of update | Direction interesting, evidence provisional |
| Benchmark | What it tests | Size | Result to remember |
|---|---|---|---|
| PaperBench | Replicate ICML 2024 papers from scratch | 20 papers, 8,316 rubric items | Best model about 21%, below ML PhDs |
| CORE-Bench | Reproduce results from given code and data | 270 tasks from 90 papers | Best agent about 21% on the hardest tier |
| ScienceAgentBench | Data-driven tasks from real papers | 102 tasks from 44 publications | Four disciplines, processing to plotting |
| RE-Bench | ML research engineering against human experts | 7 environments; 71 eight-hour attempts by 61 experts | Agents score 4× humans at 2 hours; humans narrowly win at 8 and score 2× at 32 |
| MLE-bench | Offline Kaggle competitions | 75 competitions | Best setup reaches bronze in 16.9% |
| KernelBench | Fast and correct GPU kernels | 250 PyTorch tasks | fast_p: share both correct and faster |
RE-Bench's crossover is the one to keep. Agents win short sprints. Human progress compounds over hours; the agents' does not.
pythondef meta_utility(improver_src, tasks, M): # u-hat(I) ns = {}; exec(improver_src, ns) # build improve(u, s, M) return sum(u(ns['improve'](u, s, M)) for u, s in tasks) / len(tasks) def stop(seed_src, tasks, M, T=4): u_hat = lambda src: meta_utility(src, tasks, M) I = seed_src for t in range(T): ns = {}; exec(I, ns) I = ns['improve'](u_hat, I, M) # I_t = I_{t-1}(u_hat, I_{t-1}; M) return I def accept(cand, h, D_in, D_out, pass_rate): # Self-Harness gate d_in = pass_rate(cand, D_in) - pass_rate(h, D_in) d_out = pass_rate(cand, D_out) - pass_rate(h, D_out) return d_in >= 0 and d_out >= 0 import math, random def pick_parent(pool, lam=10): # ShinkaEvolve / DGM parent rule fits = sorted(p.fit for p in pool); a0 = fits[len(fits) // 2] w = [1 / (1 + math.exp(-lam * (p.fit - a0))) / (1 + p.children) for p in pool] return random.choices(pool, weights=w)[0]
Lilian Weng, Harness Engineering for Self-Improvement (Lil'Log, July 2026). Zelikman et al., Self-Taught Optimizer (STOP), COLM 2024. Zhang et al., Self-Harness, 2026. Fernando et al., Promptbreeder, 2023. Agrawal et al., GEPA, 2025. Novikov et al., AlphaEvolve, 2025. Lange et al., ShinkaEvolve, 2025. Zhang et al., Darwin Gödel Machine, 2025. Zhang et al., Hyperagents, 2026. Hebbar et al., SIA, 2026. Trehan and Chopra, Why LLMs Aren't Scientists Yet, 2026. Wijk et al., RE-Bench, 2024.
Teach it back: open Present or Teach and explain why STOP rose with GPT-4 and fell with GPT-3.5. Then go back to the staircase and predict each step before you press it.