Practices

Context Engineering with Deep Agents: How To Remember Without Keeping Everything In Context

LangChain Blog
Practices

LangChain's Deep Agents harness attacks context rot with five built-in middleware techniques: offloading large tool results, summarizing old turns, loading skills on demand, isolating noisy work in subagents, and persisting memory to a file.

Key points

  • Context rot: as history and tool output pile up, accuracy and reasoning degrade on long tasks.
  • Tool results above roughly 20,000 tokens go to /large_tool_results/{tool_call_id} and the model sees only a preview.
  • SummarizationMiddleware condenses older messages once usage crosses 85% of the window, keeping recent turns verbatim.
  • Skills load lazily: only SKILL.md headers sit in the system prompt until the model decides one is relevant.
  • SubAgentMiddleware runs noisy research in its own window and often on a cheaper model, in parallel.
  • Memory is a markdown file such as /memories/AGENTS.md, so swapping provider keeps the same notes.

Real-world use

  • A weekly competitive analysis agent that pulls tens of thousands of rows of market data for five companies and drafts a team report.
  • A sales team's quarterly business review template packaged as a skill so it loads only when a QBR comes up.
  • A user preference such as bullet-point summaries persisted in a memory file across weekly runs and, later, across model providers.

This summary was generated by the agent from the original post on LangChain Blog. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message