WHALE: A Simple Recipe for Joint Harness-Weight Optimization

Haechan Kim, Yoonho Lee, Gisang Lee, Chelsea Finn, Kangwook LeearXiv 2026 · arXiv

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:

  1. 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.
  2. 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.
Figure 1: Overview of WHALE. (a) Weight-only and harness-only adaptation move along a single axis of J(θ, h), whereas alternating updates allow both components to co-adapt. (b) Our simple joint harness–weight optimization recipe outperforms single-component updates across three diverse domains, as well as joint prompt–weight optimization.

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%).
Figure 2: Best-so-far test mean@8 accuracy on the test datasets as rollouts accumulate. Harness-only is held constant after 40, 60, and 40 iterations in SearchQA, Mathematical Reasoning, and Chess Puzzles, respectively.

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

Abstract

Agent performance depends jointly on the model parameters and the executable harness code that manages context and control flow. Optimizing either component in isolation can leave the system bottlenecked by its frozen counterpart: weight updates can change which harness is effective, while harness updates can change which model capabilities are exposed. Existing joint-adaptation methods optimize weights and textual prompts but leave the broader harness fixed. We propose Weight-Harness Alternating LEarning (WHALE), a simple recipe that alternates two phases: updating the model under the current harness, then searching for a better harness under the updated model. We instantiate these two phases with online rejection-sampling fine-tuning and Meta-Harness, respectively. When to switch is a key design choice: to separate real improvements from noise without over-optimizing against a changing counterpart, WHALE uses either fixed phase durations or an adaptive patience rule over training signals. Using Qwen3.5-2B/4B agents across three domains (search question answering, mathematical reasoning, and chess puzzles), WHALE outperforms weight-only, harness-only, and Fast-Slow Training by 4.15-24.38 percentage points in best mean@8 accuracy. Either component can be the bottleneck: harness search matches peak weight-only accuracy with far fewer rollouts in SearchQA, but improves math accuracy only after a weight update. Small interleaved updates also outperform stagewise weight-then-harness optimization in accuracy and rollout cost. The code is available at https://github.com/krafton-ai/WHALE.
BibTeX
@misc{kim2026whale,
  author = {Haechan Kim and Yoonho Lee and Gisang Lee and Chelsea Finn and Kangwook Lee},
  title = {{WHALE: A Simple Recipe for Joint Harness-Weight Optimization}},
  year = {2026},
  eprint = {2609.00196},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.00196},
}
Figure