Harnesses That Improve Themselves: A Unifying Framework for Self-Improving Agent Harnesses

Deep Shah, Nehal KathrotiaarXiv 2026 · arXiv

TL;DR

This paper argues that an AI agent's success depends as much on its "harness"—the runtime software managing its memory and tools—as it does on the underlying model weights. The authors propose a unifying framework for self-improving agent harnesses that autonomously diagnose execution failures and rewrite their own code, achieving an 8x performance boost on coding benchmarks while significantly reducing token costs.

What Problem Does This Paper Address?

In the world of LLM agents, we often focus on the model (e.g., GPT-4, Gemini). However, every agent operates within a harness: the stateful "glue code" that handles context compaction, tool execution in sandboxes, and multi-turn control flow.

The problem is that static harnesses are brittle. A harness tuned for one model often fails when paired with another because models differ in how they follow instructions or handle tool outputs. Manual tuning by engineers is slow and often introduces regressions. Early attempts at automation, like prompt reflection, often lead to "prompt bloat"—adding endless, contradictory rules that eventually crash the context window.

Methods

The authors introduce a dual-loop architecture to move beyond static engineering:

  1. The Inner Loop (Interactive Execution): This is the agent's runtime, consisting of four editable components: Context & State, Agent Control, Action Interface, and Verification & Recovery.
  2. The Outer Loop (Closed-Loop Self-Improvement): This meta-process inspects execution traces to (1) Diagnose failures, (2) Propose code patches, (3) Validate candidates on held-out tasks, and (4) Deploy the updated harness.
Fig. 1. Interactive execution and self-improvement loops of an agent harness. Left (Inner Loop): An agent harness mediates each turn between a frozen foundation model and a live environment across four editable components: Context and State (1), Agent Control (2), Action Interface (3, executing actions and formatting per-turn observations), and Verification and Recovery (4, triggered on stop or check signals to run tests and route repairs). Right (Outer Loop): Multi-turn trajectories and verifier logs feed a four-stage cycle that diagnoses recurring failures (Stage 1), proposes code or hook patches (Stage 2), validates runtime execution and held-out generalization (Stage 3), and deploys or routes the updated harness (Stage 4).

The core technical contribution is Modular Gated Evolution. Instead of rewriting the entire harness at once (which leads to overfitting), the system updates one module at a time. Each update must pass a "validation gate" to ensure it doesn't break existing functionality or waste excessive tokens.

To prevent the system from "cheating" or overfitting to specific tasks, the authors established four practical safeguards:

  • Modular Isolation: Evolve components independently.
  • Shrinking Edit Budgets: Keep patches small and general.
  • Acceptance Checks: Verify that new code actually executes and improves performance.
  • Pool Separation: Use distinct task sets for development and final testing.
Fig. 2. Preventing overfitting during harness search. Editing an entire harness without constraints easily memorizes development tasks and inflates token usage, whereas four practical safeguards keep evolved harnesses generalizable and efficient.

Datasets

The framework was evaluated on SWE-bench Lite, a popular benchmark for resolving real-world GitHub issues. The authors used:

  • Development Set (N=12): For initial failure diagnosis.
  • Validation Set (N=8): For the Stage 3 "Gated" checks.
  • Held-out Test Sets (N=40): Including cross-repository tasks (Django) to test generalization.

Key Insights and Ideas

  • The "Scaffold Effect": A well-designed harness acts as scaffolding. For weak models, it compensates for gaps; for strong models, it unlocks the ability to solve complex, long-horizon problems they couldn't finish alone.
  • Emergent Mechanisms: Through self-improvement, the harnesses "invented" sophisticated features like pre-stop verifiers (checking work before exiting), loop breakers (detecting repetitive failures), and persistent memory (restoring working directories across stateless shell calls).
  • Modular > Monolithic: Unconstrained full-harness rewrites are "fragile and prone to syntax errors." Modular updates generalize better across different models and repositories.
  • Separating Bugs from Limits: The system learns to distinguish between a "harness flaw" (e.g., a tool rejected a patch format) and a "model limit" (the model just doesn't know the domain logic). It only attempts to fix the former.

Key Results

On the SWE-bench Lite benchmark, the Modular Gated Evolution approach showed dramatic improvements:

  • Accuracy: Jumped from a 5.0% success rate (seed harness) to 40.0% on held-out tasks.
  • Efficiency: It used 10x fewer tokens per task compared to unconstrained full-harness rewrites (46.7k vs 451.6k tokens).
  • Zero-Shot Transfer: A harness evolved for a smaller model (Gemini 1.5 Flash) transferred successfully to a stronger model (Gemini 1.5 Pro), achieving the highest overall accuracy (37.5%) at a fraction of the cost of other methods.
  • Reliability: The evolved harness eliminated "unverified exits" (the agent quitting without actually running tests), which was the dominant failure mode in the baseline.

Limitations and Future Work

  • Environment Drift: Harnesses may need "lifelong adaptation" as external APIs and software dependencies change over months of deployment.
  • Joint Optimization: Currently, model weights are frozen. Future work could explore co-evolving the model weights and the harness code simultaneously.
  • Safety Guarantees: As harnesses gain the power to modify their own code, establishing formal "certificate-driven" mutation restrictions is essential to prevent privilege escalation or "evaluator tampering" (where the agent tries to pass tests by editing the grading script).

For a deep dive into the specific failure modes discovered, see Table II in the full paper.

Summary updated

Abstract

Whether a foundation model succeeds as an autonomous agent depends as much on its runtime software as on its weights. This runtime, the agent harness, manages context and memory, steers multi-turn control, executes tool actions in sandboxes, and verifies work before stopping. Because models differ in how they use tools and how they fail, a static harness tuned for one model or task often stalls, wastes tokens, or regresses on another. This bottleneck has driven a shift from prompt tuning to self-improving agent harnesses: systems that inspect their own execution traces, separate runtime bugs from model limits, and rewrite their own code. We present a unifying architectural and design framework for self-improving agent harnesses. The framework pairs four editable runtime components (context and state, agent control, action interfaces, and verification and recovery) with a four-stage loop that diagnoses failures, proposes code patches, validates candidates, and deploys updates. Using this framework, we show how optimizers trace errors across long trajectories and discover reusable runtime mechanisms such as pre-stop verifiers, loop breakers, and persistent memory. We further show why full-harness rewrites overfit or break across modules, and how modular updates with validation gates generalize across models while bounding token cost. To keep self-modification safe, we establish practical defenses against recurring failure modes including prompt bloat, benchmark gaming, and evaluator tampering. Finally, experiments on SWE-bench Lite validate this framework, showing that gated modular evolution outperforms prompt reflection and full-harness rewrites across models and repositories at a fraction of the token cost.
BibTeX
@misc{shah2026harnesses,
  author = {Deep Shah and Nehal Kathrotia},
  title = {{Harnesses That Improve Themselves: A Unifying Framework for Self-Improving Agent Harnesses}},
  year = {2026},
  eprint = {2611.22299},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.22299},
}
Figure