Agent Context Explained

/about

About this site

Agent Context Explained is about context engineering: what goes into an agent's context window, and how an agent remembers beyond it. Nine chapters cover the window as working memory, the retrieval that fills it (BM25, dense retrieval, hybrid fusion and reranking, chunking), packing a token budget, compaction, memory across sessions, and when a long prompt beats retrieval. Every chapter is built around an animation. It is the third of a family of agent sites, after Agent Harnesses Explained and Agent Protocols Explained and followed by Agent Orchestration Explained, next to the LLM-systems sites (the Transformer Decoder Explainer, LLM Inference Explained, Inference Trade-offs Explained and others, all in the header's switch).

Measured, not asserted

Every retrieval number is measured on a fixed, openly licensed corpus: 6 articles of the SQuAD v1.1 development set (37,499 tokens) and 200 of their questions, sampled with a fixed seed from 1,160. Each question comes with its answer's exact position, so relevance needs no judgement: a chunk is relevant when it contains the whole answer. The data page lists the sources, licences, model revisions and checksums, and the full results.

Models ran once, offline

No model runs on this site or in its CI. An embedding model (all-MiniLM-L6-v2) and a cross-encoder reranker (ms-marco-MiniLM-L6-v2) ran once, on a CPU, in the engine's build script. What ships is their output: 8-bit embeddings of every question, sentence and chunk, and the reranker's scores for 6,226 question–chunk pairs. From those files the engine recomputes everything else: chunk boundaries, BM25, cosine similarities, fusion, reranked orders, recall@k, MRR and nDCG, the window task, packing, compaction, memory across sessions and the long-context costs. The only numbers that need the unquantised vectors, the float32 baselines, were recorded by the offline run and are labelled as such.

The engine, and how the animations are checked

The engine is Agent_Loop_Sim's context module (engine 1.11.1): a Python reference with a TypeScript port, vendored here at commit 46b445c with every file's SHA-256 recorded. It runs in a Web Worker. Agreement between the two languages is exact, with no tolerance: every chunk, score, ranking, metric and animation frame. Two details make that possible: all vector arithmetic is on integers (one square root and one division at the end, both correctly rounded), and BM25's logarithm is a shared transcription of fdlibm's, because the platform logarithms of Python and of browsers differ in the last bit for some inputs.

What is illustrative

Accessibility

Every animation has keyboard controls (Space plays or pauses, the arrow keys step), a live caption read out by screen readers, and starts paused when the reader prefers reduced motion. Colours come from Okabe and Ito's colour-blind-safe palette, and nothing is told by colour alone: a relevant chunk is also ticked, a cut answer also hatched.

Source

The site's source is on GitHub (MIT). For the slides behind the retrieval chapters, see the RAG and retrieval series.

Built by Brendan Lynskey