Harness Adapters: Customizing Models for Agent Harnesses
A guide to training LoRA adapters with reinforcement learning inside agent harnesses, improving both accuracy and efficiency of Qwen3.8-27B for specific harness and task combinations, with a reusable recipe.
Open the official reference| Item | Details |
|---|---|
| Provider | Hugging Face |
| Level | Intermediate |
| Published | 2026-11-20 |
| Official source | Hugging Face |
| Topics | #agents · #reinforcement · #llm · #engineering |
Background and Core Idea
Models are typically optimized for general performance rather than for a specific agent harness and task distribution. As a result, when a model and harness are combined, performance and efficiency are left on the table. The official article states: "Combining RL on a custom task distribution with your favorite agent harness yields more accurate and efficient models for that target harness and task distribution." With reinforcement learning, a custom harness adapter can be trained to squeeze everything out of the model for a specific harness and task combination.
The article uses Qwen3.8-27B as an example: under the pi harness, its Terminal-Bench 2.1 score is 39% with an average of 2.9K tokens per task. Freezing those weights and adding an RL-trained LoRA adapter yields 55% pass@1 with average token usage of 1.5K. Most of this is due to the model reasoning less, calling fewer tools, and performing better on the first attempt.
Training Inside Agent Harnesses
The method leverages the Harbor integration in OpenEnv and TRL's OpenEnv guide to train the model inside the chosen harnesses. Ready-to-use Docker images are built for all RL tasks with the target harnesses pre-installed. The final images use Pi 1.5.2, OpenCode 2.2.7, and Hermes Agent v0.22.6.
Unlike most RL frameworks that train a re-implementation of the agent loop, here the harness runs exactly as it ships. The article notes: "Here the harness runs exactly as it ships, and the trainer learns from the exact tokens it produced, recorded by a proxy between the harness and vLLM."
Generating Custom RL Tasks
RL training needs tasks the agent can attempt, a verifier that scores each attempt, and evidence that the verifier is right. The article emphasizes: "A verifier that accepts wrong answers teaches the wrong behavior." The task set comes from three sources:
- SWE-smith (Python, Go): injects bugs into real repositories, with the tests that catch each bug becoming the task's tests, adding volume.
- SWE-Gym (Harbor tasks in TaskTrove): turns real GitHub issues and their merged fixes into tasks, adding real-world bugs.
- Tasksmith: generates tasks from merged pull requests. An LLM agent writes the instruction and tests, and Tasksmith checks that the reference and a valid alternative pass while the unfixed code and a known-wrong solution fail.
Validation with openenv validate
A metadata screen runs first, keeping tasks from training splits with permissive licenses and dropping duplicates, tasks marked as not for training, the 253 tasks in target benchmarks, and any task from a repository those benchmarks use. Then semantic checks from openenv validate run on every task in fresh trials: the reference solution earns the maximum reward (semantic.oracle_max); doing nothing scores clearly lower (semantic.floor_gap); no canary scores more than doing nothing (semantic.canary_floor); and a replay of the reference gives the same reward (runtime.episode_determinism).
Each trial runs as its own Hugging Face Job, allowing dozens of tasks to be validated at once. Example command:
openenv validate path/to/task --sandbox hf-sandbox858 of 1,127 Hub candidates passed. Wrong-answer controls caught defects, including a Tasksmith task that accepted an incomplete implementation and a Terminal-Bench 2.1 verifier (regex-log) that accepted known-wrong answers. Most failures were infrastructure problems, such as images that did not start. Failed tasks stay in a rejected split with the failing check recorded.
Difficulty Check with the Base Model
A valid task can still teach nothing. GRPO scores each attempt against other attempts at the same task, so a task where every attempt passes or every attempt fails gives no learning signal. Before training, Qwen3.8-27B attempted each task 4 times, or 8 times for a stratified sample of six tasks per repository. Of 442 scored tasks, 151 were solved every time and 120 never; the 171 tasks solved only sometimes form the qualified set.
Training Setup and Super-Adapter
Training uses TRL's AsyncGRPOTrainer, with datasets, training, and agent rollouts all running on the Hub in Jobs, combined with OpenEnv and harbor. One LoRA adapter is trained per harness (pi, Hermes Agent, OpenCode). The three LoRAs can also be merged into a single super-adapter that runs unchanged under pi, Hermes Agent, and OpenCode. All artifacts (adapters, GGUFs, RL tasks, safeagents plugin) can be browsed through the Hugging Face collection.
Limitations and Scope
This guide is based solely on the official article's described methods and results, without independent reproduction or additional benchmarks. Results target Qwen3.8-27B and specific harness versions (Pi 1.5.2, OpenCode 2.2.7, Hermes Agent v0.22.6) and task distributions; transferring to other models, harnesses, or tasks requires re-validation. Task validation relies on openenv validate and base-model difficulty checks and cannot guarantee coverage of all defects. Training and validation require appropriate compute resources and a Hub Jobs environment.
Sources & Further Reading
This page is grounded in the authoritative sources below — verifiable and citable by AI engines and readers.
- 🔗 Official source
- # Topic: AgentsBuilding, orchestrating and shipping AI agents
- # Topic: Reinforcement LearningRL, reward models and self-play
- # Topic: LLMsLLM capabilities, products and best practices
- # Topic: EngineeringAPIs, prompting and system design
Citation: Please attribute Laojin Global (laojinchuhai.com) and keep the original link.
Made by Laojin · AI that ships
AllModelsAPIOne key for many models
AllModelsAPI is a multi-model API gateway: one key reaches many models through an OpenAI-compatible interface — point your existing code at a new base URL and you're migrated. It's not a demo: our own production workloads run on it every day.
Related
Linked by topic, people and hubs