Context Engineering Inside the Harness: 4 Mechanisms That Beat Context Overflow and Goal Loss on Long-Horizon Tasks
An agent, in its easiest type, is an LLM calling instruments in a loop. That loop works for brief jobs. Give it a job that runs for an hour and 200 software calls, and it breaks in 2 predictable methods. The AWS Samples design guide for autonomous cloud coding agents names them instantly: shallow brokers undergo from context overflow, get distracted (objective loss), and don’t preserve state over lengthy durations. The layer that fixes this isn’t the mannequin. It is the harness, which AWS describes as managing every thing however the mannequin.
This article opens up that layer. Compaction, reminiscence technique, context budgeting, and todo-state are the equipment that turns a shallow loop right into a deep agent. We have a look at how LangChain Deep Agents, Claude Code, Manus, OpenAI Codex, and Amazon Bedrock AgentCore implement every one, with the precise thresholds they ship.
Why an even bigger window doesn’t repair it
The apparent repair is a bigger context window. The proof says it helps lower than anticipated. Chroma’s Context Rot report evaluated 18 LLMs, together with GPT-4.1, Claude 4, Gemini 2.5, and Qwen3, and discovered that efficiency grows more and more unreliable as enter size grows, even on easy retrieval duties. Anthropic’s context engineering guide explains the mechanism: consideration creates n² pairwise relationships for n tokens, so each added token depletes a finite “consideration finances.” Context is a useful resource with diminishing returns, not a bucket.
For an agent loop, that is worse than it sounds. Manus stories {that a} typical job wants round 50 software calls, and that the input-to-output token ratio runs close to 100:1. Each statement lands in context and stays there. The unique instruction drifts towards the center of the window, which is strictly the place recall degrades. Goal loss shouldn’t be solely a mannequin bug. It is the anticipated consequence of an unmanaged context on an extended sufficient job.
Mechanism 1: Context budgeting and offloading
The first job of a harness is deciding what by no means enters the window in any respect. Deep Agents ships 2 offloading guidelines with laborious numbers. When a software response exceeds 20,000 tokens, it’s written to the filesystem and changed with a file path plus a preview of the first 10 traces. When session context crosses 85% of the mannequin’s window, older write and edit software calls, whose full file contents already reside on disk, are truncated to a pointer. Only after offloading runs out of room does the harness fall again to summarization.
Claude Code applies the similar budgeting to what hundreds earlier than the first immediate. Auto reminiscence is capped at the first 200 traces or 25KB. MCP software schemas keep deferred by default, with solely software names listed, and full schemas load on demand through software search. After compaction, any re-read file over 5,000 tokens comes again as a path reference relatively than content material. The context window simulation in the Claude Code docs makes the payoff concrete: a analysis subagent reads 6,100 tokens of recordsdata and returns a 420-token end result to the mum or dad.
That subagent sample is budgeting at the structure stage. Anthropic’s information notes that every subagent might burn tens of hundreds of tokens exploring, however returns a distilled abstract, usually 1,000 to 2,000 tokens. The AWS AgentCore walkthrough builds precisely this: a coordinator spawns 3 browser subagents in parallel, every in its personal MicroVM, and an analyst subagent receives solely their structured findings. AWS stories a 4 to six minute anticipated runtime, and notes that sequential processing would take as much as 3x longer.
Mechanism 2: Compaction
When offloading shouldn’t be sufficient, the harness summarizes. Compaction is the apply of taking a dialog nearing the window restrict, summarizing it, and reinitiating a brand new context with the abstract. It can also be the place objective loss most frequently occurs, as a result of a lossy abstract can drop the one constraint that mattered.
The implementations differ in what they promise to maintain. Claude Code’s compaction immediate preserves architectural choices, unresolved bugs, and implementation particulars whereas discarding redundant software outputs. Right after compaction it re-reads as much as 5 of the recordsdata modified most not too long ago, reloads the guidelines matching these recordsdata, and re-injects invoked ability our bodies, capped at 5,000 tokens per ability and 25,000 whole. The docs are specific that detailed directions from early in the dialog could also be misplaced, which is why persistent guidelines belong in the project-root CLAUDE.md, which is re-injected from disk. Users can steer the move with /compact focus on the auth bug repair or transfer the set off level with /autocompact.
Deep Agents made objective preservation a structural function. Its abstract is a structured doc with devoted fields for session intent, artifacts created, and subsequent steps. The LangChain staff added these fields after forced-summarization experiments confirmed the change improved efficiency. The full unique transcript can also be written to the filesystem, so a incontrovertible fact that was summarized away might be recovered by read_file later.
Compaction has moved into the API layer too. OpenAI’s Responses API affords server-side compaction through context_management with a compact_threshold, plus a standalone /responses/compact endpoint that returns a compacted context window containing an opaque encrypted compaction merchandise; OpenAI instructs builders to move that returned window unchanged into the subsequent name. OpenAI says Codex relies on this mechanism to maintain long-running coding duties. The Claude Developer Platform exposes a compact_20260112 context-management edit with customized directions and a pause_after_compaction possibility for inserting content material earlier than the mannequin continues. When you write customized directions there, they exchange the default immediate totally, so a compaction immediate is an actual engineering artifact, not a setting.
Mechanism 3: Todo-state and recitation
Compaction protects the objective at the second of summarization. Todo-state protects it on each flip in between. Manus described the trick plainly: its agent creates a todo.md and rewrites it step-by-step, checking objects off. Rewriting the record recites the goals into the finish of the context, pushing the international plan into the mannequin’s current consideration span and decreasing “misplaced in the center” drift. No structure change is required. It is pure language used to bias the mannequin’s personal consideration.
The proof on todo-state shouldn’t be one-sided. Deep Agents shipped a write_todos software by default till v0.7 in July 2026, when LangChain made TodoListMiddleware opt-in after its evals throughout 3 job classes confirmed barely higher reward and decrease value with todos disabled. LangChain nonetheless recommends turning it again on for lengthy multi-step duties, much less succesful fashions, and UIs that present progress. Claude Code retains a todo record and re-injects the plan written in plan mode from disk after compaction. Anthropic’s information calls the normal sample structured note-taking: the agent writes a NOTES.md or TODO file outdoors the window and reloads it. Its Claude Plays Pokémon instance maintained tallies throughout hundreds of sport steps, then learn its personal notes after every context reset and resumed multi-hour sequences.
The sample behind all of those is that the objective exists as a mutable artifact, not solely as a message in historical past. Messages age and get summarized. A file that’s rewritten each few turns is at all times current, at all times brief, and survives any reset. Whether that’s price its per-turn token value relies upon on the mannequin and the job size, which is strictly what the Deep Agents evals measured.
Mechanism 4: Memory technique throughout classes
The final piece is what persists after the job ends. Claude Code re-injects the project-root CLAUDE.md and auto reminiscence from disk after each compaction. AgentCore Memory shops occasions and runs configured extraction methods in the background, so a coordinator can name a recall software on the subsequent run as a substitute of re-researching. AWS warns that with out not less than 1 extraction technique configured, uncooked occasions are saved however nothing is extracted for retrieval. Anthropic’s file-based reminiscence software serves the similar objective on the Claude platform.
The limitation is that persistent context shouldn’t be free. The ETH Zurich research we (*4*) discovered that repository context recordsdata like AGENTS.md don’t usually enhance job success whereas elevating inference value: LLM-generated recordsdata elevated value by 20% and 23% on the 2 benchmarks, and developer-committed recordsdata by as much as 19%. Memory that reloads each session is a standing tax on the consideration finances. The Claude Code docs give the matching recommendation: hold CLAUDE.md below 200 traces and transfer reference materials into expertise or path-scoped guidelines that load solely when wanted.
Interactive explainer: watch a 200K window replenish
The simulator beneath runs a 60-step migration job via a 200K token window. Toggle the 4 mechanisms, set the compaction set off, and press Run. With every thing off, the window overflows earlier than the job is half achieved. With offloading, compaction, todo recitation, and subagent delegation on, the similar job finishes with the objective nonetheless in current consideration. Token counts are illustrative; the thresholds match Deep Agents defaults.
Testing whether or not the harness really holds the objective
Context administration is just helpful if the agent can nonetheless end the job and recuperate particulars it not sees. LangChain maintains focused evals for precisely this: assessments that set off summarization mid-task and verify whether or not the agent continues towards its goal, and needle-in-a-haystack instances the place a reality is summarized away and should be recovered via filesystem search. To generate sufficient occasions to check immediate variants, the staff triggers summarization at 10 to twenty% of the window as a substitute of the 85% default, and used a 25% set off with Claude Sonnet 4.5 on terminal-bench-2 to check the impact.
The failure to look at for, in LangChain’s view, is objective drift: an agent that asks for clarification proper after a abstract, or wrongly declares the job full. AgentCore Evaluations ships a objective success fee evaluator that may rating the similar traces. If you run a harness and haven’t compelled a compaction in a check, you don’t but know what your abstract immediate drops.
Key Takeaways
- Shallow brokers fail from context overflow and objective loss; the harness, not the mannequin, is the place the repair lives.
- Budget first: Deep Agents offloads software outcomes over 20,000 tokens and evicts previous edits at 85% of the window.
- Compaction should title what it retains; Deep Agents provides session intent and subsequent steps fields, Claude Code re-reads 5 current recordsdata.
- Todo recitation retains the objective at the finish of context, however Deep Agents v0.7 evals present it isn’t a free win.
- Persistent reminiscence prices consideration: ETH Zurich measured 20 to 23% larger inference value from LLM-generated context recordsdata.
The publish Context Engineering Inside the Harness: 4 Mechanisms That Beat Context Overflow and Goal Loss on Long-Horizon Tasks appeared first on MarkTechPost.
