TL;DR
Harness-R1 introduces a novel paradigm for improving large language model (LLM) agents by training a dedicated 9B "harness engineer" to automatically edit the agent's executable runtime environment. Using online reinforcement learning (GRPO) grounded in actual task outcomes, the engineer learns to inject precise Python code patches across the agent's lifecycle, significantly boosting success rates without altering the underlying agent's weights.
What Problem Does This Paper Address?
When LLM agents are deployed, they continuously accumulate interaction traces. While these traces contain valuable data, the agent's behavior typically remains fixed unless its weights are explicitly fine-tuned. However, an agent system consists of two parts: the core LLM actor and the harness—the surrounding runtime code that handles context construction, tool mediation, action validation, and error recovery.
Traditional methods either focus solely on fine-tuning the LLM or rely on fixed prompting strategies (like Self-Refine) to fix errors. Prompting large frontier models to statically edit runtime code often fails because these models optimize for plausible-looking code rather than functional code. Without a grounded feedback loop to test if their code actually works, fixed editors frequently introduce regressions or break execution interfaces.
Methods
Harness-R1 frames failure-conditioned, lifecycle-wide harness editing as an online reinforcement learning problem.
The framework operates in a closed loop:
- Failure Mining: The system collects a batch of failure trajectories from a frozen target agent and compacts them into a "failure packet."
- Patch Generation: A separate 9B Harness Engineer model reads this packet and generates a Python patch containing hooks for four specific lifecycle points:
episode_init(context/skills setup),make_pre_hint(state guidance),on_before_action(runtime guardrails), andon_post_step(recovery logic). - Validation & Rerun: The patch is validated for execution safety. If valid, the frozen target agent reruns the exact same batch of tasks using the modified harness.
- Outcome-Grounded Training: The engineer receives a reward based strictly on the realized change in task success. The policy is trained using a two-stage approach: a cold-start Supervised Fine-Tuning (SFT) phase using teacher-filtered valid patches, followed by online Group-Relative Policy Optimization (GRPO).
Datasets
The authors evaluated Harness-R1 across three distinct interactive agent environments:
- WebShop: A simulated e-commerce environment testing grounded web navigation and item purchasing.
- ALFWorld: A text-based embodied environment requiring multi-step household task planning and execution.
- DBBench: A relational-database benchmark demanding schema inspection and structured SQL querying.
The training splits consisted of roughly 1,000 SFT examples and 1,500 RL failure packets derived from these environments.
Key Insights and Ideas
- Outcome over Plausibility: Code that looks correct to a frontier model often fails in practice. By rewarding the engineer only when a patch successfully turns a past failure into a win, Harness-R1 prioritizes functional utility over superficial correctness.
- Harness-Agent Co-Evolution: Optimizing the harness is entirely complementary to fine-tuning the agent's weights. When the target agent itself is fine-tuned and becomes smarter, the harness engineer can be retrained to discover entirely new ways to safeguard and support the upgraded model.
- Strong Cross-Model Generalization: Remarkably, a harness engineer trained on a single model's failures generalizes robustly to completely unseen target models. It can read the failure traces of entirely different model families (like Llama or Gemma) and generate highly effective custom patches for them.
Key Results
Harness-R1 achieved substantial performance gains across all evaluated benchmarks:
- Vanilla Target Boost: It raised the average success rate of a vanilla Qwen3.5-9B agent from 44.3% to 53.6% (+9.3 percentage points), outperforming much larger frontier models used as zero-shot prompt editors.
- Fine-Tuned Target Boost: When paired with an already fine-tuned target agent, Harness-R1 pushed the success rate further from 59.2% to 64.2% (+5.0 points).
- Target Generalization: Applied across 20 completely unseen target models, the framework delivered a positive average gain on every single model, averaging a 7.06 percentage point increase overall.
- Lifecycle Specificity: Ablation experiments revealed that the importance of lifecycle hooks is environment-dependent. Pre-action mediation (
on_before_action) was critical for preventing premature purchases in WebShop, whereas post-feedback recovery (on_post_step) drove the gains in ALFWorld.
Limitations and Future Work
- Transductive Reward Constraints: The reward signal is currently tied to the same batch of tasks used to identify failures. This can occasionally result in patches that are overly tailored to specific task distributions. Future work will explore explicitly optimizing against regressions on completely held-out tasks.
- Ignoring Latency and Cost: The current optimization objective focuses purely on task success. It does not penalize the engineer for adding complex hooks that increase runtime latency or inference costs.
- Multi-Round Co-Evolution: The authors demonstrated a single step of sequential adaptation. A natural next step is to build a continuous, multi-round alternating training loop where the agent and the harness engineer evolve together dynamically over time.
Summary updated