Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

LangChain 11 min read How-to mediumAdept

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

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.

Related posts

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

    LangChain mediumAdept

    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. FilesystemMiddleware offloads tool results over ~20,000 tokens (and user messages over 50,000) to files and shows only a preview. SummarizationMiddleware condenses older messages at 85% of the context window while keeping recent ones verbatim and writing the originals to recoverable files. SkillsMiddleware uses progressive disclosure to load task instructions only when relevant, subagents isolate noisy work in separate contexts, and MemoryMiddleware persists learned preferences in a plain markdown file that survives switching model providers.

  • Why We Rebuilt LangChain’s Chatbot and What We Learned

    LangChain mediumAdept

    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. A fast createAgent with Claude Haiku 4.5 handles most docs questions in 3-6 tool calls and under 15 seconds. A Deep Agent with separate docs, knowledge-base and code subagents handles implementation questions in 1-3 minutes, with each subagent filtering its results so the orchestrator's context stays small. The rebuild removed constant reindexing, kept document structure intact and produced verifiable citations down to line numbers, with LangSmith traces used to tune prompts and cut wasted tool calls.

  • From Static Help Content to a RAG-Based Onboarding Agent for Partners

    Booking.com Data Science mediumAdept

    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. A manual audit of the embedding store found navigation and breadcrumb noise, chunks too small to carry needed context, and irrelevant partner-specific content. These fixes were built into the periodic ingestion script, and the agent was re-architected to choose among separate retrievers: general help articles, a registration-process knowledge base with rephrase-and-retry, and pre-approved templated answers for legally sensitive questions. In an A/B experiment scored across about 2,000 conversations, LLM-judged task completion rose 1.33x and answer relevance and refusal rate improved, with the lesson that automated judges flag weak retrieval but human inspection of retrieved chunks is needed to find the fix.

  • Context Management for Deep Agents

    LangChain mediumAdept

    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.

  • Unlocking dependable responses with Gemini Enterprise Agent Platform’s Agentic RAG

    Google Research easyNovice

    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. That agent inspects retrieved snippets and a draft answer, identifies exactly which parts of the query lack supporting evidence, and feeds targeted gaps back to the query rewriter for further retrieval rounds before final synthesis. On the FRAMES-based FramesQA benchmark (824 multi-hop queries, 2,676 PDFs), it improves accuracy by up to 34% over a vanilla RAG Engine baseline. In a cross-corpus setting with three distractor corpora it reaches 90.1% accuracy, nearly matching single-corpus results with latency within about 3%.

The quest for software engineering knowledge.

Look:
Layout: