Long-running agents stop drowning in context: LangChain moves memory into files that survive a model swap
Synopsis
LangChain's open source Deep Agents harness applies five context engineering techniques against context rot in long tasks: offloading oversized tool results and user messages to the filesystem, summarizing history near the limit, loading skills on demand, isolating noisy work in subagents, and keeping long-term memory as a plain file. Information is moved out of the active window rather than deleted and can be read back, so memory lives in storage the user controls and survives a model or provider switch.
Interpretation
A long-running agent can move most of its context out of the active window instead of deleting it, avoiding the accuracy drop that grows as a task gets longer. The prior condition is that the model carries all history, tool output and intermediate drafts through every call, so the information pile grows until it exceeds what the context window can comfortably hold. A competitive analysis agent that researches five competitors every Monday and writes a report in the team template has, by step four, carried five raw data exports, dozens of search results and two stale drafts through every model call, most of it irrelevant to formatting the final report.
The techniques plug into the agent loop as middleware that reads and rewrites context around model calls and tool calls. Middleware is code inserted at specific points in the loop that can change context before the next step runs, rather than requiring the whole agent to be rewritten. FilesystemMiddleware writes a full tool result to /large_tool_results/{tool_call_id} once it exceeds roughly 20,000 tokens, leaving the model a short preview of the first and last lines plus the path; oversized user messages get the same treatment at a 50,000-token threshold and go to /conversation_history/.
Summarized history stays recoverable, and long-term memory is a plain file in the user's own store. SummarizationMiddleware checks token usage before each model call and, at 85% of the model's context window by default, a separate LLM call condenses older messages into one summary while recent messages are kept verbatim. Summarized messages are written to /conversation_history/{session_id}.md so the agent can read back Company A's research while drafting, and the memory file is read at the start of a run and injected into the system prompt, so a different model or provider can read the same file.
Perspective
The techniques target long-running agents that work across many steps and tools, especially where large tool outputs and intermediate drafts accumulate, such as a research agent producing periodic reports in a fixed template. Memory is stored as a plain file in storage the user controls, so the same memory can be read after a model or provider switch. The thresholds and file paths given are defaults, and the material states that defaults should be customizable because thresholds suited to one task rarely suit every task.
Context rot is described as a tendency for accuracy and reasoning to worsen as history, noise and tool output accumulate, without a quantified curve. Summarization triggers at 85% usage by default, a threshold explicitly called a default, with the note that summarization can also fire on topic changes rather than only at a token threshold and that the summarization prompt can be customized. Offloading and summarization are emphasized as recoverable rather than lossy truncation, but the material does not state the practical cost of reading data back during a long run.
