How does LangChain approach context engineering?

Short answer

LangChain's July 2025 post "Context Engineering" sorts the work into four strategies: write context outside the window (scratchpads, memories), select it back in (retrieval of memories, tools and knowledge), compress it (summarization, trimming) and isolate it (sub-agents, sandboxes, hidden state fields). LangGraph and the LangChain v1 docs map those strategies onto state, a long-term store, summarization and middleware.

The framing: the context window as RAM

LangChain’s post “Context Engineering” (July 2, 2025, by the LangChain team) compares the model to a CPU and the context window to its RAM. Context engineering is deciding what fills that RAM at each step. It quotes Andrej Karpathy’s description: the “delicate art and science of filling the context window with just the right information for the next step.” The context has three kinds of content: instructions, knowledge and tool feedback.

The post then sorts everything teams do about this into four strategies. That split is LangChain’s main contribution: a vocabulary you can apply to any agent, not only one built with LangChain.

An earlier LangChain post, “The rise of context engineering” by Harrison Chase (June 23, 2025), makes the relation to prompt engineering explicit: prompt engineering is a subset of context engineering, because even with all the context in hand, how you assemble it in the prompt still matters. It also names poor communication with the model as often the root cause of agent errors, and points to LangSmith tracing, which shows the exact inputs and outputs of each model call, as the way to check whether the model actually received the right data and tools.

The four strategies

Strategy What it means Techniques In LangGraph
Write Save context outside the window Scratchpads during a task, memories across sessions Checkpointed state, long-term memory store, LangMem
Select Pull the right context back in Load memories, retrieve relevant tools, RAG over knowledge Per-node state access, store retrieval, LangGraph Bigtool
Compress Keep only the tokens you need Summarization, trimming older messages Summarization and trimming utilities, summary nodes
Isolate Split context over components Sub-agents, sandboxes, state fields the model does not see State schemas, E2B and Pyodide sandboxes, supervisor and swarm libraries

Write. A scratchpad holds notes during a task, as a file or a field in the agent’s state. Memories last across sessions; the post names ChatGPT, Cursor and Windsurf as products that generate long-term memories automatically.

Select. Small, always-relevant memories (instructions and examples) can be files that always load, like CLAUDE.md or Cursor rules. Larger collections need retrieval through embeddings or knowledge graphs. Selection also applies to tools: retrieving only the relevant tool descriptions, which the post says research found improves tool selection roughly threefold. And it quotes a Windsurf engineer that “embedding search becomes unreliable as a retrieval heuristic as the size of the codebase grows”, which is why coding agents combine grep, knowledge graphs and re-ranking.

Compress. Claude Code’s auto-compact, which summarized the trajectory past 95 percent of the window at the time of the post, is the example. Summarization can also shrink a heavy tool result or a hand-off between agents. Trimming is the rule-based cousin: drop older messages.

Isolate. Sub-agents each get their own window and a narrower task. The cost is tokens: the post cites Anthropic’s finding that multi-agent systems can use up to 15 times more tokens than chat. Sandboxes keep heavy objects out of the context, and a state schema can keep fields hidden from the model.

How the LangChain docs build on it

The LangChain v1 documentation defines context engineering as “providing the right information and tools in the right format so the LLM can accomplish a task”, and names missing context, more than model capability, as the main reason agents are unreliable. It splits context into three types:

  1. Model context: what goes into each call (system prompt, messages, tools, model, response format). Transient.
  2. Tool context: what tools read and write in state, store and runtime context. Persistent.
  3. Life-cycle context: what happens between calls, such as summarization, guardrails and logging. Persistent.

Middleware is the main mechanism to change any of these. State is short-term memory per conversation; the store is long-term memory across conversations.

The common misunderstanding

The four strategies are often read as a menu: pick compression, or pick retrieval. They work as a cycle. What you compress is lost unless you wrote it somewhere first, and what you write is useless unless you can select it later. The failure modes LangChain borrows from Drew Breunig show why selection is the hard part: poisoning (a hallucination gets saved and reloaded), distraction, confusion (too much irrelevant context) and clash (two parts of the context disagree). A memory that writes everything and selects badly produces exactly those.

What this means for a team

LangGraph’s store is per application. If one team builds a LangGraph agent and another uses Claude Code and ChatGPT, each has its own write and select layer, and what one learns the others do not see. The Write column is where team knowledge should live once, so that every tool can Select from it. More in What is a context graph? and Is RAG the same as AI memory?; for the practitioner view, see What did Manus learn about context engineering?

Where Bombos fits

In LangChain’s terms, Bombos is a shared Write and Select layer for a whole team. It is a plugin that gives every AI tool your team uses, including your own LangGraph agents, Claude Code, ChatGPT and Cursor, one memory: a context graph with team knowledge and learned rules, retrieved per question by similarity, keywords and graph proximity, with a visible trail of what each answer used. It runs in our cloud or on your own server, and one person can start with it for their own agents.

Related questions

Who came up with the four context failure modes LangChain mentions?

LangChain credits Drew Breunig for context poisoning (a hallucination enters the context), distraction (the context overwhelms the training), confusion (superfluous context influences the answer) and clash (parts of the context disagree).

Do I need LangGraph to use write, select, compress and isolate?

No. The four strategies are a way to think about any agent; Claude Code, Cursor and others use them too. LangGraph offers built-in pieces for each, such as checkpointed state, a long-term store and summarization utilities.

What is the difference between state and store in LangChain?

State is short-term memory scoped to one conversation, such as current messages and tool results. The store is long-term memory that persists across conversations, such as user preferences and extracted insights.

What does LangChain mean by transient and persistent context?

Transient context is what the model sees in one call; changing it does not alter saved state. Persistent context is what gets saved across turns, for example through tool writes or life-cycle hooks such as summarization.

Sources

  1. Context Engineering (LangChain blog, July 2, 2025)
  2. Context engineering in agents (LangChain docs)
  3. The rise of context engineering (LangChain blog, Harrison Chase, June 23, 2025)
The first half hour · free

What does your AI forget?

  1. 01You tell us which AI you use and where it keeps starting over.
  2. 02We show what a shared memory changes there, on your own examples.
  3. 03You keep the plan, with or without Bombos.
Piet Baudoin
Piet BaudoinYou talk to Piet, from the Bombos teamDutch team from Utrecht and Nijmegen · data in Europe
We reply the same working day.