How the LangChain Deep Agents SDK prevents 'context rot' in long-running tasks through three compression techniques triggered at rising thresholds of the context window: offloading large tool results to a filesystem, offloading large tool inputs (write/edit arguments), and summarizing conversation history while preserving the full transcript on disk. Also covers evaluation — aggressive-triggering stress tests, needle-in-the-haystack recall tests, and watching for goal drift as the most insidious summarization failure.
Long-running agents fail in a specific way: the context window fills with the debris of past steps — full file reads, redundant tool arguments, stale conversation — and the model’s answers degrade. This is context rot. The LangChain Deep Agents SDK counters it with a filesystem abstraction the agent can offload to and retrieve from, plus a set of compression techniques that fire as the window fills.
The principle behind all of them is the same: reduce what’s in working memory while keeping everything recoverable from disk.
Three compression techniques
They trigger at rising thresholds of the context window, escalating from cheap to aggressive.
1. Offload large tool results. When a tool returns a large response — say, reading a big file — the SDK writes the full result to the filesystem and leaves only a file-path reference plus a short preview in active context. If the agent needs the detail, it reads it back with read_file or search. The result exists; it just isn’t clogging the window.
2. Offload large tool inputs. Write and edit operations leave large, already-persisted arguments sitting in history. Once context crosses a high threshold (around 85%), the SDK truncates those older tool calls and replaces them with a pointer to the file on disk — pruning data that’s redundant because it already lives elsewhere.
3. Summarize. When offloading isn’t enough, the SDK falls back to summarization, in two parts. An LLM writes a structured summary of the session — intent, artifacts created, next steps — and that replaces the full message history in working memory. Meanwhile the complete original transcript is written to the filesystem as the canonical record. The agent keeps high-level awareness of its goal while retaining the ability to search back for any specific detail.
Evaluating compression
Broad benchmarks are a poor way to test this, because compression events fire only occasionally in a normal run — you can’t isolate their effect. Two targeted approaches work better.
Stress-test by forcing it. Lower the compression threshold artificially — say to 20% of the window instead of 85%. That makes compression fire constantly, so you can isolate its impact and compare configurations (for instance, two summarization prompts) cleanly.
Test one mechanism at a time. A needle-in-the-haystack test plants a key fact early in a conversation, forces a summarization event, and then asks the agent to recall the fact later. If it succeeds, you’ve proven it can recover information from the filesystem after that fact left active context.
When you evaluate, focus on three things:
- Baseline — run the agent on representative tasks first, so you know what “working” looks like before compression.
- Recoverability — confirm critical information stays reachable after being offloaded or summarized.
- Goal drift — watch for the agent losing the user’s original intent after a summarization. This is the most insidious failure mode, and forcing frequent summarization is the fastest way to surface it.
Compression plus this kind of targeted evaluation is what lets an agent run for hours on a complex task without its context quietly rotting out from under it.
- Deep Agents
- Context Compression
- Context Rot
- Filesystem Offloading
- Summarization
- Needle-in-the-Haystack Test
- Goal Drift


More Guides
Run disciplined SEO A/B tests in seven steps — one metric, two variations, randomized segments, run to significance, track, analyze the winner, and iterate.
Build a topic cluster in seven steps — select and score a pillar, validate it, map subtopics, align to intent, architect internal links, publish, and measure.
Prepare your site for AI search in five steps — content architecture, entity consistency, E-E-A-T, structured data, and machine-readable structure.
Get your content cited by AI in seven steps — answer capsules, link-free extraction, original data, digital PR, community presence, consistent messaging, and tracking.
A seven-step walkthrough for setting up Google Search Console on a new site — property type, DNS verification, sitemap, GA4 link, users, URL checks, and a monitoring routine.