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

LangChain published a guide on retrieval for AI agents, arguing that context engineering should begin with how an agent finds information rather than what it does once text is already in its window. The post walks through the retrieval problems agents face and the techniques its Deep Agents harness applies by default, using a competitive-analysis agent that researches hundreds of competitors each Monday as the running example.
The argument rests on a familiar constraint: agents have a limited context window and must retrieve rather than memorize. LangChain identifies three failure modes. Searching is inefficient when an agent opens every file to see what is inside or keeps rewording the same query, burning tokens and time on failed attempts. A single search can also return far too much at once, such as a full market data export, leaving no room for the actual work. And retrieved material can be irrelevant or stale, which is especially costly because models treat off-topic or outdated text as convincingly as correct text, letting a bad fact propagate through later steps.
The first remedy is picking a tool matched to the job. Plain filesystem searching is wasteful if the agent reads files just to inspect them, since every read lands in context. Instead, Deep Agents ships glob, which matches file names by pattern, and grep, which searches inside files without loading them and can return matching files, matching lines or counts. Both are built in alongside ls, read_file, write_file and edit_file. Because these tools go through the agent's backend, they behave the same whether files sit in agent state, local disk, a persistent store or a sandbox.
Keyword search has an obvious ceiling: grep matches literal text, so searching a news archive for "Company A funding" would miss an article headlined with a Series B raise. For meaning-based lookup, developers add a retrieval tool backed by a vector store. LangChain notes that a retrieval tool can also sit on a SQL database for structured lookups, a search API for fresh web information, or an MCP server exposing someone else's tooling such as documentation search.
When the agent searches matters too. A fixed search-then-answer pipeline suits an FAQ bot but not a research agent that discovers an unknown product launch midway through and needs its pricing. Deep Agents already runs the agentic pattern by default: the agent loops and can call any tool as many times as it needs. Search know-how can be packaged as a skill, a set of instructions covering which index to use, how to phrase queries and how to format citations. Skills use progressive disclosure, so the agent sees only a name and short description until a task requires the full instructions, keeping them out of context the rest of the time.
The second problem is volume. When the agent needs one revenue figure from a 40,000-row export, loading the whole thing is untenable. read_file returns one page at a time, 100 lines by default, and accepts an offset and limit so the agent can jump to the relevant region after grepping for a match. If a tool result still exceeds roughly 20,000 tokens, the harness writes it to a file under /large_tool_results/ and hands back the path plus a preview of the first and last few lines, which the agent can page through later.
Custom retrieval tools can adopt the same discipline deliberately. LangChain's "retrieve, offload, delegate" pattern has the tool run its search, save each result as a file in the agent's backend and return only the paths. A sample search_news tool runs a four-document similarity search, uploads the contents as files under /retrieved/ and replies with the saved paths, so the main agent sees four short strings instead of four full articles.
Keeping the wrong articles out of the main agent's context takes a third step. Even after offloading, the main agent would have to read the files to judge relevance, and anything off-topic it opens enters its window. A subagent handles that filtering: a chunk-analyst defined with a name, a description telling the main agent when to invoke it and a system prompt instructing it to read one assigned file and return key facts plus a source URL. The main agent is created with the retrieval tool, the subagent and the same backend instance, so the subagent can read the offloaded files. The flow becomes search, delegate each path to an analyst that may run in parallel, then synthesize the returned summaries and search again if gaps remain. Noisy reading happens in subagents' own context windows, and the main agent sees only conclusions.
Delegation cures irrelevance but not staleness, since a monthly index will not catch this week's news. LangChain suggests a search API or MCP server for current information, or date filtering inside the retrieval tool when the data carries dates. It also warns that relevant, fresh results bring risk: retrieved text is data, not instructions, so it can carry prompt injection, and no prompt or delimiter strategy fully prevents that. Output validation, such as checking that answers cite expected sources and that claims match them, is the suggested mitigation. The post closes with general guidance: use the most efficient tool that works, page rather than load, return pointers rather than payloads, delegate reading to subagents, and verify grounding while treating retrieved text as untrusted. Deep Agents installs with uv add deepagents, and LangChain is holding a live session on the topic on November 9th.
Why it matters: The advice applies directly to teams building research or analysis agents, where context spent on clumsy searching is context unavailable for reasoning, and the specific thresholds and patterns give concrete defaults to copy. The subagent split in particular changes how a single agent's memory pressure is distributed, though it trades main-agent clarity for extra orchestration and per-file latency. Treating retrieved content as untrusted is a security requirement as much as a quality one, in my reading, and is likely to become a standard review point for agent designs that pull from the open web.
Based on reporting from the original publisher. Visit the source for full context and later updates.
Publisher excerpt
Agents waste time and context on clumsy searches, oversized results and stale data. Learn the retrieval techniques LangChain's Deep Agents harness uses to get the right context in.