AivexaNewsSearch
AI news for builders and product teamsChecked every hour

Context Engineering with Deep Agents: How To Remember Without Keeping Everything In Context

Collected Oct 14, 2026

LangChain has published a walkthrough of how its open source agent harness, Deep Agents, manages the context window of long-running agents. The post frames the problem as "context rot": as an agent takes on longer tasks it accumulates instructions, tool results and files until the volume exceeds what a model can comfortably hold, and the more history, noise and tool output a model carries, the worse its accuracy and reasoning tend to get. Deep Agents addresses this with five techniques that move context out of the active window without deleting it, so the raw data stays recoverable.

The post describes an agent as a model plus a harness, and sorts context engineering into two jobs: keeping unnecessary information from entering the window, and filtering what is already there. Deep Agents is provider agnostic and wraps whichever model the developer chooses.

The first technique is offloading, implemented by a FilesystemMiddleware that runs on every tool call. When a tool result exceeds roughly 20,000 tokens, the full result is written to a path under /large_tool_results/ keyed by tool call ID before it reaches the conversation. The model sees only a short preview, described as the first and last few lines, plus the file path; it can later page through the stored file with a read_file tool. Oversized human messages, such as a pasted call transcript, get the same treatment at a higher threshold of 50,000 tokens and are saved under /conversation_history/. The rationale is that truncation is lossy while offloading keeps the data retrievable.

The second technique is summarization, handled by SummarizationMiddleware, which checks token usage immediately before each model call. Once usage crosses a threshold — 85 percent of the model's context window by default — a separate LLM call condenses older messages into a single summary. Older messages leave the window while the most recent ones are kept verbatim, and the summary is presented before those recent messages so nothing recent is paraphrased. Two properties matter: the summarized messages are written to /conversation_history/{session_id}.md so the agent can read a detail back if it needs one, and the process cycles, with each new summary folding in the previous one as usage climbs again. LangChain notes summarization can also be triggered on topic changes rather than only a token threshold, and that the summarization prompt is customizable.

Skills are the third technique. A skill is a folder of instructions, optionally with scripts and reference documents, for a specialized task such as a quarterly business review report format. SkillsMiddleware scans the skills folder before the agent starts and reads only the header of each SKILL.md, then adds those names and descriptions to the system prompt on every model call. The full instructions enter context only when the model decides a skill is relevant and reads the file. The post calls this progressive disclosure: the model sees a menu up front and pulls in the full recipe when needed, so ten skills cost roughly as much context as ten one-liners. The trade-off is that instructions only enter the window when the model judges them relevant, so that judgement becomes load-bearing.

Subagents isolate work the developer already knows will be noisy. SubAgentMiddleware lets each subagent carry its own system prompt and tool set; LangChain's example defines a market-researcher with a pull_market_report tool and an instruction to return three short bullet points rather than the raw report. The main agent hands off a company, the subagent reads the full report in its own window and returns only the bullets, so the main agent never sees the raw data or even a preview. Because subagent tasks tend to be small and well scoped, the post notes they can often run on a cheaper model and in parallel.

The fifth technique is long-term memory, a markdown file the agent is pointed at with one argument. MemoryMiddleware reads the file at the start of a run, injects its contents into the system prompt on every model call, and updates the file when the agent learns something worth keeping, such as a preference for bullet points over paragraphs. Because that memory is a plain file in storage the developer controls rather than something a model provider holds, the same backend and memory file can be pointed at a different model or provider while everything the agent has learned carries over.

Most of these behaviors are built in, so developers do not need to write middleware unless they want to customize something. Middleware is code plugged into points in the agent loop — before the agent starts, around each model call, or around each tool call — where it can read and modify context before the next step. Installation is via uv add deepagents. LangChain also points to a live instructor session on November 3 and a free self-paced Deep Agents course on LangChain Academy, and promotes LangSmith, its agent engineering platform, for debugging agent decisions, evaluating changes and deployment.

The post closes with general guidance: offload large inputs rather than truncating them, keep compaction recoverable, load task know-how on demand, isolate noisy work in subagents, own the memory so it survives a model switch, and keep thresholds customizable because defaults that suit one task rarely suit every task.

Why it matters: teams building long-running agents hit context limits not as a single wall but as a gradual accuracy decline, and this post offers concrete defaults — a 20,000-token offload threshold, a 50,000-token human-message threshold, summarizing at 85 percent usage — that developers can adopt or tune today. The provider-agnostic, file-based memory is the most strategically interesting piece: it suggests agent state can outlive a given model vendor, which lowers switching costs, though it also means developers take on storage and retrieval design themselves. The techniques are complementary rather than competing, so the practical work is deciding which noise to keep out and which history to compact.

Read at LangChain

Based on reporting from the original publisher. Visit the source for full context and later updates.

Publisher excerpt

Long-running agents degrade as context piles up. Learn how offloading, summarization, skills, subagents, and memory keep your agent's context window focused.