← AUTOMATER NEWSROOM

Deep Agents Guide to Context Engineering: Keep the Window Small and Detail Recoverable

LangChain's Oct. 14 Deep Agents guide explains five middleware techniques for recoverable context engineering: offloading, summarization, skills, subagents, and file-based memory that survives model switches.

Hero overview of five Deep Agents context techniques keeping the active window small while file-backed detail stays retrievable.Hero overview of five Deep Agents context techniques keeping the active window small while file-backed detail stays retrievable.
Original explanatory graphic: offload, summarize, skills, subagents, and memory keep the active window small while file-backed detail stays retrievable.

LangChain published a conceptual guide to how Deep Agents remember on Oct. 14, 2026, framing long-run failure as context rot — as instructions, tool results, files and drafts pile up, accuracy and reasoning degrade. Deep Agents, LangChain’s open source agent harness, answers with middleware techniques that keep the active window small while keeping file-backed detail recoverable from storage you control.

That recoverable distinction applies to file-backed history. Offloaded tool results and summarized conversation logs are relocated to the filesystem with a read-back path, and skills and long-term memory stay file-backed the same way. Noisy subagent work is different: it runs isolated in a separate window and returns only its contracted result to the main agent.

LangChain blog page for Context Engineering: How Deep Agents Remember by Jess Weng, showing title, date, and key takeaways.
LangChain blog hosts the Context Engineering guide by Jess Weng dated Oct. 14, 2026, with key takeaways on context rot and Deep Agents memory techniques. · Original source

Where this bites: an overnight coding run

LangChain illustrates the problem with a Monday competitive-analysis run in the source example: five market exports, dozens of searches and two stale drafts carried into final formatting. A similar accumulation pattern shows up in a coding run.

Consider a test-migration lane: it pulls failing logs, reads five source files, writes three patches, reruns the suite twice, then drafts release notes. By the final step the model still carries early log dumps, superseded diffs and passing output it no longer needs. Without intervention, formatting notes pays for every prior artifact and reasons over stale plans.

The guide’s mental model is that an agent is a model with a harness around it. The harness either keeps unnecessary information out, or manages what is already there. In Deep Agents that logic lives in middleware — code hooked before the run, around each model call, or around each tool call. Most is built in, the guide notes, unless you change defaults.

That expands the earlier context management guide for Deep Agents, which documented three compression mechanisms plus filesystem preservation and targeted evals. The new guide adds operator-facing patterns for skills, subagents and long-term memory. The LangChain blog index lists the new guide as its lead recent story for Oct. 14, 2026.

Diagram showing middleware deciding what the model sees, with recoverable files separate from isolated subagent work.Diagram showing middleware deciding what the model sees, with recoverable files separate from isolated subagent work.
Original diagram: middleware hooks filter model and tool calls, with file-backed previews and summaries recoverable and noisy subagent work isolated to a contracted result.

Five techniques, and what stays in context

Technique Full data lives in Active window keeps How it returns
Offloading Filesystem file Preview plus path Agent pages file with read_file
Summarization Full log on disk Summary plus recent verbatim Agent reads history file
Skills Skill folder on disk Names and descriptions only Model reads SKILL.md when relevant
Subagents Separate subagent window Only contracted result In source example, three bullets; configurable per subagent
Long-term memory Markdown file you own Injected contents every call Loaded at start, updated when learned

1. Offloading keeps large inputs out. In the source example, when a tool result exceeds roughly 20,000 tokens, the full result is written to /large_tool_results/{tool_call_id} before entering the conversation. The model keeps only first and last lines plus the path. Oversized human messages such as a pasted transcript get the same treatment at 50,000 tokens under /conversation_history/.

Operator rule from the guide: offload, do not truncate. Truncation is lossy; offloading keeps detail retrievable by paging the file.

2. Summarization resets the slow climb. Offloading handles spikes; summarization handles accumulation. The default check runs before each model call: once usage crosses 85% of the window, a separate call condenses older messages, keeps recent messages verbatim, and puts the summary first. It is recoverable and it cycles, with each new summary folding in the previous one.

3. Skills load know-how on demand. A skill in the source QBR example is a folder of instructions, scripts and reference docs. SkillsMiddleware scans only headers before the run and adds names plus descriptions to the system prompt. Full instructions enter only when the model decides the skill is relevant and reads it. Ten skills cost about as much as ten one-liners until one is needed.

4. Subagents isolate noisy work. For work you know will be noisy — the source example researches a company across dozens of searches — run it in a separate window and return only the result. The following source code excerpt defines that contract:

market_researcher = {
    "name": "market-researcher",
    "description": "Researches a company and returns the 3 most notable developments.",
    "system_prompt": "Use pull_market_report, then return 3 short bullet points. Do not return the raw report.",
    "tools": [pull_market_report],
}

agent = create_deep_agent(model=model, subagents=[market_researcher])

In that configured example the main agent sees three bullets, not even a preview. Three bullets is that example’s return contract, not a harness default. Well-scoped subtasks can also run on a cheaper model and in parallel.

5. Long-term memory persists across runs. Memory in the source formatting-preference example — “use bullets, not paragraphs” — is a markdown file loaded at run start, injected on every model call, and updated when the agent learns something worth keeping. Source excerpt:

agent = create_deep_agent(
    model="openai:gpt-6",
    memory=["/memories/AGENTS.md"],
    backend=backend,
    store=store,
)

Because that file lives in storage you control, the same backend pointed at a different provider next week still reads the same preferences. Swap the model, keep the memory.

Test recoverability, not just token savings

The most useful operator lesson comes from the January companion guide. It recommends stressing compression to see failure:

  • Trigger summarization at 10-20% of the window in evals, not 85%, to generate enough events to compare prompts. Adding explicit intent and next-steps fields improved continuation.
  • Run needle-in-the-haystack checks: plant a fact early, force summarization, then require recovery via filesystem search. If the agent cannot read back /conversation_history, compaction is not recoverable.
  • Monitor for goal drift. The failure is an agent that asks for clarification or declares done right after summarization. Frequent summaries on sample tasks surface it.

Apply that to the coding lane above: plant a failing test name early, force compaction mid-run, then check whether the final patch still targets that test and can cite the original log from disk. If it drifts, fix the summary prompt before lowering thresholds in production.

Replace truncation with offload-plus-preview, treat 20,000 tokens and 85% as starting points, move stable instructions into skills, give subagents a strict return contract, and own memory as a versioned file.

For surrounding discipline on scoping windows and fleet hygiene, see our context engineering playbook and subagent orchestration guide. Install to try is uv add deepagents, with a free LangChain Academy course for depth. Keep only what is needed now while file-backed detail stays retrievable and isolated subagent work returns only its contracted result.

Sources

  1. Context Engineering with Deep Agents: How To Remember Without Keeping Everything In Context
  2. Context Management for Deep Agents
  3. LangChain Blog