A context window is a working surface
A context window is the set of tokens available to the model for one inference. It can contain instructions, conversation, retrieved documents, tool results, and an unfinished output. It is not automatically a durable store, and capacity alone does not guarantee that every included fact will influence the answer equally.
The Lost in the Middle study tested models on multi-document question answering and key-value retrieval. In its experiments, performance was often strongest when relevant information appeared near the beginning or end of a long context and weaker when that information appeared in the middle. This is evidence about specific models and tasks, not a universal law, but it is a strong warning against treating maximum context length as uniform usable memory.
Context also has a freshness problem. Earlier conversation turns can contain assumptions that later evidence has replaced. Simply retaining every token does not identify which statement is current. Applications need explicit rules for superseding old state, preserving decisions, and removing information that no longer belongs in the task.
Retrieval chooses what enters the window
Retrieval-augmented generation combines a language model with an external document index. The original RAG work paired parametric memory in a pretrained model with non-parametric memory in a dense Wikipedia index. Retrieval made the evidence set explicit and allowed the generator to condition on selected passages.
Retrieval is not truth by itself. A production system still needs document freshness, access control, chunking, ranking, source display, and an answer policy for weak evidence. The goal is to place the smallest useful evidence set into context, not to fill the window because space is available.
A retrieval pipeline normally turns the query into a search representation, selects candidate passages, reranks or filters them, and formats the selected evidence for the model. Each stage can fail independently. A relevant document may be absent from the index, split across poor chunk boundaries, ranked below noise, or presented without enough surrounding context.
From a question to grounded context
Retrieval is a selection pipeline. The model should receive relevant, authorized evidence with provenance, not an undifferentiated document dump.
User need
Form the search query
Represent the current question and include filters such as project, date, language, or access scope.
External memory
Retrieve candidates
Search the permitted index for passages that may contain the required evidence.
Evidence quality
Rank and filter
Prefer relevant, current, authoritative material and remove duplicates or unauthorized results.
Working context
Assemble with provenance
Present concise passages with source identity and enough context to interpret them correctly.
Answer policy
Generate or abstain
Answer from the evidence, expose uncertainty, and avoid a strong claim when support is missing.
Simplified retrieval-augmented generation pipeline based on the separation between parametric and non-parametric memory.
Use different stores for different jobs
Generative Agents explored an architecture that stored a stream of experiences, retrieved records based on relevance, recency, and importance, and produced higher-level reflections used for planning. It is a research prototype, but it illustrates why durable agent memory is an application design, not a synonym for context length.
Durable memory needs a write policy as much as a read policy. Storing every message creates noise and privacy risk; storing only a summary can erase important detail. A useful design states what may be remembered, how long it is kept, who can inspect or delete it, and what evidence is required before an old record is updated.
Source figure
A published architecture for memory, reflection, and planning

Figure 5 from Generative Agents shows observations entering a memory stream, retrieval selecting relevant records, and those records supporting reflection, planning, and action. It is a research architecture, not a universal memory design.
Park et al., Figure 5| Layer | Best for | Main failure to manage |
|---|---|---|
| Working context | Current instructions and evidence | Noise, position effects, token cost |
| Retrieval index | Large document and code collections | Stale, irrelevant, or unauthorized results |
| Structured records | Exact preferences, state, and permissions | Schema drift and incorrect updates |
| Decision log | Outcomes, assumptions, and unresolved work | Summaries that erase important constraints |
Placement and compression shape model behavior
Prompt assembly is an information architecture problem. High-priority instructions should be clear and stable. The current task should be easy to distinguish from historical discussion. Retrieved evidence should be grouped with its source, and the final portion of the prompt should restate the immediate output requirement without introducing a competing goal.
Compression should preserve decisions and evidence relationships. A useful summary says which conclusion was reached, what source or test supported it, what constraints remain, and what was intentionally excluded. A weak summary preserves fluent prose but loses the facts needed to continue safely.
For code work, a compact context might contain the issue, relevant interfaces, the current diff, failing test output, and repository rules. It usually should not contain every file inspected earlier. The agent can retrieve those files again if a later decision makes them relevant.
Compress decisions, not conversation volume
When a session grows, preserve the current goal, accepted constraints, changed files, verification results, and open questions. That compact decision state is usually more useful than a generic summary of every turn.
For facts that must remain exact, use structured storage with explicit updates. For large knowledge collections, retrieve and cite. For the immediate task, keep the prompt focused. Calling all three things memory hides the design choices that determine reliability.
Test memory as a system. Check whether relevant records are retrieved, outdated records are replaced, access rules are respected, deleted information stays deleted, and the model can continue when retrieval returns nothing. These cases matter more than demonstrating that a long conversation can be replayed.
Sources and further reading
Claims and figures in this article were checked against these original papers and official project resources.
- 1Lost in the Middle: How Language Models Use Long Contexts
Transactions of the Association for Computational Linguistics, 2024
- 2Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
Advances in Neural Information Processing Systems, 2020
- 3Generative Agents: Interactive Simulacra of Human Behavior
ACM CHI Conference on Human Factors in Computing Systems, 2023