Training the Whole Agent: Co-Evolving the Harness and Policy in Reinforcement Learning

    Most reinforcement-learning work on coding agents optimizes policy parameters while leaving the agent's runtime contract—its harness—fixed. Yet the harness determines which tools are available, how tool descriptions and results are presented, which runtime limits apply, and when a run terminates. This article presents a practical framework for co-evolving the harness and policy through alternating optimization, covering harness layers, search representations, reward and credit-assignment design, reported benchmark signals, common failure modes, and an implementation checklist for reproducible, observable, and secure deployment.

    Most reinforcement-learning (RL) work on coding agents spends nearly all of its compute updating policy parameters. Meanwhile, much of what the agent actually interacts with—which tools it can call, how those tools are described, how returned information is formatted, what feedback it receives on failure, and when the run is forcibly terminated—remains almost unchanged from the first day of training to the last. This fixed runtime contract is commonly called the harness. It is useful to think of the harness as the agent’s workbench and operating manual.

    As a result, the model may be optimized to an extreme on a given workbench, even though that workbench is not well suited to the model. Policy and tools are two coupled variables. Optimizing only one of them is analogous to performing gradient descent in the wrong coordinate system.

    1. The Ignored Half: An Agent Is More Than Its “Brain”

    In RL training for coding agents, most compute goes into updating policy parameters. The harness—which tools are available, how their descriptions are written, how returned information is presented, what hints are shown on failure, and when the run is forced to stop—is usually fixed.

    The result is that the model is optimized to the limit of a given workbench, but the workbench itself may not fit the model. Policy and tools are two coupled variables. Optimizing only one is like doing gradient descent in the wrong coordinate system.

    2. What the Harness Contains

    A harness can be decomposed into at least five designable layers:

    1. Tool set and granularity: How capabilities such as reading files, searching code, editing, running tests, and submitting patches are divided. If granularity is too coarse, a single call returns a large amount of information. If it is too fine, the number of steps grows sharply and context is consumed by protocol overhead.
    2. Tool descriptions and invocation contracts: Parameter naming, required fields, and error-code semantics. Vague descriptions force repeated trial and error, while overly verbose descriptions consume useful context.
    3. Organization of returned information: Whether to return full file contents, diff fragments, or summaries with location anchors; whether errors are passed through raw or filtered structurally. This layer often has a larger impact on the context budget than the model itself.
    4. Runtime hints and constraints: Step limits, suppression of repeated calls, timeout policies, and when to hint that the agent should converge and submit.
    5. Termination and verification conditions: What counts as completion, how test success is determined, and how patches are collected.

    The problem with a fixed harness is that it is a set of prior assumptions that were never jointly optimized with the policy. As model capability changes, a hint that was once “sufficient” may become noise, and a return format that was once “clear” may become interference.

    3. Basic Framework for Co-Evolution

    The core idea is to turn the harness from a constant into an optimizable variable and place it in the training loop together with the policy. In engineering practice, this is typically implemented with bi-level, or alternating, optimization:

    1. # Harness configuration schematic
    2. # (modifiable by outer search/evolution)
    3. tools:
    4. - name: read_file
    5. granularity: span # full | span | summary
    6. max_tokens: 4000
    7. - name: search_code
    8. result_mode: anchors # raw | anchors | ranked
    9. top_k: 8
    10. - name: run_tests
    11. failure_report: filtered # raw | filtered
    12. runtime:
    13. max_steps: 40
    14. repeat_penalty_hint: true
    15. context_budget: 120000
    16. termination:
    17. require_tests_pass: true
    1. # Alternating optimization pseudocode
    2. for outer_step in range(N):
    3. harness = propose_harness(history) # evolution / search / learned selection
    4. for inner_step in range(M):
    5. trajs = rollout(policy, harness) # sample multiple trajectories in a sandbox
    6. rewards = verify_and_score(trajs) # test pass + process constraints
    7. policy = grpo_update(policy, trajs, rewards) # group-relative advantage estimation
    8. history.append(evaluate(harness, policy))

    The outer layer changes the workbench; the inner layer trains behavior. The two are coupled at evaluation: the outer layer uses the policy’s performance after inner-loop convergence to estimate the value of a harness, while the inner loop continues policy optimization under the new harness.

    4. Search Space and Representations

    A harness is a mixture of discrete configuration and natural-language instructions, so direct gradient-based optimization is not feasible. Three common approaches are:

    • Structured search: Enumerate configuration items as a finite set of values and iterate with evolutionary algorithms or combinatorial search. This is low-cost and reproducible, making it suitable for closing the loop first.
    • Learned selection: Treat “current state—candidate harness” as a selection problem and use online learning with feedback to converge gradually. This can be sample-efficient but requires a stable evaluation signal.
    • Text-level rewriting: Let the model itself propose changes to tool descriptions and hints, then validate them in the outer loop. This is expressive, but it can easily expand without bound, so length and complexity constraints are necessary.

    A practical recommendation is to fix the text layer first and search only structured configuration. Once a gain has been confirmed, open up the text layer; otherwise, it is difficult to tell where the improvement came from.

    5. Reward Design and Credit Assignment

    This is where the entire method is most likely to fail. The final reward is usually whether the patch passes tests, but the effect of a harness change is indirect. Additional design is therefore needed:

    • Process rewards: Invalid-call ratio, repeated calls, context usage, and step efficiency. These discourage using large amounts of trial and error to obtain a single success.
    • Controls and ablations: Paired evaluation of the same policy under different harnesses is needed to attribute gains clearly. Reporting only the final score hides variance.
    • Preventing reward hacking: If “fewer steps” is weighted too heavily, the model will learn to skip verification and submit directly. A hard correctness gate must remain.
    • Variance control: Group-relative advantage methods such as GRPO rely on multiple samples under the same prompt. Frequent harness changes break comparability across groups, so it is advisable to freeze the harness within an outer stage.

    6. Signals from Public Research

    One public research effort by a university research team working with independent researchers described a reinforcement-learning approach in which the harness and policy adapt together. It validated the idea on a model with roughly 9 billion parameters. On three public code-repair benchmarks, accuracy improved by approximately 9.8, 12.6, and 6.4 percentage points compared with conventional policy-only training.

    The significance of these numbers is not their absolute values but their magnitude. They indicate that changing the workbench can deliver gains comparable to a typical model-side optimization. The large differences across benchmarks also suggest that the optimal form of a harness is strongly tied to task distribution.

    7. Failure Modes and Risk Controls

    • Context explosion: As tool returns become more “friendly,” token costs rise. Budget caps and monitoring are required.
    • Benchmark overfitting: A harness searched on a small set of evaluations may simply fit quirks in the evaluation scripts. An independent held-out set is needed.
    • Permissions and security: Tools that can execute commands or write files should run in isolated sandboxes with least privilege, rollback capability, and full auditing.
    • Reproducibility: Harness versions must be tagged together with policy versions; otherwise, production issues cannot be traced back.

    8. Deployment Checklist

    1. Establish observability first: Log every tool call, return summary, token usage, and termination reason end to end, and route them to logging and monitoring with alerts.
    2. Containerize the evaluation pipeline: Ensure that the same policy can be compared in a paired manner under different harnesses.
    3. Proceed in three phases—freeze, search, and converge: Release only one variable dimension at each stage.
    4. Use general cloud capabilities: Run sandboxes on a container platform, store trajectories and checkpoints in object storage, schedule sampling with a message queue, and use logs and monitoring for attribution.
    5. Validate on a held-out set and with manual sampling before launch: Confirm that the gains are not evaluation noise.

    9. Conclusion

    An agent’s capability ceiling is determined not only by its parameters but also by the contract between the agent and its environment. Treating the tool set, return formats, runtime hints, and termination conditions as trainable objects and optimizing them alternately with the policy is a systematic improvement path with low cost and clear benefits.

    The real engineering requirements are to version the harness, pair the evaluations, and harden the security boundaries. With these three practices in place, co-evolution becomes a reproducible gain rather than a lucky tuning result.