Build Self-Improving Harnesses

... PLUS: Turn every agent run into an inspectable trace

In today’s newsletter:

  • Build Self-Improving Harnesses With Tested Code Changes

  • Turn every agent run into an inspectable trace

Reading time: 5 minutes.

A coding agent edits a file, skips the tests, and reports that the issue is fixed. You can add another instruction telling it to test its work. You can also change the runtime so it only finishes after a successful test run.

Google researchers compared those kinds of interventions in Harnesses That Improve Themselves. With the task model frozen, they tested prompt rules, unrestricted harness rewrites, and changes to one harness module at a time.

The experiment asks a useful question for developers: how much freedom should an optimizer have to change the agent it is trying to improve?

Find the Runtime Behavior Behind the Failure

Before changing an agent, inspect how the failed run unfolded. An incorrect patch and a correct patch that was never tested need different repairs.

For an agent that stops too early, adding more reasoning instructions may leave the underlying problem untouched. The runtime still accepts the model’s decision to finish.

A completion check gives your code a separate decision to make. Has the agent changed a file? Did it test the latest edit? Did that test succeed?

The paper divides editable harness code into four areas:

  • Context and state determine which history and intermediate results reach the model.

  • Control determines when the agent continues, retries, or stops.

  • Tools determine how the agent reads and changes its environment.

  • Verification and recovery check the work and return failures for another attempt.

The divisions give the optimizer a specific place to repair a recurring behavior.

Test One Change Before Keeping It

The modular approach patches one area, executes the candidate, and checks validation performance under a token budget.

One proposed change increased the turn limit from 12 to 18. Development performance improved, but validation performance fell and token use exceeded the cap. The system rejected the change.

That is a failure you could easily miss by reviewing only the development score. More attempts might help the examples already used for debugging while making other tasks slower or less reliable.

For your own agent, a retry-loop change should therefore be tested on tasks that previously succeeded as well as tasks that failed. Otherwise, the optimizer has no reason to preserve behavior it hasn’t been asked to measure.

Compare the Extra Work With the Extra Success

The held-out results show the cost of giving the optimizer unrestricted control:

Approach

Tasks solved

Tokens per task

Original harness

5.0%

—

Prompt rules

2.5%

—

Full rewrite

42.5%

451.6K

Gated module edits

40.0%

46.7K

The full rewrite solved one more issue across the 40 held-out tasks, while using about 9.7 times as many tokens per task.

The sample is small, so the percentages are directional. But the comparison shows why a success score alone is insufficient when choosing a harness revision.

Keep the Evaluator Outside the Editable Code

A self-improving harness needs a clear boundary between changing how work gets done and changing what counts as success.

For the agent that skips testing, the optimizer could improve when tests run and how failures return to the model. The external evaluation must still establish whether the patch actually fixes the issue.

Otherwise, removing an inconvenient check can look like progress. The same problem appears when an optimizer adds rules tailored to visible benchmark examples instead of improving behavior that transfers to new tasks.

A practical implementation can record each candidate change alongside its validation results and token usage. When a revision is accepted, you can identify which behavior improved and what the improvement cost.

The rejected turn-limit increase is a useful example to retain. An automated optimizer proposed a plausible repair, and the evaluation supplied a concrete reason to keep the existing code.

Turn every agent run into an inspectable trace

An agent changes several files, runs tests, and returns a patch that doesn’t work. The conversation shows the commands it used, but trying another approach still means reconstructing the workspace at the point where the agent went wrong.

Shepherd records agent execution as a persistent trace connected to the working environment. You can inspect a run, branch from an earlier state, and compare another attempt. Workspace changes remain available for review before you apply them.

That makes the run itself something you can work with after the agent finishes.

Review the Output Before Applying It

Shepherd’s quickstart asks a Claude agent to write a small Python program. The generated file becomes a retained output, separate from the active workspace.

You can inspect or run the proposed program before deciding whether to keep it. Shepherd provides commands to select, apply, or discard the result.

For a coding task, that separates two decisions that often happen together: asking an agent to attempt a change and accepting the files it produced. A completed run can remain available for review even if you decide against applying its output.

Return to the Decision That Went Wrong

Suppose an agent investigates a failing test and concludes that the parser needs changing. Several edits later, the test still fails.

You could ask the agent to undo its changes and try again. But that asks the same conversation to reconstruct which edits belong to the failed approach and which information should carry forward.

Shepherd supports forking execution together with its environment. You can return to the recorded state before the parser edits and continue with a different approach.

The original attempt remains available for comparison. You can examine whether the alternative changed the relevant behavior, introduced a smaller patch, or simply repeated the same investigation.

Reverting a managed environment also has a boundary. An external action, such as sending a message, cannot generally be undone by restoring local files. The reversible workflow depends on which effects the runtime controls.

Give a Supervising Agent a Place to Intervene

A supervising agent needs more than the final answer if it is going to improve another agent’s work. It needs to see which actions produced the result and have a way to test an alternative.

Shepherd’s execution model supports that kind of supervision. A higher-level agent can inspect a recorded run and branch the execution to investigate another path.

In the parser example, a supervisor could notice repeated edits without a new test result. The supervisor could then try a continuation that first runs a focused test, keeping the original attempt for comparison.

The comparison would still need a success check. A different trace is only an alternative attempt until tests or another evaluator establish that the result improved.

Try the Retained-Output Workflow

Shepherd is in early alpha and requires Python 3.11 or later. Its documented platforms are macOS and Linux; Windows users should use WSL.

Install it with:

pip install shepherd-ai

The repository includes a keyless quickstart that demonstrates retained outputs without an LLM:

mkdir shepherd-quickstart
cd shepherd-quickstart
shepherd init
shepherd demo write quickstart > quickstart_demo.py
python quickstart_demo.py
shepherd run changeset --latest

The final command shows the proposed changes. Use shepherd run show --latest to inspect the recorded run.

The offline example demonstrates the review machinery. The Claude quickstart adds an actual agent that produces the proposed files. Starting there lets you see how a completed task stays inspectable before you build a supervisor that branches and compares attempts.

That’s all for today. Thank you for reading today’s edition. See you in the next issue with more AI Engineering insights.

PS: We curate this AI Engineering content for free, and your support means everything. If you find value in what you read, consider sharing it with a friend or two.

Your feedback is valuable: If there’s a topic you’re stuck on or curious about, reply to this email. We’re building this for you, and your feedback helps shape what we send.

WORK WITH US

Looking to promote your company, product, or service to 200K+ AI developers? Get in touch today by replying to this email.