Agent Context Explained
What goes into the window, and how an agent remembers beyond it.
An interactive guide to what goes into an agent's context window, retrieval and memory, with every number measured on a real corpus.
How this is checkedEvery retrieval number is measured on 200 SQuAD questions with real MiniLM embeddings and recorded reranker scores, and the TypeScript engine in your browser reproduces the Python reference exactly, with no tolerance. How it is tested →
What you'll learn
A model knows only what is in its context window. Context engineering decides what goes in: which chunks of which documents, found how, cut where, packed in what order, what to drop or summarise when the window fills, and what to remember between sessions. Every claim here is measured, not asserted: on 6 articles of SQuAD and 200 of their questions, each with its answer's exact place in the text, so a retriever either finds the chunk that holds the answer or does not.
The animations are driven by Agent_Loop_Sim's context module. A small embedding model and a cross-encoder ran once, offline; their outputs ship with the site (int8 vectors and recorded scores), and the engine recomputes every chunk boundary, score, ranking and metric from them, identically in Python and in your browser. On this corpus BM25 finds the answer's chunk first 79% of the time, dense retrieval 71%, the two fused 81%, and fused then reranked 89%. No language model runs anywhere.
01
The window is the working memory
A twelve-question task in a window too small for it: what the agent knows grows with each read and shrinks when the window is trimmed, compacted or searched again, and what each choice costs in tokens.
02
Lexical retrieval: BM25
BM25 scored live for a query, term by term: inverse document frequency, term-frequency saturation (k1) and length normalisation (b), measured on 200 labelled questions.
03
Dense retrieval
Chunks and questions as 384-dimensional embeddings: cosine similarity, nearest neighbours on a 2-D projection, and how much recall survives int8, int4 and one-bit vectors.
04
Hybrid retrieval and reranking
Two ranked lists merged by reciprocal rank fusion, rank by rank, then a cross-encoder rereading the top twenty; recall@k for every stage.
05
Chunking
One text cut three ways, fixed, recursive and semantic: where the boundaries fall, which answers they cut in two, and what each chunking does to recall.
06
Packing the window
Which retrieved chunks fit a token budget, as a knapsack solved greedily and exactly, and where to put them: an illustrative lost-in-the-middle curve and four placements, measured on 200 questions.
07
Compaction and summarisation
A 36-question task compacted by a perfect and a lossy summariser: which facts survive n compactions, measured over 20 seeded runs, and what searching again costs.
08
Agent memory
Six sessions and the probes between them: transcript, scratchpad, episodic and semantic memory, with forgetting and consolidation, as facts recalled against tokens spent.
09
Long context or retrieval?
Fifty questions over a document set of up to a million tokens: the whole set in every prompt, with and without the prompt cache, against the top k chunks, in dollars, seconds and answers found.
Part of a family of sixteen companion sites in four tracks, all in the site menu above: Foundations (Decoder, Training), Hardware (Kernels, Systolic, Accelerators, Racks), Inference (Serving, Architectures, Numerics, Trade-offs) and Agents (Harnesses, Protocols, Context, Orchestration, Evals, Security). It is the third of the six agent sites. How this one was built, and how to check it: about.