Context Management for Deep Agents

LangChain published a technical explanation of how its open source Deep Agents SDK manages context for tasks that run longer than a model's context window. The post is credited to Chester Curme and Mason Daugherty. Deep Agents is described as LangChain's batteries-included agent harness: it lets developers build agents that plan, spawn subagents, and operate on a filesystem to carry out complex, long-running work. Because those tasks routinely exceed the context limits of the underlying model, the harness ships with several context compression mechanisms.
The term the post uses is context compression: reducing the volume of information in an agent's working memory while keeping the details needed to finish the task. That can mean summarizing earlier interactions, dropping stale information, or deciding what to keep and what to throw away. The framing problem is what the post calls context rot, alongside the finite memory constraints of large language models. Deep Agents exposes a filesystem abstraction supporting listing, reading, writing, search, pattern matching and file execution, and agents use it to retrieve content they previously offloaded.
Three compression techniques are implemented, triggered at different frequencies. First, large tool results are offloaded to the filesystem whenever they occur. Second, large tool inputs are offloaded once the context crosses a threshold: old write and edit arguments from tool calls are moved to disk. Third, when the context crosses the threshold and no more context is eligible for offloading, the SDK runs a summarization step over the message history. The thresholds are expressed as fractions of the model's context window size, which the SDK reads from LangChain's model profiles to obtain the token limit for a given model.
Tool results are the first target. A response from a tool invocation, such as reading a large file or making an API call, can on its own exceed a model's context window. When Deep Agents detects a tool response larger than 20,000 tokens, it writes the response to the filesystem and substitutes a file path reference plus a preview of the first 10 lines. The agent can then re-read or search that content when it needs it.
The second target is tool inputs. File write and edit operations leave tool calls behind in the conversation history that contain the complete file content, even though that content is already persisted on disk and largely redundant. Once session context crosses 85% of the model's available window, Deep Agents truncates older calls of this kind, replacing them with a pointer to the file.
Summarization is the fallback when offloading no longer frees enough space, and it has two parts. An LLM generates a structured summary of the conversation covering session intent, artifacts created and next steps, and that summary replaces the full history in working memory. Separately, the complete original messages are written to the filesystem as a canonical record. The combination is meant to keep the agent aware of its goals and progress through the summary while preserving the ability to recover specific details through filesystem search; the post points to a trace where the model calls read_file to fetch previously offloaded messages.
The post is candid that measuring whether these techniques help is hard: on real-world tasks, and on benchmarks such as terminal-bench, compression events may fire only sporadically, making their individual impact difficult to isolate. LangChain's answer is to deliberately make the features fire more often. Triggering summarization at 10 to 20% of the available context window is described as likely suboptimal for overall performance, but it produces far more summarization events, which makes configurations comparable. Using that technique, the team says it could see how small changes to the summarization prompt, specifically adding dedicated fields for session intent and next steps, improved performance. A cited figure plots token use over time for sample runs of Claude Sonnet 4.5 on terminal-bench-2: a green line shows a sharp token drop near turn 20 when a summarization event compresses history, while an orange line shows a smaller reduction near turn 40 when a large file write tool call is evicted. Those runs triggered compression at 25% of the context window rather than the 85% default.
The SDK also maintains targeted evaluations that isolate individual mechanisms rather than measuring broad task-solving ability. One class of test forces summarization mid-task and checks whether the agent keeps going, on the theory that summarization must preserve not just agent state but its trajectory. Another plants a needle-in-the-haystack fact early in a conversation, forces a summarization event, and then requires the agent to recall that fact later; because the fact is no longer in active context, it must be recovered through filesystem search. These are described as integration tests for context management that cut iteration time and make failures attributable to a specific compression mechanism.
The closing guidance generalizes the approach: start from real-world benchmarks to establish a baseline, then stress-test individual features by triggering compression aggressively, at 10 to 20% of context rather than 85%, to amplify the signal from each feature; test recoverability, since compression only helps if critical information stays reachable; and watch for goal drift, the failure mode where an agent loses the user's intent after summarization and asks for clarification or wrongly declares the task complete. The post notes that all features of the Deep Agents harness are open source.
Why it matters: teams building long-running agents inherit a concrete set of defaults from this work, including a 20,000-token offload trigger and an 85% window threshold, that they can copy or tune in their own harnesses. The emphasis on recoverability and goal drift is a reminder that compression changes what an agent can still see, so evaluation needs to check both that the objective survives and that offloaded details remain retrievable. The suggested practice of forcing frequent summarization is a cheap way for developers to make compression behavior observable in CI, though the post itself notes that such aggressive settings are not the ones you would ship.
Based on reporting from the original publisher. Visit the source for full context and later updates.
Publisher excerpt
Learn how Deep Agents SDK manages context for long-running AI tasks through offloading, summarization, and filesystem abstraction to prevent context rot.