Glossary
Virtual context management
A technique that pages information between an LLM's context window and external storage so an agent can work with more than fits in its prompt.
Virtual context management is a technique for giving an LLM agent access to more information than fits in its context window by moving data between the prompt and external storage as it is needed. The term comes from the 2023 MemGPT paper, which modelled it on virtual memory in operating systems: the prompt plays the role of RAM, external storage plays the role of disk, and a set of rules or tools decides what gets paged in and out.
The operating system analogy
In a computer, physical memory is small and fast, and disk is large and slow. Virtual memory hides that split from programs. Each program sees one large address space, while the operating system keeps the pages in active use in RAM and moves the rest to disk. When a program touches a page that is not in RAM, a page fault occurs and the system loads it. When RAM fills up, an eviction policy such as least recently used decides which page goes back to disk.
An LLM has the same shape of problem. The context window is the only memory the model can reason over directly, and it is limited by cost as much as by size. Every token in the prompt is paid for on every call, and long-context models tend to use the middle of a long input less reliably than the start and end, an effect known as lost in the middle. Research summarised on the reduce token costs page puts a model’s effective context at roughly half to two thirds of its advertised window. Everything else the agent might need, such as old conversation turns, documents and facts about the user, has to live somewhere else.
Virtual context management maps the pieces across. The prompt is main memory. A database, file store or vector database is disk. Retrieval is a page load. Evicting old messages or summarising them is page-out. The working set is the small group of facts the agent needs for the current step of its task.
How virtual context management works
Any implementation has to answer four questions: how the context window is divided, what triggers a page-out, what triggers a page-in, and who makes those decisions.
The first is the context budget. A typical agent splits its window into fixed regions: system instructions, a block of always-present facts, recent conversation turns, retrieved material and space for the response. A 32,000-token window might reserve 1,500 tokens for instructions, 1,000 for pinned facts about the user, 8,000 for recent turns, 6,000 for retrieved passages and the rest for tool outputs and the answer. Without a budget, whichever region grows fastest (usually conversation history) crowds out the others.
The second is page-out. When a region exceeds its budget, something has to leave. The simplest policy is first in, first out: the oldest messages are removed from the prompt. Better systems write them to external storage before removing them, so they can still be found later, and many keep a rolling summary in the prompt so the agent retains a compressed trace of what was said. MemGPT used two thresholds: a warning when the prompt passed a set share of the window, which gave the agent a chance to save important details, and a flush when it reached the limit.
The third is page-in. Information comes back into the prompt through retrieval, which can be triggered in two ways. In system-driven retrieval, the application searches external storage before each model call and inserts the results, the same pattern as standard retrieval-augmented generation. In model-driven retrieval, the agent decides it needs something and calls a search tool through function calling, as in agentic RAG.
The fourth is control. In MemGPT, the model itself manages memory: it has tools to edit a working context block, save text to archival storage and search past messages. Other systems keep these decisions in application code or hand them to a separate memory service, so the agent’s own loop stays focused on the task.
Model-managed versus system-managed paging
The choice of who manages the context has larger consequences than any other design decision.
Model-managed paging gives the agent flexibility. It can decide mid-task that it needs an older conversation, run several searches in a row and keep only what helps. The cost is that every memory operation consumes model calls and tokens, and the quality of what is saved depends on the model’s judgment. A smaller model may forget to save a key fact before it is evicted, or search with a poor query and conclude the information does not exist.
System-managed paging is predictable. Retrieval runs on every turn with known latency, extraction happens in the background, and the agent sees a prompt that is already assembled. The cost is less flexibility: if the retrieval step misses something, the agent may not know to ask for it.
Many production systems combine the two. A system-managed layer assembles a baseline prompt with recent turns and the most relevant memories, and the agent also has a search tool for cases the baseline did not cover. This keeps latency steady for ordinary turns while leaving room for deeper lookups.
A worked example
Consider a support agent with a 32,000-token budget serving a customer who has been in touch for six months. The full history is around 400,000 tokens across many sessions, plus a 200-page product manual.
Without virtual context management, the team has two poor options. They can include as much history as fits, which means the oldest sessions are dropped and the agent forgets that the customer upgraded their plan in March. Or they can summarise everything, which keeps the upgrade but loses the specific error code the customer reported last week.
With virtual context management, the prompt for a new message contains the system instructions, a pinned block of current facts (plan tier, region, open tickets), the last ten turns of the current session, and three passages retrieved for this question: one from the manual and two from earlier sessions where the same error appeared. The rest of the history and manual sit in external storage. If the customer asks about something from January, the agent searches for it and the relevant turns are paged in. The prompt stays around 12,000 tokens, and every token in it relates to the current question.
Failure modes
Virtual memory in operating systems has a well-known failure called thrashing, where the system spends more time moving pages than doing work. Agents have an equivalent. If the working set is larger than the budget, the agent keeps evicting information it needs a few turns later, retrieves it again, and spends tokens and latency on churn. The fix is the same in both cases: a larger budget for the active region, or a task design with a smaller working set.
Retrieval misses are the second failure. A page fault in an operating system always finds the page; a semantic search may not. Similarity search returns what resembles the query, which is not always what answers it, and as stored history grows more results look equally plausible. Hybrid search, reranking and query expansion reduce misses but do not remove them.
The third is stale or conflicting data. External storage keeps everything, including facts that have since changed. If a user moved city in June, a search in December can return both the old and new address, and the model has to guess which is current. This is memory drift, and it needs contradiction resolution at write time rather than at retrieval time.
The fourth is summary loss. Summaries are written before anyone knows the next question, so they inevitably drop details that later turn out to matter. This is the main weakness of conversation summary memory, and it applies to any page-out policy that relies on summarising.
How it relates to other context techniques
Virtual context management is an umbrella for several techniques that each handle part of the problem. Context offloading moves tool outputs and intermediate results out of the prompt into files or storage. Context compression and context pruning reduce what stays in the prompt. Prompt caching lowers the cost of a stable prefix but does nothing for the parts that change on every turn. Together they form much of what is now called context engineering.
It also overlaps with memory. The pinned facts block is a form of working memory, the external store holds long-term memory, and the retrieval step is memory retrieval. The distinction worth keeping is that virtual context management describes how information moves through the prompt, while agent memory describes what is stored and how it is kept accurate over time. A system can page perfectly and still serve outdated facts if the store behind it is not maintained.
Where Exabase fits
Exabase provides the external tier of a virtual context system: the storage, retrieval and upkeep that sit behind the prompt. Your agent framework still assembles the prompt and runs the loop; Exabase supplies what gets paged in.
For conversational context, Exabase Memory takes in conversations and extracts facts, preferences and events with the M-1 engine. Instead of paging out raw turns and summaries, you page out durable facts: an 8,000-token conversation becomes about 50 tokens of structured memories. M-1 resolves contradictions when memories are written, so a search returns the user’s current city rather than every city they have mentioned. Retrieval through memory search combines semantic and keyword matching with recency weighting, optional query expansion (expandQueries, 1 to 5) and reranking, and simple retrieval returns in about 200ms, fast enough to run before every model call.
For documents and media, Deep Search returns sub-document passages with page numbers or timestamps rather than whole files, and its precision parameter (0 to 1) lets you trade recall for relevance per query. That keeps the retrieved region of the budget small. Content stored as Resources is indexed when it is written, so there is no separate embedding pipeline to maintain, and Workers can re-extract documents that change.
Each user or tenant gets an isolated Base, so the external store for one user never returns another user’s data. In an illustrative request on the reduce token costs page, replacing full history and top-K chunks with memory and Deep Search cuts input from about 15,100 tokens to about 2,800. The agent memory solution and the Memory API docs show the setup, and the token cost calculator estimates savings for your own workload.
What is virtual context management in simple terms?
It is a way of letting an LLM work with more information than fits in its prompt. Only what the agent needs right now stays in the context window. Everything else is stored outside and brought back in when it becomes relevant, much as an operating system moves data between RAM and disk.
Who coined the term virtual context management?
The term comes from the 2023 paper “MemGPT: Towards LLMs as Operating Systems” by researchers at UC Berkeley. The paper described a system that pages data between the prompt and external storage, inspired by virtual memory. The project behind it later became the Letta framework.
Is virtual context management the same as RAG?
RAG is one part of it. Retrieval-augmented generation covers bringing information into the prompt. Virtual context management also covers what leaves the prompt, how the budget is divided and what is written back to storage as the conversation goes on. The difference is explored in RAG vs agent memory.
Do larger context windows remove the need for it?
No. Larger windows raise cost per call, and accuracy tends to drop as inputs get longer, so a full window often performs worse than a short, relevant one. Most production agents still manage what goes into the prompt. The trade-off is covered in RAG vs long context.
What is thrashing in an LLM agent?
Thrashing happens when an agent’s working set is larger than its context budget, so it keeps evicting information it soon needs again and retrieving it back. The agent spends tokens and time on moving context rather than on the task. Increasing the budget for active information or narrowing the task usually fixes it.
Should the model or the application manage the context?
It depends on the workload. Model-managed paging suits research agents that need flexible, multi-step lookups. Application-managed paging suits products with many users and strict latency targets. Many teams use both: an automatic retrieval step on every turn, plus a search tool the agent can call when it needs more.
Related pages: MemGPT, Context window, Context offloading, Context engineering, Memory vs context window, Working memory, Exabase vs Letta, What is context window overflow, Reduce token costs