Context Engineering Inside the Harness: 4 Mechanisms That Beat Context Overflow and Goal Loss on Long-Horizon Tasks
The "harness" layer, not the model itself, is what enables deep agentic tasks: it manages context, memory, state, and workflow beyond a simple LLM-loop Context overflow, goal loss, and state drift are predictable failures in long-running agents; they are structural problems, not just model limitations Four core mechanisms beat these failures: context budgeting/offloading, compaction, todo-state/recitation, and subagent-driven delegation Larger context windows alone do not solve the problem—Chrom
Analysis
TL;DR
- The "harness" layer, not the model itself, is what enables deep agentic tasks: it manages context, memory, state, and workflow beyond a simple LLM-loop
- Context overflow, goal loss, and state drift are predictable failures in long-running agents; they are structural problems, not just model limitations
- Four core mechanisms beat these failures: context budgeting/offloading, compaction, todo-state/recitation, and subagent-driven delegation
- Larger context windows alone do not solve the problem—Chroma's Context Rot report shows performance degrades as input length grows across GPT-4.1, Claude 4, Gemini 2.5, and Qwen3, because attention scales quadratically (n²) and depletes a finite attention budget
- Each major platform implements these mechanisms with distinct thresholds: Deep Agents offloads tool responses over 20K tokens and truncates at 85% window usage; Claude Code caps auto-memory at 200 lines/25KB and re-reads up to 5 recently modified files post-compaction; OpenAI provides server-side compaction via the Responses API; AWS AgentCore spawns parallel subagents in MicroVMs to compress massive exploration into structured summaries
Why It Matters
Agent developers must stop treating context as an infinite bucket and start treating it as a managed, finite resource—every added token depletes a shared attention budget with n² pairwise relationships. The choice of harness architecture (offloading rules, compaction prompts, todo-state discipline) now directly determines whether an agent survives hours-long coding or research tasks. As compaction moves into the API layer (OpenAI, Anthropic), practitioners need to understand these mechanisms to write correct custom prompts and avoid silent goal loss.
Technical Details
- Context Budgeting & Offloading: Deep Agents ships two hard thresholds: tool responses exceeding 20,000 tokens are written to the filesystem and replaced with a file path plus a 10-line preview; when session context crosses 85% of the model window, older write/edit calls are truncated to pointers since full content lives on disk. Summarization is the last resort. Claude Code applies pre-prompt budgeting: auto-memory capped at 200 lines / 25KB, MCP tool schemas deferred until search, and post-compaction re-reads capped at 5,000 tokens per file with a 25,000-token total skill budget.
- Compaction: Takes a conversation nearing its window limit, summarizes it, and restarts fresh. Claude Code preserves architectural decisions, unresolved bugs, and implementation details while discarding redundant tool outputs; it then re-injects up to 5 recently modified files and skill bodies (capped at 5K/skill, 25K total). Deep Agents structures summaries with dedicated fields for session intent, artifacts created, and next steps, storing the full transcript on disk for recovery via
read_file. OpenAI exposes/responses/compactwith an encrypted compaction item to pass through unchanged; Claude Developer Platform offerscompact_20260112with custom instructions andpause_after_compactionfor injecting content mid-flow. - Todo-State & Recitation: Manus maintains a
todo.mdthat the agent re-renders every turn, ensuring the current goal and pending steps remain the most salient tokens in context—this combats goal drift between compaction events. - Subagent Delegation: Anthropic notes subagents may burn tens of thousands of tokens exploring but return distilled 1K–2K token summaries. AWS AgentCore spawns three browser subagents in parallel MicroVMs feeding a single analyst subagent; expected runtime 4–6 minutes vs. up to 3× longer sequentially.
- Attention Economics: Chroma's Context Rot evaluated 18 LLMs and confirmed declining reliability with length. Manus reports a typical 100:1 input-to-output token ratio; each observation accumulates in context while the original instruction drifts toward the middle of the window—the zone of maximum recall degradation.
Industry Insight
- API-layer compaction is the new surface for customization: OpenAI and Anthropic are moving compaction into framework APIs rather than leaving it to library-level prompts. Engineers writing custom compaction instructions effectively replace the default system prompt—a subtle but high-leverage override that can dramatically affect goal preservation on long tasks.
- Offloading is becoming standard, not optional: The 20K-token and 85%-window thresholds from Deep Agents, plus Claude Code's 25KB auto-memory cap, signal industry convergence on the principle that the harness should decide what never enters context at all, before ever invoking a model call.
- Todo-state is an under-explored vector: While compaction gets most attention, the Manus-style per-turn recitation of
todo.mdis a low-overhead guard against the more frequent problem of goal drift between compaction events—likely to become a common pattern in agent frameworks.
Disclaimer: The above content is generated by AI and is for reference only.