AI News AI资讯 22h ago Updated 2h ago 更新于 2小时前 46

Context Engineering Inside the Harness: 4 Mechanisms That Beat Context Overflow and Goal Loss on Long-Horizon Tasks Harness内部的上下文工程:4种机制解决长程任务中的上下文溢出和目标丢失问题

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 长运行、多工具调用的Agent核心瓶颈是上下文溢出与目标丢失,根本解法在"Harness"层而非模型本身。 上下文是有限资源,注意力随token数量呈二次方增长,单纯扩大窗口收益递减且不可靠(Chroma Context Rot报告验证)。 四大Harness机制:上下文预算与卸载(如Deep Agents 20k token阈值)、压缩与结构化摘要(保留目标与待办)、子代理并行架构降维输入、持续Todo-state维护任务焦点。 主流框架已落地差异化实现:Claude Code侧重文件与规则持久化、Deep Agents引入结构化总结字段、OpenAI Codex/Bedrock提供服务端压

62
Hot 热度
70
Quality 质量
68
Impact 影响力

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/compact with an encrypted compaction item to pass through unchanged; Claude Developer Platform offers compact_20260112 with custom instructions and pause_after_compaction for injecting content mid-flow.
  • Todo-State & Recitation: Manus maintains a todo.md that 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.md is a low-overhead guard against the more frequent problem of goal drift between compaction events—likely to become a common pattern in agent frameworks.

TL;DR

  • 长运行、多工具调用的Agent核心瓶颈是上下文溢出与目标丢失,根本解法在"Harness"层而非模型本身。
  • 上下文是有限资源,注意力随token数量呈二次方增长,单纯扩大窗口收益递减且不可靠(Chroma Context Rot报告验证)。
  • 四大Harness机制:上下文预算与卸载(如Deep Agents 20k token阈值)、压缩与结构化摘要(保留目标与待办)、子代理并行架构降维输入、持续Todo-state维护任务焦点。
  • 主流框架已落地差异化实现:Claude Code侧重文件与规则持久化、Deep Agents引入结构化总结字段、OpenAI Codex/Bedrock提供服务端压缩API。

为什么值得看

本文首次系统拆解Agent" Harness "层的工程实现,将零散的优化手段归纳为可复用的四大机制,并给出LangChain、Claude Code、Manus、OpenAI Codex、AWS Bedrock等产品的具体阈值与架构对比。对正在构建长周期、多步骤AI Agent的开发者而言,这是一份可直接落地的设计蓝图,避免了重复试错。

技术解析

  • 上下文预算与卸载策略:当工具响应超过阈值(Deep Agents为20,000 tokens)时,完整内容写入文件系统,上下文仅保留路径+前10行预览;会话上下文达到窗口85%后,老的非关键工具调用被截断为指针。Claude Code则对预加载内容严格限容(自动记忆≤200行/25KB,MCP工具Schema按需加载),并通过子代理模式将大段探索(6,100 tokens)压缩为精炼结果(420 tokens)回传父代理。
  • 压缩(Compaction)与目标保护:压缩是将临近满载的对话历史摘要化并重启上下文的过程。关键风险是"有损摘要丢弃唯一约束导致目标丢失"。各方案通过差异化手段保真:Claude Code在压缩后强制重读最近5个修改文件、重载匹配规则并注入技能体;Deep Agents将摘要设计为结构化文档,内含"会话意图、已创建工件、下一步"专用字段,并将完整原始转录本存盘以备回溯;OpenAI Responses API与Claude Developer Platform已将压缩下沉为API级原语(如compact_thresholdpause_after_compaction),允许开发者注入自定义压缩提示词。
  • Todo-state与持续回忆机制:在每步交互间维持任务焦点,典型做法是维护外部todo.md等状态文件并在每次循环中刷新。该机制与压缩互补:压缩解决"历史信息过载",Todo-state解决"当前目标漂移"。
  • 子代理并行架构:以AWS AgentCore为例,协调器并行派生多个浏览器子代理(各自独立MicroVM),分析子代理仅接收结构化发现结果而非原始数据,将顺序处理耗时缩短至原来的1/3–1/4,本质是将上下文预算从"线性堆积"转为"树状聚合"。

行业启示

  • 工程化成为Agent竞争新分水岭:模型尺寸与上下文窗口只是基础,真正决定长任务可靠性的取决于Harness层的上下文管理策略。产品差异化将体现在压缩算法、状态持久化与预算调度等工程细节上。
  • 建议采用分层Harness架构:新建Agent系统时应显式分离"模型推理层"与"上下文管理层",优先集成或自研上下文预算、压缩触发、子代理编排三大组件;将持久化规则与关键约束外置至项目级配置文件(如CLAUDE.md),避免压缩丢失。
  • 关注API层标准化趋势:OpenAI、Anthropic等正将压缩与上下文管理封装为服务端API(如context_managementcompact_endpoint),未来开发者优先利用原生压缩能力而非自行维护历史摘要逻辑,可降低技术债并提升跨平台兼容性。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

Agent Agent LLM 大模型 Deployment 部署 Research 科学研究 Programming 编程