Deep Agents Uses Five Middleware Techniques to Prevent Context Rot in Long-Running LLM Tasks

·2026.10.10 02:00

Key point

The open-source harness moves context out of the active window using offloading, summarization, skills, subagents, and long-term memory.

1 / 7

Details

Long-running agents suffer from context rot, where accumulating history and tool outputs degrade model accuracy. Deep Agents, LangChain's open-source agent harness, addresses this by using middleware to strategically move context out of the active window without deleting it, ensuring the model receives the right information at the right time.

Core Context Management Techniques

The harness employs five specific strategies to manage the context window:

  • Offloading: Large tool results (over ~20,000 tokens) and user messages (over 50,000 tokens) are written to the filesystem. The model sees only a preview and file path, retrieving full data via read_file when needed.
  • Summarization: When token usage hits 85% of the context window, older messages are condensed into a summary by a separate LLM call. The original messages are saved to /conversation_history/{session_id}.md for recovery.
  • Skills: Specialized instructions are stored in folders and loaded via progressive disclosure. The model sees only skill names and descriptions until it explicitly decides to load the full instructions.
  • Subagents: Noisy tasks, such as deep research, run in isolated context windows. The subagent processes raw data and returns only concise results to the main agent, keeping the primary context clean.
  • Long-term Memory: Agent learnings are persisted in markdown files (e.g., /memories/AGENTS.md). These files are loaded at the start of a run and injected into the system prompt, allowing preferences to survive across conversations.

Provider Agnosticism and Implementation

Because memory is stored as plain files in user-controlled storage, Deep Agents is provider-agnostic. Users can switch models or providers (e.g., from OpenAI to another) while retaining all learned context and preferences. The techniques are implemented via middleware hooks that intercept the agent loop before model calls or tool executions, requiring no custom code for standard use cases.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.