TL;DR
Building effective LLM agents requires optimizing both the model's internal weights and the external "harness" code that manages tools, context, and control flow. WHALE (Weight-Harness Alternating LEarning) is a simple, elegant framework that alternates between fine-tuning model weights and searching for better harness code. By allowing these two components to co-adapt, WHALE outperforms single-component and prompt-only optimization methods by up to 24.4 percentage points.
What Problem Does This Paper Address?
When we deploy LLM-based agents, we aren't just deploying a neural network; we are deploying a system. This system consists of model weights (which handle reasoning and generation) and the harness code (the Python infrastructure that manages context windows, formats tool inputs/outputs, handles execution errors, and decides when to terminate a loop).
Historically, optimization has been siloed. Researchers either freeze the harness and fine-tune the model weights, or they keep the model frozen and optimize textual prompts or agent workflows. However, optimizing one in isolation creates a shifting bottleneck:
- A highly capable model cannot utilize critical information if a brittle harness fails to retrieve it.
- An advanced harness cannot fix an agent if the underlying model lacks the capability to follow its instructions or format its outputs correctly.
Coordinating the joint optimization of weights and executable code is notoriously difficult because they operate on different timescales. Fine-tuning relies on rapid, gradient-based updates, while code optimization involves a slower proposal-and-evaluation cycle. Running them simultaneously confounds credit assignment, while running them sequentially ("stagewise") leads to severe over-optimization against a frozen counterpart.
Methods
The authors introduce WHALE (Weight-Harness Alternating LEarning), a modular framework that treats joint optimization as a game of conditional updates. Instead of optimizing both simultaneously, WHALE alternates between two distinct phases:
- Weight-Update Phase: The framework freezes the current harness code ($h$) and updates the model weights ($\theta$) using Online Rejection-Sampling Fine-Tuning (RSFT). The model generates trajectories, a verifier filters out incorrect ones, and the model is trained via supervised learning only on successful rollouts.
- Harness-Search Phase: The framework freezes the newly updated model weights and uses Meta-Harness, an LLM-driven optimizer, to iteratively propose, evaluate, and select modifications to the executable harness code.
A crucial design contribution is when to switch between phases. WHALE explores two strategies:
- Fixed Schedules: Switching after a predetermined number of epochs or search iterations.
- Adaptive WHALE: An early-stopping-style patience rule driven purely by training signals. The weight phase stops when the rolling average of the training reward plateaus, and the harness phase stops when the best training score in its archive stops improving.
Datasets
WHALE was evaluated across three distinct tool-use domains using Qwen3.5-2B and 4B base models:
- SearchQA (Search-based Question Answering): Trained on 18,946 questions from HotpotQA and Natural Questions. Evaluated on a diverse 700-question test set spanning benchmarks like MuSiQue, Bamboogle, and TriviaQA. The agent interacts with a Wikipedia search tool.
- Mathematical Reasoning: Trained on DAPO-Math-17K. Evaluated on challenging math problems from AIME 2024 and AIME 2025. The agent can write and execute Python code to solve sub-problems.
- Chess Puzzles: Sourced from the Lichess open puzzle database (16k training, 256 test). The agent generates moves in Universal Chess Interface (UCI) notation and receives board state updates from the environment.
Key Insights and Ideas
- Domain-Dependent Bottlenecks: The paper reveals that different tasks are limited by different components. SearchQA is harness-dominant: optimizing the harness code alone matches the peak accuracy of weight-only tuning while using a fraction of the rollouts. Conversely, Math is model-dominant: harness search yields virtually zero improvement until a weight-update phase shortens the model's verbose reasoning steps and prevents token truncation.
- The Danger of Stagewise Optimization: Spending the entire training budget to fully optimize weights before touching the harness results in poor performance. The model over-optimizes its behavior to the initial, sub-optimal harness, creating a local minimum that subsequent harness search cannot escape.
- Catalytic Interaction: Small, frequent, interleaved updates act as a catalyst. A minor tweak to the model weights can suddenly unlock the expressivity of the harness search space, allowing the system to climb toward a superior joint optimum.
Key Results
WHALE consistently achieved the highest post-adaptation test accuracy across all three domains, outperforming weight-only, harness-only, and prompt-only (Fast-Slow Training) baselines:
- SearchQA: WHALE achieved 48.3% accuracy compared to 38.3% for both weight-only and harness-only baselines. Adaptive WHALE pushed this further to 52.82%, while saving 23% of the rollout cost.
- Math: WHALE reached 24.8% accuracy, vastly outperforming harness-only search (which stalled at 0.4%) and beating weight-only tuning (15.4%).
- Chess Puzzles: WHALE hit 29.8% accuracy, outperforming weight-only (22.2%) and harness-only (19.8%).
Limitations and Future Work
While WHALE provides a powerful recipe, a few limitations remain open for future exploration:
- Algorithmic Instantiations: The framework was validated using specific choices (RSFT for weights, Meta-Harness for code). The black-box interface allows for other algorithms (like PPO or alternative code-generation pipelines), but these were not tested.
- Compute Overhead: Harness search relies on an external LLM "proposer" (in this case, Claude 4.7 Opus) to write code modifications. While target-agent rollouts are highly efficient, the cost of the proposer LLM compute is non-trivial.
- Scale: The study focuses on smaller, highly agile models (Qwen3.5-2B/4B). Scaling this joint optimization recipe to frontier-class models remains an open engineering challenge.
Summary updated