Harness Adapters: Better AI Agents at Lower Cost14 min read2,731 words

Harness Adapters: Better AI Agents at Lower Cost

Learn how harness adapters tune AI models for specific agent frameworks, improving coding results while reducing tool calls, token use and operating costs.

harness adaptersagentic AIreinforcement learningLLM efficiencyAI coding agents
Harness Adapters: Better AI Agents at Lower Cost

Why AI Agents Need Models Trained for Their Harness

A strong model can still perform poorly inside an AI agent. Usually the issue isn't the model by itself - it's the setup around it. The agent "harness" (the runtime that manages the loop) affects how tool calls work, what context the model sees, and how the system steps through a task.

Hugging Face's harness-adapter experiments test a simple idea: train a model with reinforcement learning using the same harness it will run with in production. The output is a small LoRA adapter tuned for a specific model-and-harness pairing. In tests with Qwen3.8-27B, these adapters improved coding benchmark results while also cutting down tool calls and generated tokens.

That matters beyond benchmark bragging rights. In production coding agents, fewer unnecessary steps can mean lower inference costs, faster task completion, and less operational mess. Still, the payoff depends on having reliable tasks, verifiers, and evaluation. This article explains what harness adapters are, how the experiments were run, what the results show (and don't show), and how to decide whether this approach fits your own agent.

What is a harness adapter?

An AI agent harness is the runtime around a model. It manages the conversation, sends tool results back to the model, and decides how the loop proceeds. Pi, OpenCode, and Hermes Agent are examples of coding-agent harnesses. Even when two harnesses use the same underlying model, behavior can still diverge because their prompts, context handling, and tool interfaces differ.

A base model is usually trained to work across a wide range of tasks and interaction styles. It isn't automatically optimized for a particular harness - or for the exact way your organization expects the agent to behave. That mismatch shows up as redundant tool calls, token-heavy exploration of problems the harness could have handled more directly, or weaker use of the harness's tools.

A harness adapter is a small set of learned weights (a LoRA adapter) trained on top of a base model for a specific harness and task distribution. It doesn't replace the model or the harness. Instead, it nudges the model's behavior so it works better in that specific environment.

Why train inside the real agent loop?

A lot of reinforcement-learning setups rebuild an agent loop inside the training framework. That can help - but a reconstructed loop can still differ from what you deploy. If tool behavior, message formatting, or context handling changes even a bit, you may end up training for an approximation rather than the real system.

Hugging Face's approach keeps the chosen harness in the loop during training. A proxy records the tokens exchanged between the harness and the model server, so training can learn from the actual interaction. The experiments used Harbor, OpenEnv, and TRL's AsyncGRPOTrainer, with Pi, OpenCode, and Hermes Agent running inside task-specific Docker images.

This is a systems choice, not just a training detail. When your training environment includes the same production harness, the learned behavior is more likely to hold up after deployment. The trade-off is that you inherit the harness's operational complexity, and you need to keep training and evaluation aligned with the environment you'll actually use.

What does the adapter learn to optimize?

The training objective rewarded verified task correctness, with an extra bonus for tool efficiency. In practice, the trained models often solved tasks using fewer tool calls and shorter interaction trajectories. The point wasn't to make the agent "concise" for its own sake - it was to improve task completion while cutting out unnecessary back-and-forth.

That distinction matters. Fewer calls alone don't mean success. An agent can stop early to look efficient while leaving the job unfinished. A useful adapter improves (or at least preserves) verified task success while reducing the work required to achieve it.

How do you train a harness adapter?

Reinforcement learning only works well if the tasks and reward signal are solid. A model can't learn reliably from a broken test suite, or from a verifier that accidentally rewards incorrect solutions. And not every valid task provides useful learning signal - if a task is always passed or always failed, the training method has little information about which behaviors actually help.

In the harness-adapter work, task construction and filtering were treated as part of the core process, not as "cleaning up" after the fact.

Build tasks from more than one source

The dataset combined three sources. SWE-smith creates bug-fixing tasks by injecting bugs into real Python and Go repositories. SWE-Gym packages real GitHub issues and their merged fixes as tasks. Tasksmith generates tasks from merged pull requests, producing instructions and tests, then checking that reference solutions pass while known-wrong solutions fail.

Using multiple sources helps balance scale and realism. Injected bugs can generate volume, while issue-based tasks reflect problems developers actually face in repositories. The generated tasks also target skill gaps that show up in evaluation benchmarks - things like filesystem operations, HTTP streaming, and serialization.

The final dataset had 871 tasks across 35 repositories. Tasks were capped at 40 per repository so one project wouldn't dominate. From there, 171 tasks formed the qualified subset for GRPO training: tasks the base model solved sometimes, but not on every attempt.

Validate the verifier, then check task difficulty

Each task went through eligibility and semantic checks. The reference solution had to earn the maximum reward. "Do nothing" solutions had to score lower. Known-wrong canaries couldn't score above a floor. Replaying the reference solution also needed to produce consistent results.

These checks mattered. Out of 1,127 Hub candidates, 858 passed validation. Some failures were infrastructure problems, but others revealed real issues: at least one task accepted an incomplete implementation, and at least one benchmark verifier accepted known-wrong answers. A verifier bug can teach the agent to confidently do the wrong thing - so validating the verifier is a prerequisite for meaningful training.

After that, the team tested Qwen3.8-27B multiple times. Tasks the model solved every time or never solved were excluded from the qualified set, because they don't help a GRPO-style method learn useful distinctions. The remaining tasks created a better middle ground: success was possible, but not guaranteed.

Keep training and evaluation comparable

The adapters were trained using LoRA and GRPO, with AsyncGRPOTrainer. Each harness adapter used two NVIDIA B200 GPUs: one for the vLLM model server and one for training. The final task mixture included 750 tasks from the harness-adapter environments and 300 from Termgrade.

The setup also included safeagents rules to block suspicious tool use. Across three runs, the system checked about 1.3 million tool calls and blocked 647. That's a useful operational safeguard, but it shouldn't be treated as a complete security solution. Those rules have to match your tools and task environment, and teams still need controls tailored to their own repositories, credentials, and deployment risks.

What results did the adapters achieve?

The main finding held up within the tested setup: each specialist adapter outperformed the base model on coding benchmarks under its own harness, and it generally did so with fewer tool calls. Evaluation used Terminal-Bench 2.1 and the 51 hardest tasks from SWE-bench Pro, with one attempt per task and fixed limits on time, agent steps, and tokens.

One important caution from the authors: don't over-interpret raw scores across different harnesses. Pi, OpenCode, and Hermes Agent handle context differently, so score changes can reflect the harness as much as the model. Comparisons within the same harness are much more meaningful.

Specialist adapters improved performance and efficiency

On Terminal-Bench 2.1, the Pi adapter moved from around 40% pass@1 for the base model to about 56.5%. Hermes rose from roughly 44.7% to 58.8%, while OpenCode increased from about 47.6% to 52.4%. On the hard SWE-bench Pro subset, the Pi and OpenCode adapters also showed clear gains. Hermes improved from 29.4% to 43.1% in the reported comparison.

Efficiency improved too. On tasks where both the adapter and base model solved, the specialist adapters used about 53-72% fewer tool calls on Terminal-Bench and 56-72% fewer on SWE-bench Pro. The earlier Pi example shows why this can matter in practice: pass@1 increased from 39% to 55%, while average token use dropped from about 2.9K to 1.5K per task.

For a business, success-plus-efficiency beats benchmark gains alone. If your workload behaves similarly, fewer model calls can lower inference spend and reduce how long the agent ties up a worker or sandbox. But "fewer tokens" doesn't automatically translate into lower total cost. Infrastructure, retries, task failures, and human review all still drive real spending.

A single adapter can serve multiple harnesses - but with a trade-off

The team also merged the three specialist LoRAs into one "super-adapter" to answer a practical deployment question: can you run one tuned model across several agent frameworks, instead of maintaining separate variants?

The updates had low pairwise cosine similarity (around 0.01-0.02), suggesting the specialists pushed the base model in largely different directions. The team concatenated them and tested different scaling weights. Applying every update at full strength made the agent overly aggressive - tool calls dropped a lot, but results varied across harnesses. In their Terminal-Bench selection experiment, half strength produced the best overall balance.

With thinking mode off, the super-adapter improved average pass@1 across six harness-and-benchmark comparisons from 39.5% (base) to 49.0%. It also used 53-73% fewer tool calls on tasks both models solved. Even so, a specialist adapter stayed ahead on most comparisons, especially for Pi. In other words, the merged adapter is a compromise: broader compatibility in exchange for giving up some of the best per-harness gains.

Some behavior transferred across harnesses

The Pi adapter was tested under Hermes and OpenCode as well. It matched OpenCode's specialist on Terminal-Bench and kept about two-thirds of Hermes's specialist gain in the reported comparison, with similarly reduced tool calls. That suggests the adapters may learn behaviors that carry beyond a single harness.

But this isn't proof that harness choice stops mattering. It's one transfer test on a defined set of coding tasks. On 300 AutomationBench business-automation tasks - using a different agent loop - the adapters stayed close to the base model. Some were slightly ahead, the merged adapter was roughly even, and Hermes lagged. The evidence supports a narrow conclusion: specialization improved the tested coding setup without clearly ruining performance on that separate evaluation, but broad transfer remains uncertain.

What should teams consider before adopting them?

Harness adapters are a targeted optimization, not a universal upgrade. They make the most sense when your agent harness is stable, you have a repeated class of tasks, and you can gather enough reliable examples to train and evaluate behavior. If your workflow changes every few weeks, the cost of maintaining specialized adapters may erase the benefits.

Start with a measurable operational problem

Before training, identify what's expensive or unreliable in the current system. Is the agent making redundant calls? Failing a known category of repository task? Are token costs high because it keeps exploring the same files? Establish a baseline using the harness and settings you plan to deploy.

Then define success using both quality and operating cost. Track pass rate, tool calls, tokens, latency, retries, and human correction. A model that cuts tokens by 40% but increases failed tasks can be a net loss. Evaluation should include paired task-level results, not just an average score - so you can see what improved and what got worse.

Treat task quality as part of the model

If you build your own training set, validate the verifier. Include a reference solution, a no-op or floor case, known-wrong controls, and repeatability checks. Also sample the base model on each task before training, so you don't fill the dataset with tasks that provide no useful learning signal.

Next, watch for leakage. Keep evaluation tasks and repositories out of training, use permissively licensed data where required, and document why tasks were accepted or rejected. A bigger dataset isn't automatically better. Bad labels - or overly easy tasks - can dilute the learning signal and reward behaviors you don't actually want.

Watch for efficiency and reasoning trade-offs

The study flagged one behavior worth monitoring. With thinking mode off, some adapter trajectories included short text segments before tool calls that looked like reasoning. The authors described this as possible "reasoning leakage." Under their tested conditions, benchmark results still held, but the behavior raises a real question about how thinking and non-thinking modes interact during learning.

For production teams, the practical response is to inspect trajectories, not just aggregate scores. Check whether the model is outputting text you don't want logged, whether it follows your expected interaction format, and whether shorter trajectories reflect good decisions - or premature stopping.

Use a specialist or a merged adapter deliberately

A specialist adapter is the better choice when you have one main harness and you want the best measured performance there. A merged adapter can make sense when the operational value of one artifact across multiple harnesses outweighs the downside of giving up peak per-harness scores.

Don't pick the merged option just because it's easier at checkpoint time. Compare maintenance savings against the performance you'll lose on your highest-value workflow. The right decision depends on deployment constraints, not on how "simple" it sounds on paper.

Conclusion

Harness adapters address a practical weakness in general-purpose AI models: the model may not be optimized for the agent loop and task distribution it will actually run. Training with reinforcement learning inside the target harness produced coding agents that performed better - and often used fewer tools and fewer tokens - in Hugging Face's evaluations.

This approach looks strongest when your workflow is repeated, your harness is stable, and task outcomes are easy to verify reliably. It's less compelling when your task distribution is broad or shifting, the verifier is weak, or maintaining specialized models costs more than the operational gains.

If you're considering the method, start with one measurable workflow. Validate tasks, set up a paired baseline, and track quality alongside total operating cost. If the adapter improves under production-like conditions, specialization may be worth it. If not, you may get more value by improving the harness, the tools, or the evaluation process first.

Frequently Asked Questions

An AI harness is the runtime that manages an agent’s interaction with a model and its tools. It handles prompts, tool calls, returned results and the agent loop. Different harnesses can produce different behavior even when they use the same model.
No. A harness adapter, such as a LoRA, is trained on top of a base model. It adjusts the model’s behavior for a particular task distribution and harness while keeping the original model as its foundation.
No. The experiments found fewer tool calls and tokens on many coding tasks, which can reduce inference costs. Actual savings depend on pricing, infrastructure, retries, task success and human review, so teams should measure total cost on their own workloads.
Use a specialist when one harness is your main deployment target and you want its strongest measured results. A merged adapter can simplify multi-harness operations, but may sacrifice some of the specialist’s performance.
That is not established. The adapters stayed close to the base model on a separate business-automation benchmark, but results varied by adapter. The evidence supports gains on the tested coding tasks, not a general guarantee across unrelated domains.

Related articles