框架內的語境工程:克服長時任務中語境超載與目標遺失的四種機制
An agent, in its simplest form, is an LLM calling tools in a loop.That loop works for short jobs.Give it a task that runs for an hour and 200 tool calls, and it breaks in 2 predictable ways.
The AWS Samples design guide for autonomous cloud coding agents names them directly: shallow agents suffer from context overflow, get distracted (goal loss), and do not maintain state over long periods.The layer that fixes this is not the model.
It is the harness, which AWS describes as managing everything but the model.This article opens up that layer.Compaction, memory strategy, context budgeting, and todo-state are the machinery that turns a shallow loop into a deep agent.
We look at how LangChain Deep Agents, Claude Code, Manus, OpenAI Codex, and Amazon Bedrock AgentCore implement each one, with the actual thresholds they ship.Why a bigger window does not fix it The obvious fix is a larger context window.The evidence says it helps less than expected.
Chroma’s Context Rot report evaluated 18 LLMs, including GPT-4.1, Claude 4, Gemini 2.5, and Qwen3, and found that performance grows increasingly unreliable as input length grows, even on simple retrieval tasks.
Anthropic’s context engineering guide explains the mechanism: attention creates n² pairwise relationships for n tokens, so every added token depletes a finite “attention budget.” Context is a resource with diminishing returns, not a bucket.For an agent loop, this is worse than it sounds.
Manus reports that a typical task needs around 50 tool calls, and that the input-to-output token ratio runs near 100:1.Each observation lands in context and stays there.The original instruction drifts toward the middle of the window, which is exactly where recall degrades.
Goal loss is not only a model bug.It is the expected outcome of an unmanaged context on a long enough task.Mechanism 1: Context budgeting and offloading The first job of a harness is deciding what never enters the window at all.Deep Agents ships 2 offloading rules with hard numbers.
When a tool response exceeds 20,000 tokens, it is written to the filesystem and replaced with a file path plus a preview of the first 10 lines.
When session context crosses 85% of the model’s window, older write and edit tool calls, whose full file contents already live on disk, are truncated to a pointer.Only after offloading runs out of room does the harness fall back to summarization.
Claude Code applies the same budgeting to what loads before the first prompt.Auto memory is capped at the first 200 lines or 25KB.MCP tool schemas stay deferred by default, with only tool names listed, and full schemas load on demand via tool search.
After compaction, any re-read file over 5,000 tokens comes back as a path reference rather than content.The context window simulation in the Claude Code docs makes the payoff concrete: a research subagent reads 6,100 tokens of files and returns a 420-token result to the parent.
That subagent pattern is budgeting at the architecture level.Anthropic’s guide notes that each subagent may burn tens of thousands of tokens exploring, but returns a distilled summary, often 1,000 to 2,000 tokens.
The AWS AgentCore walkthrough builds exactly this: a coordinator spawns 3 browser subagents in parallel, each in its own MicroVM, and an analyst subagent receives only their structured findings.
AWS reports a 4 to 6 minute expected runtime, and notes that sequential processing would take up to 3x longer.Mechanism 2: Compaction When offloading is not enough, the harness summarizes.
Compaction is the practice of taking a conversation nearing the window limit, summarizing it, and reinitiating a new context with the summary.It is also where goal loss most often happens, because a lossy summary can drop the one constraint that mattered.
The implementations differ in what they promise to keep.Claude Code’s compaction prompt preserves architectural decisions, unresolved bugs, and implementation details while discarding redundant tool outputs.
Right after compaction it re-reads up to 5 of the files modified most recently, reloads the rules matching those files, and re-injects invoked skill bodies, capped at 5,000 tokens per skill and 25,000 total.
The docs are explicit that detailed instructions from early in the conversation may be lost, which is why persistent rules belong in the project-root CLAUDE.md, which is re-injected from disk.
Users can steer the pass with /compact focus on the auth bug fix or move the trigger point with /autocompact.Deep Agents made goal preservation a structural feature.Its summary is a structured document with dedicated fields for session intent, artifacts created, and next steps.
The LangChain team added those fields after forced-summarization experiments showed the change improved performance.The full original transcript is also written to the filesystem, so a fact that was summarized away can be recovered by readfile later.Compaction has moved into the API layer too.
OpenAI’s Responses API offers server-side compaction via contextmanagement with a compactthreshold, plus a standalone /responses/compact endpoint that returns a compacted context window containing an opaque encrypted compaction item; OpenAI instructs developers to pass that returned window unchanged into the next call.
OpenAI says Codex relies on this mechanism to sustain long-running coding tasks.The Claude Developer Platform exposes a compact20260112 context-management edit with custom instructions and a pauseaftercompaction option for inserting content before the model continues.
When you write custom instructions there, they replace the default prompt entirely, so a compaction prompt is a real engineering artifact, not a setting.Mechanism 3: Todo-state and recitation Compaction protects the goal at the moment of summarization.Todo-state protects it on every turn in between.
Manus described the trick plainly: its agent creates a todo.md and rewrites it step by step, checking items off.Rewriting the list recites the objectives into the end of the context, pushing the global plan into the model’s recent attention span and reducing “lost in the middle” drift.
No architecture change is required.It is natural language used to bias the model’s own attention.The evidence on todo-state is not one-sided.Deep Agents shipped a write_todos tool by default until v0.
7 in July 2026, when LangChain made TodoListMiddleware opt-in after its evals across 3 task categories showed slightly better reward and lower cost with todos disabled.LangChain still recommends turning it back on for long multi-step tasks, less capable models, and UIs that show progress.
Claude Code keeps a todo list and re-injects the plan written in plan mode from disk after compaction.Anthropic’s guide calls the general pattern structured note-taking: the agent writes a NOTES.md or TODO file outside the window and reloads it.
Its Claude Plays Pokémon example maintained tallies across thousands of game steps, then read its own notes after each context reset and resumed multi-hour sequences.The pattern behind all of these is that the goal exists as a mutable artifact, not only as a message in history.
Messages age and get summarized.A file that is rewritten every few turns is always recent, always short, and survives any reset.Whether that is worth its per-turn token cost depends on the model and the task length, which is exactly what the Deep Agents evals measured.
Mechanism 4: Memory strategy across sessions The last piece is what persists after the task ends.Claude Code re-injects the project-root CLAUDE.md and auto memory from disk after every compaction.
AgentCore Memory stores events and runs configured extraction strategies in the background, so a coordinator can call a recall tool on the next run instead of re-researching.
AWS warns that without at least 1 extraction strategy configured, raw events are stored but nothing is extracted for retrieval.Anthropic’s file-base
Related
相關文章
中國開源走向物理世界,螞蟻靈波攜機器人通用大腦亮相烏鎮
11月2日至5日,2026年世界互聯網大會烏鎮峰會在浙江烏鎮舉行,本屆峰會的主題為“開源開放 共建共享——攜手構建網絡空間命運共同體”。螞蟻集團旗下具身智能公司螞蟻靈波,攜全棧開源的機器人通用大腦亮相烏鎮,展示模型研發、開源協作以及場景應用的新進展。今天,開源正從語言、代碼和內容生成,延伸至機器人對物理世界的感知、預測與行動。與數字世界不同,機器人本體千差萬別,任務場景高度分散,許多團隊不得不為每一種構型、每一個場景從頭訓練“大腦”。對此,靈波給出的路徑是開放的具身基礎模型。
曝OpenAI拿下超6.7億年單!打“骨折”、送額度、配工程師,就為了搶Anthropic客戶
編譯 | 孫小雯 編輯 | 程茜 OpenAI和Anthropic為了搶用戶,最近又槓上了!10月30日,OpenAI剛將部分Pro套餐的ChatGPT Work和Codex額度翻倍;次日,Anthropic取消了已驗證Ultra賬戶的5小時用量限制,周限額保留。
英特爾與騰訊發佈基於至強6+的雲實例,曬智能體AI基礎設施全家桶
作者 | ZeR0 編輯 | 漠影 11月3日報道,近日,在2026騰訊全球數字生態大會上,英特爾與騰訊雲發佈基於英特爾至強6+處理器的騰訊雲新一代雲實例,並全面展示英特爾的芯片產品與雲端實踐。 全新至強6+處理器擁有最高288顆能效核,單顆處理器最高可支持超過1000個智能體的穩定部署,這也為騰訊雲服務器提供更高併發、更低時延、更優能效的雲端算力服務。
智元榮獲2026世界互聯網大會傑出貢獻獎
11月3日,2026年世界互聯網大會烏鎮峰會在浙江烏鎮隆重開幕,國務院總理李強出席開幕式並發表主旨演講。開幕式上,智元憑藉在具身智能領域的系統性技術突破與產業化實踐,獲頒世界互聯網大會傑出貢獻獎。智元合夥人、高級副總裁朱潔在領獎時表示:人工智能的終局,不在於屏幕與雲端,而紮根於工廠一線和尋常煙火。具身智能賽道的競爭,早已跳出單點技術的競速,轉向軟硬協同、工程化落地、產業組織與治理體系的綜合比拼。智元期待與各界同心同行,堅守務實,躬身落地。
電動車退燒、AI 儲能燒起來:LG 新能源把產能挪向數據中心
11 月 3 日,首席財務官李昌植在財報電話會上給出時間表:今年底軟包儲能系統(ESS)產能將超 50 吉瓦時,明年進一步拉到 70 GWh 以上。在他看來,電動車增速放緩之際,AI 數據中心的大規模新建為電池廠撕開了新口子——第三季度 ESS 在手訂單已達 160 GWh,公司正與電力企業、超大型數據中心運營商談新項目,今年 9 月還作為儲能供應商擠進了英偉達的 DSX Ready 計劃。
最高288核的至強6+,為了Agent高密度部署還下了哪些「雲功夫」?
作者 | 陳悅琳編輯 | 包永剛 一個智能體能順利完成任務,不代表成百上千個智能體就能同時高效運行。 對於承載大量智能體任務的雲服務器而言,除了提升計算速度,如何在任務集中到來時迅速準備好執行環境、怎樣減少暫時閒置的任務對內存資源的佔用,也成為亟待解決的問題。 對此,在一年一度的騰訊全球數字生態大會上,英特爾與騰訊雲聯合發佈了基於至強6+處理器的新一代雲實例,圍繞任務啟動效率、內存資源利用率等關鍵因素進行優化後,其綜合性能較上一代提升30%以上。