# How Deep Agents Manages Context: Offloading and Summarization

## Executive summary

This video details 'context rot,' the degradation of an AI agent's reasoning and accuracy due to excessive context accumulation. Deep Agents, an open-source agent harness, addresses this through two primary context engineering techniques: offloading and summarization. Offloading intercepts massive inputs (like tool results or long documents) by saving them to a virtual file system and only providing the model with a preview. Summarization, conversely, runs before model calls to condense the entire context window, keeping the model focused while preserving the full history in a summarized format.

## Key takeaways

- Context Rot Defined: Context rot occurs when an agent processes too much history, noise, and tool output, overwhelming the model's context window and degrading its reasoning and accuracy. (0:00)
- Offloading Mechanism: Offloading prevents large inputs from entering the context window. Tool results exceeding 20,000 tokens are saved to a virtual file system (e.g., `large_tool_results`), allowing the model to access the full data via a read file tool using only a preview. Long human messages (over 50,000 tokens) use a similar process, saving data to `conversation_history`. (1:33)
- Summarization Mechanism: Summarization condenses the entire context window to manage token usage. It runs before every model call, typically when token usage crosses the default 85% threshold. Content above the 'keep cutoff' line is summarized and saved, while the summary is sent to the model, keeping the context compact. (2:37)

## Technical details

- Deep Agents Architecture: Deep Agents is an open-source agent harness built with context engineering techniques, including offloading, summarization, skills, subagents, and long-term memory, designed for long-running tasks. (0:29)
- Offloading Thresholds: Tool results over 20,000 tokens are offloaded to `large_tool_results`. Human messages over 50,000 tokens are offloaded to `conversation_history`. (1:33)
- Summarization Thresholds: Summarization is triggered by default when token usage reaches 85%. The check runs before every model call, and the process involves summarizing content above the 'keep cutoff' line. (2:37)

## Practical implications

- Build engineers can design more robust and scalable AI agents capable of handling long-running tasks without suffering from context rot.
- Implementing offloading and summarization techniques allows for the management of massive tool outputs (e.g., database queries, large documents) while maintaining model focus.
- The ability to control context thresholds (e.g., 85% for summarization) provides fine-grained control over resource usage and model performance.

## Topics

Large Language Models (LLMs), Agent Architecture, Context Management, Context Rot, LangChain, Deep Agents, Introduction to Deep Agents (free LangChain Academy course), Context engineering in Deep Agents (docs), Context Management for Deep Agents (blog)

Source: https://www.youtube.com/watch?v=Ud5RsBegyfw
