Scrape Info

Memory and Context Management in Long Research Sessions

Memory systems fail not because context windows are small, but because models lose signal in noise.

Editor at Large · · 10 min read
Cover illustration for “Memory and Context Management in Long Research Sessions”
Research Agents · August 19, 2026 · 10 min read · 2,169 words
Long research sessions with AI agents fall apart even when the context window is huge. Token count alone doesn't explain why; the real culprit is what happens to a model's attention as that window fills, plus a hard ceiling on how many things any model can juggle at once. Fix that, and the token limit stops mattering nearly as much as everyone thinks. Back in early 2023, most models capped out around 4,000 to 8,000 tokens. By 2025, the leading models handle context windows anywhere from 128,000 tokens up to 2 million. On paper, that should've solved the "agent forgets everything" problem for good, but it didn't, and the reason is a thing people in this field call context rot: bigger windows don't fix long sessions, because the failure was never about window size. ## What "memory" actually means for an AI research agent Start with the awkward part: a stateless language model has zero memory by default, and every call starts from scratch. There's no thread connecting facts, no memory of what worked an hour ago, no record of the dumb mistake it made three steps back. Each prompt is a fresh amnesiac waking up and getting handed a stack of papers with no context for any of it. The field borrowed a three-part memory split from cognitive science, and it holds up: - **Episodic memory** covers specific events: what happened, when, in what order. Old session transcripts live here. - **Semantic memory** holds distilled facts, the stuff you've pulled out of those events once you know it's actually true. - **Procedural memory** is know-how. It covers which tool to try first, how to recover when a search comes back empty, the playbook the agent's built up over time. Why split these apart at all? Because an agent that treats "the thing I skimmed on a random blog" the same as "the thing I've checked three separate times" will contradict itself mid-session, or worse, state a wrong answer with total confidence. Deciding which bucket a piece of information belongs in is the first real architecture decision you make, and most teams never make it on purpose. The in-context window is working memory and nothing more. Anything you want to survive past this one exchange has to get written somewhere else, deliberately. No single storage system does all three jobs well, and that's not a flaw waiting to be optimized out. It's the reason layered memory exists as a category at all. ## The simplest strategies and why they fail at depth The sliding window is the first thing everybody tries: keep the last N turns, drop the rest. That's fine for small talk, but it breaks the moment a finding from turn four still matters at turn forty, because by then it's gone. You shredded the thread one dropped turn at a time and didn't notice until the agent asked you the same question twice. The two-buffer setup is a step up: a raw buffer for recent turns, a compressed summary buffer for the older stuff. Better, but summarization loses things by nature. Exact numbers, source citations, the difference between "probably true" and "confirmed" often don't make it through the compression pass. And it's still one tier pretending to be three; it can't tell an episode from a fact even if it wanted to. Then there's plain retrieval-augmented generation: pull relevant chunks on demand, drop them in context. This helps with raw token count, but flat retrieval on basic keyword search does badly on research tasks that need several sources connected together; some benchmarks show it scoring in the single digits on multi-hop questions. The reason is structural, not a tuning problem. Research questions live in the relationships between things, not inside isolated paragraphs. Flat retrieval gives you the paragraphs and throws away the wiring between them. All three of these treat the symptom, the window filling up, instead of the actual disease, which is signal getting buried under noise. ## The layered memory architecture that research agents actually need The fix isn't a bigger bucket. It's routing information to the right bucket at the right time. **Layer 1, in-context working memory**, holds only the live reasoning thread: the current question, the most recent sources, whatever hypothesis is active right now. It needs curating, not just piling up like a junk drawer nobody cleans out. Newer systems like DeepSeek-V3.2 and GLM-4.7 build pruning right into the reasoning loop, compressing what's already been seen and cutting redundant history as it goes instead of letting it stack up. **Layer 2, the episodic store**, writes state snapshots after each meaningful step. That lets a session pause and pick back up later, or lets a developer rewind and see exactly what the agent knew at step twelve. LangGraph's checkpointing does this for real, writing snapshots out to Postgres, SQLite, Redis, or MongoDB. **Layer 3, the semantic store**, is the distilled, checked knowledge base. Facts and structured extractions pulled out of finished research steps, queried when needed instead of crammed into context up front. GraphRAG is the real upgrade over flat RAG here, because instead of retrieving isolated chunks it retrieves subgraphs: entities, their relationships, and the context wrapped around them. That's what actually makes multi-hop reasoning possible. **Layer 4, the procedural store**, holds the agent's accumulated know-how, including which tools to call in what order and how it's learned to recover when a search dead-ends. Update it across sessions and the agent gets better over time instead of relearning the same lesson every Monday. Put all four together and a research step looks like: read from semantic and episodic memory, reason inside working memory, write new findings back to whichever layer owns them, prune whatever stopped earning its spot. Done well, this kind of trajectory compression can cut context size by 68% while keeping 91% of what matters, per the RE-TRAC paper. ## How production frameworks implement this architecture today Nobody builds all four layers from scratch. A handful of tools have staked out real ground here instead. Mem0 (arXiv: 2504.19413) is a long-term memory layer built for production agents specifically; it learns user preferences and pulls context back across sessions, and by mid-2025 it was running at real scale. LangGraph handles the episodic side well through checkpointing to durable storage, which is exactly what you want for time-travel debugging or picking a session back up after it got interrupted overnight. HiAgent, shown at ACL 2025 in Vienna, tackles hierarchical working memory for tasks that stretch across a lot of steps, aimed squarely at the degradation that wrecks long research sessions. Letta takes a different route: LLM-managed memory paging for conversations that outgrow the window. Worth flagging the cost here, though: every paging decision eats latency and burns tokens, and if you're running high-frequency calls, that overhead piles up fast. Cognee builds and keeps updating a structured memory graph of user history, a working version of the semantic layer aimed at customer-facing agents. On the research side, systems like IterResearch and MemAgent rebuild task state at each step using dynamic memory structures, tossing out generic history to fake something close to an unlimited horizon. No single tool does all four layers. Most real deployments stitch together a checkpointing framework, a dedicated memory layer, and a vector or graph retrieval backend, then wire the three together by hand. ## Why the quality of ingested data determines whether memory architecture pays off Here's the part people skip past. A beautifully layered memory system fed raw, messy HTML still poisons every retrieval that comes after it, and garbage in means garbage retrieved and garbage reasoned over. Format isn't a preprocessing footnote; it's load-bearing. Raw HTML off a web page averages 38,381 tokens, and most of that is nav bars, ad scripts, footers, cookie banners: noise fighting for space in a window that isn't infinite no matter what the spec sheet promises. Run that same page through a scraper built to output clean Markdown and you land around 2,788 tokens, a 94% cut, saving roughly 35,980 tokens per page. At Claude Sonnet 4.6 pricing that gap works out to about $1,079 per 10,000 scrapes, based on Vellum's 2026 analysis. The savings don't stop at the bill. Cleaner input means tighter chunks and sharper vector embeddings, which means retrieval gets more accurate across the board. Summarization compresses better starting from structured text instead of soup. GraphRAG's entity extraction is noticeably more accurate on clean Markdown or JSON than on a page full of `
` tags. For memory stores, the defaults that actually work are Markdown most of the time, structured JSON when you need a fixed schema, JSON-LD for linked data, and clean plain text pulled out of PDFs. The scraping layer sits at the front door of the semantic store. It's not off to the side of memory architecture as some separate concern. Whatever comes through that door sets the ceiling for everything built on top. ## Feeding live web data into a research agent's memory pipeline At some point in a session, the agent hits a wall: it doesn't know something, so it calls a search or scraping tool, gets structured content back, and routes it into memory. That loop, done right, is what separates an agent that actually finds things from one that just guesses with a straight face. Search comes first. Iterative retrieval, meaning search, reason, search again based on what you just learned, is what pushes research agents from mediocre to actually useful. Systems built this way clear complex multi-hop benchmarks by wide margins over basic keyword search. Parallel AI, which raised a $100 million Series A in early 2025, builds search infrastructure with provenance attached to every result, so you get the evidence behind an answer instead of a ranked list of blue links. It scores 47% on the HLE benchmark, ahead of Exa at 24%, Tavily at 21%, and Perplexity at 30%. Brave Search runs its own independent index with a privacy angle, priced at $5 per 1,000 queries. Perplexity, meanwhile, processed something like 780 million queries in May 2025 alone across 22 million monthly users, which tells you how much load a research-grade search layer actually needs to carry. Scraping is the ingestion step that turns search results into usable memory. Firecrawl takes a URL and hands back clean Markdown, HTML, screenshots, or schema-extracted JSON, handling JavaScript rendering on its own; it's grown to over 1.25 million developers and 150,000-plus companies, with 5 billion requests served. Crawl4AI, an open-source Python library built specifically for feeding LLMs, has picked up 66,700 GitHub stars and counting. Bright Data runs an enterprise proxy network across 195-plus countries with anti-blocking baked in, a fit for high-volume competitive research. And Olostep offers one API for search, scraping, crawling, and batch jobs together, with a batch endpoint that runs 10,000 URLs in five to eight minutes and enterprise pricing down near $0.30 per 1,000 successful requests at volume, plus SDKs and an MCP server so a developer and an autonomous agent can both call it directly. Once the data's in hand, it has to land in the right layer. Search results go into the episodic log: what was searched, when, what came back. Scraped, structured content goes into the semantic store as extracted facts and relationships. And whichever source types and queries actually worked get written into the procedural store, so the agent's search strategy sharpens over time instead of resetting to zero every session. One story worth keeping in mind: when Microsoft shut down the Bing Search APIs on August 11, 2025, plenty of teams that had hardcoded a single search provider into their pipeline had to rebuild on short notice. Put an abstraction layer between your agent and whatever search API you're using, because a provider swap shouldn't mean tearing apart your memory architecture too. ## What a well-managed long research session looks like step by step Picture a session kicking off with a genuinely complex, multi-part research goal. Before doing anything else, the agent checks its procedural store: has a strategy like this worked before, and if so, which one? Then it checks episodic memory: did an earlier session already turn up something relevant, something that saves it from starting on a blank page? From there, the first retrieval loop runs. A search call comes back with candidate sources, the agent weighs them and picks the strongest, and a scraping call pulls the full content back as clean Markdown. Because that Markdown is lean, the agent slots it straight into working memory and starts reasoning on it right away, no wall of HTML noise dragging along for the ride. That's the loop that repeats for as long as the session runs. Check memory before acting, retrieve only what's needed, keep the working window lean, write findings back to whichever layer actually owns them. Skip that discipline and you're back to a model quietly losing the plot fifteen turns in, no matter how many tokens the vendor advertised on the box.Venn diagram: Flat RAG vs. Layered Memory Architecture. Compares Flat RAG and Layered Memory; overlap: Shared Mechanisms.Diagram: Four Memory Layers: What Goes Where. Visualizes: Visualize the four-layer memory architecture for research agents as a vertical stack, showing each layer's name, primary role, and example implementation.Diagram: Raw HTML vs. Clean Markdown: The Token Cost of Messy Ingestion. Visualizes: Show a side-by-side magnitude contrast between a raw HTML page and the same page scraped to clean Markdown.
Filed underResearch Agents

More in Research Agents