---
title: "Context Management for Deep Agents"
description: "The Deep Agents SDK manages long-running agent context with three compression techniques triggered at fractions of the model's context window."
url: "https://swe.quest/articles/context-management-for-deep-agents-dc1d776470c6aad5"
canonical: "https://www.langchain.com/blog/context-management-for-deepagents"
source: "LangChain"
published: "2026-10-13"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 5
tags: ["ai-agents","llms","evals"]
---

# Context Management for Deep Agents

A post on [LangChain](https://swe.quest/sources/langchain.md), published 2026-10-13, 5 min read, Deep dive. Original: [https://www.langchain.com/blog/context-management-for-deepagents](https://www.langchain.com/blog/context-management-for-deepagents)

## Summary

The Deep Agents SDK manages long-running agent context with three compression techniques triggered at fractions of the model's context window. Tool results over 20,000 tokens are offloaded to a filesystem and replaced with a path plus a 10-line preview. Old write/edit tool inputs are replaced with file pointers once context passes 85%, and summarization runs as a last resort, producing a structured summary while saving the full history to disk for later retrieval. To evaluate these mechanisms, the team forces compression early (10-25% of the window) to generate more events and uses targeted evals such as needle-in-the-haystack recovery to catch goal drift and lost details.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Evaluation](https://swe.quest/tags/evals.md) (AI & ML)

## Prerequisites

- LLM context windows ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- tool-calling agents ([easy posts on AI agents](https://swe.quest/tags/ai-agents.md?difficulty=easy))

## Keywords

Deep Agents, LangChain, terminal-bench, LangSmith, Claude Sonnet 4.5

## Related posts

- [Context Engineering with Deep Agents: How To Remember Without Keeping Everything In Context](https://swe.quest/articles/context-engineering-with-deep-agents-how-to-remember-without-keeping-everything-1dc293ec006d2b0c.md): LangChain · 2026-11-10 · Medium · 9 min read · AI agents, LLMs
  Long-running agents suffer "context rot" as tool output, history and instructions accumulate, so Deep Agents moves context out of the active window via middleware hooks in the agent loop rather than deleting it.
- [Building Long-Running Agents with ScaleDown and Deep Agents](https://swe.quest/articles/building-long-running-agents-with-scaledown-and-deep-agents-76e2d7318050ea78.md): LangChain · 2026-10-13 · Medium · 9 min read · AI agents, LLMs, Python
  The langchain-scaledown integration offloads context-management decisions in long-running agents (summarizing history, compressing tool results, extracting fields, classifying state) from frontier LLMs to ScaleDown's small, task-specific constrained decoding models, which ScaleDown reports are far faster and cheaper on these narrow tasks.
- [DeepSeek-V4: a million-token context that agents can actually use](https://swe.quest/articles/deepseek-v4-a-million-token-context-that-agents-can-actually-use-4aebeb5a933f7a88.md): Hugging Face · 2026-04-24 · Hard · 7 min read · LLMs, Inference & serving, AI agents, Model training
  DeepSeek-V4 (Pro: 1.6T total/49B active; Flash: 284B/13B active) is a MoE model family whose 1M-token context is made practical by a hybrid attention design that interleaves Compressed Sparse Attention (4x KV compression plus an FP4 lightning indexer selecting top-k blocks) with Heavily Compressed Attention (128x compression with dense attention), plus FP8 KV storage.
- [Building Deep Research: How we Achieved State of the Art](https://swe.quest/articles/building-deep-research-how-we-achieved-state-of-the-art-414ffb743a73bb80.md): Hugging Face · 2025-11-24 · Medium · 7 min read · AI agents, LLMs, Evaluation
  Tavily's deep research agent reached state of the art on DeepResearch Bench while using 66% fewer tokens than LangChain's Open Deep Research, mainly through context engineering.
- [Context Engineering (Agent Memory) for AI Agents Starts with Retrieval](https://swe.quest/articles/context-engineering-agent-memory-for-ai-agents-starts-with-retrieval-4b7268c3138eae87.md): LangChain · 2026-11-10 · Medium · 11 min read · AI agents, RAG & retrieval, LLMs, Vector search
  Agent retrieval fails in three ways: inefficient searching, too much context at once, and irrelevant or stale context.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
