The harness that keeps agents from collapsing on long-running tasks

A language model driving tools in a loop works well for short tasks. Give it an hour-long job with two hundred tool calls and it breaks in two predictable ways: context overflow and goal loss. The AWS design guide for autonomous cloud-coding agents names the problems — shallow agents suffer context flooding, grow distracted, and fail to hold state over time. The layer that fixes this is not the model but the harness, which AWS defines as the manager of everything except the model.
Why a bigger window does not solve the problem
The intuitive fix is to expand the context window. Evidence shows it helps less than expected. Chroma's Context Rot report tested eighteen models, among them GPT-4.1, Claude 4, Gemini 2.5 and Qwen3, and found performance grows less reliable as input length increases, even on simple retrieval tasks. Anthropic's context-engineering guide explains the mechanism: attention creates pairwise relationships at n² for n tokens, so every additional token drains a finite "attention budget." Context is a resource with diminishing returns, not a bucket.
For an agent loop the dynamic is worse. Manus reports a typical task requires roughly fifty tool calls, with an input-to-output token ratio of about 100:1. Every observation lands in context and stays there. The original instruction drifts to the middle of the window, precisely where recall degrades. Goal loss is not merely a model bug; it is the expected outcome of unmanaged context in a task that runs long enough.
Context budgeting and offloading to disk
The harness's first job is deciding what never enters the window. Deep Agents ships with two hard-number offloading rules: when a tool response exceeds twenty thousand tokens it is written to the filesystem and replaced by a file path plus a ten-line preview. When session context crosses eighty-five percent of the model window, old write and edit calls — whose full content already sits on disk — are trimmed to a pointer only. Only when offloading is exhausted does the harness fall back to summarization.
Claude Code applies the same budgeting to what loads before the first prompt. Automatic memory is limited to the first two hundred lines or twenty-five kilobytes. MCP tool schemas remain deferred by default, showing tool names only; full schemas load on demand via tool search. After compression, any repeat file read over five thousand tokens returns as a path reference instead of content. The window simulation in the Claude Code documentation demonstrates the trade-off: a research sub-agent reads six thousand one hundred tokens of files and returns a four-hundred-twenty-token result to the parent.
The sub-agent pattern as architectural budgeting
The sub-agent pattern is budgeting at the architecture level. Anthropic's guide notes each sub-agent may burn tens of thousands of tokens in exploration but returns a distilled summary, often one thousand to two thousand tokens. The AWS AgentCore training builds exactly this: an orchestrator spawns three browser sub-agents in parallel, each in its own MicroVM, and an analyst sub-agent receives only their structured findings. AWS reports an expected runtime of four to six minutes, noting serial processing would take up to three times longer.
Compression: where the goal gets lost
When offloading is not enough, the harness summarizes. Compression is the practice of taking a conversation approaching the window limit, summarizing it, and starting a new context with the summary. It is also where goal loss happens most, because a lossy summary may drop the single constraint that matters. Implementations differ in what they promise to preserve.