---
title: "Context Engineering (Agent Memory) for AI Agents Starts with Retrieval"
description: "Agent retrieval fails in three ways: inefficient searching, too much context at once, and irrelevant or stale context."
url: "https://swe.quest/articles/context-engineering-agent-memory-for-ai-agents-starts-with-retrieval-4b7268c3138eae87"
canonical: "https://www.langchain.com/blog/context-engineering-starts-with-retrieval"
source: "LangChain"
published: "2026-11-10"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["ai-agents","rag","llms","vector-search"]
---

# Context Engineering (Agent Memory) for AI Agents Starts with Retrieval

A post on [LangChain](https://swe.quest/sources/langchain.md), published 2026-11-10, 11 min read, How-to. Original: [https://www.langchain.com/blog/context-engineering-starts-with-retrieval](https://www.langchain.com/blog/context-engineering-starts-with-retrieval)

## Summary

Agent retrieval fails in three ways: inefficient searching, too much context at once, and irrelevant or stale context. The fix is to keep searches small and keep raw results out of the main agent's context window. Deep Agents does this with glob/grep before reads, paged read\_file (100 lines by default with offset/limit), and automatic offloading of tool results over ~20k tokens to files with a preview. For custom RAG tools, the recommended pattern is "retrieve, offload, delegate": write results to files, return only paths, and have parallel subagents read each file and return key facts with sources and dates. Other advice covers using grep with synonyms before semantic search, agentic rather than single-shot retrieval, skills for progressive disclosure, and treating retrieved text as untrusted.

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)
- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)

## Prerequisites

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

## Keywords

Deep Agents, LangChain, MCP, LangSmith, subagents, progressive disclosure

## 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.
- [Why We Rebuilt LangChain’s Chatbot and What We Learned](https://swe.quest/articles/why-we-rebuilt-langchain-s-chatbot-and-what-we-learned-903a9865b6131c52.md): LangChain · 2026-08-26 · Medium · 15 min read · AI agents, RAG & retrieval, LLMs, Documentation
  LangChain replaced chat.langchain.com's chunk-and-embed vector retrieval with tool-calling agents that search structured sources directly: full doc pages via Mintlify's API, a scan-titles-then-read pattern over the Pylon knowledge base, and ripgrep/tree/file-read tools over the codebase.
- [From Static Help Content to a RAG-Based Onboarding Agent for Partners](https://swe.quest/articles/from-static-help-content-to-a-rag-based-onboarding-agent-for-partners-c0de8cedba3db499.md): Booking.com Data Science · 2026-10-19 · Medium · 9 min read · RAG & retrieval, AI agents, Evaluation, LLMs
  Booking.com's registration-flow chatbot for self-managed partners gave weak answers even though retrieval surfaced the right documents, and the cause turned out to be upstream data quality rather than the model.
- [Context Management for Deep Agents](https://swe.quest/articles/context-management-for-deep-agents-dc1d776470c6aad5.md): LangChain · 2026-10-13 · Medium · 5 min read · AI agents, LLMs, Evaluation
  The Deep Agents SDK manages long-running agent context with three compression techniques triggered at fractions of the model's context window.
- [Unlocking dependable responses with Gemini Enterprise Agent Platform’s Agentic RAG](https://swe.quest/articles/unlocking-dependable-responses-with-gemini-enterprise-agent-platform-s-agentic-1fa2162940afaaba.md): Google Research · 2026-06-05 · Easy · 8 min read · RAG & retrieval, AI agents, LLMs, Evaluation
  Google's agentic RAG framework, now in public preview on Gemini Enterprise Agent Platform, extends multi-agent retrieval (orchestrator, planner, query rewriter, search fanout) with a Sufficient Context Agent.

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)
