Improving Deep Agents with harness engineering

LangChain reported that its coding agent, deepagents-cli, improved by 13.7 points on Terminal Bench 2.0, rising from 52.8% to 66.5% and moving from outside the Top 30 on the leaderboard into the Top 5. The company says it changed only the harness and kept the underlying model fixed at GPT-5.2-Codex. The work is framed as harness engineering: building tooling around a model rather than retraining it, with the stated design space covering system prompts, tool choice, execution flow, hooks, skills, sub-agent delegation and memory.
Terminal Bench 2.0 is described as a standard benchmark for agentic coding, with 89 tasks spanning machine learning, debugging and biology. LangChain ran it through Harbor, which spins up sandboxes on Daytona, drives the agent loop and handles verification and scoring. Every agent action is stored in LangSmith along with latency, token counts and cost metrics, which the team treats as the raw material for improvement.
To keep the search tractable, LangChain compressed the optimization space to three knobs: the system prompt, tools, and middleware (its term for hooks around model and tool calls). The starting point, a default prompt with standard tools and middleware, scored 52.8% with GPT-5.2-Codex. The team packaged its trace analysis into an Agent Skill so the debugging loop would be repeatable: fetch experiment traces from LangSmith, spawn parallel error-analysis agents whose findings a main agent synthesizes, then aggregate feedback into targeted harness changes. LangChain says a human can help verify and discuss proposed changes, though is not required, and warns that changes overfitted to one task can cause regressions elsewhere. It plans to publish the skill and is testing it for prompt optimization more generally.
The largest gains came from forcing a build-and-verify loop. LangChain says the most common failure pattern was an agent writing a solution, re-reading its own code, concluding it looked fine, and stopping. The system prompt now prescribes planning and discovery, building with verification in mind, running tests and comparing output against the task spec rather than against the agent's own code, and fixing errors by revisiting that spec. This is backed by deterministic context injection: a PreCompletionChecklistMiddleware intercepts the agent before it exits and reminds it to run a verification pass against the task specification, an approach LangChain compares to a hook that forces the agent to keep working on exit.
A second cluster of changes concerns environment context. A LocalContextMiddleware runs at agent start to map the working directory plus parent and child directories, and runs bash commands to locate tooling such as Python installations, since discovery and search are error prone. Prompting tells the agent its work will be measured against programmatic tests, that file paths in task specs must be followed exactly for automated scoring to succeed, and that edge cases matter as much as happy paths. Time budget warnings nudge the agent to finish and switch to verification, a heuristic the team notes matters mainly because Terminal Bench imposes strict timeouts.
LangChain also added a LoopDetectionMiddleware that tracks per-file edit counts through tool call hooks and appends context suggesting the agent reconsider its approach after repeated edits to the same file. Traces showed "doom loops" where an agent made small variations on the same broken approach more than ten times. The team is explicit that this is a heuristic for today's models and expects such guardrails to become unnecessary as models improve.
Reasoning budget turned out to be a real trade-off. GPT-5.2-Codex has four reasoning modes: low, medium, high and xhigh. Running only at xhigh scored 53.9%, worse than 63.6% at high, because agents ran out of time under Terminal Bench limits, and xhigh burns over twice the tokens and time. LangChain settled on an xhigh-high-xhigh "reasoning sandwich", spending heavily on planning and late verification while using high in the middle, which it says pushed the score to 66.5%. It contrasts this hand-tuned policy with adaptive reasoning in Claude and Gemini models, and suggests a multi-model harness might use a large model for planning and a smaller one for implementation.
The general principles LangChain draws: assemble context on the agent's behalf because search in unseen environments is unreliable; prompt aggressively for self-verification since models favor their first plausible solution; use traces as a feedback signal, debugging tooling and reasoning together because a missing tool or instruction can send a model down a wrong path; patch bad patterns in the short term; and tailor harnesses to models. On that last point, a test run with Claude Opus 4.6 scored 59.6% on an earlier harness version without a matching improvement loop, which LangChain presents as competitive but behind Codex.
Open directions the team lists include multi-model systems combining Codex, Gemini and Claude, memory primitives for continual learning, and measuring harness changes across models; it is also exploring methods such as RLMs to mine traces more efficiently. Deep Agents is open source in Python and JavaScript, and LangChain released a dataset of its traces.
Why it matters: agent quality is often treated as a function of the model, but this result suggests a large share of the gains for coding agents is available in the scaffolding around a fixed model, which is cheaper to change than to retrain. For teams building or evaluating agents, that means prompts, verification hooks, environment context injection, loop detection and reasoning budgets are first-class engineering surfaces worth instrumenting and iterating on with traces. A likely trade-off, based on the reported numbers, is that heavier reasoning is not strictly better once time and token limits bind, so harness defaults tuned for one benchmark or model family may not transfer without a fresh round of measurement.
Based on reporting from the original publisher. Visit the source for full context and later updates.
Publisher excerpt
Harness engineering improved LangChain's coding agent from Top 30 to Top 5 on Terminal Bench using self-verification, tracing, and context optimization.