A model reads nothing between calls: on every step of an agent the harness rebuilds the whole request, so context engineering is choosing what goes into that one request, in what order, and what stays outside it, so that it fits, stays cacheable, and holds what the next step needs.
Fig. 1 lays the request out as a tray of layers in the order it is sent, stable parts first and the growing history after them, against the 200,000-token window of Claude Haiku 4.5, to scale (a layer under about 1,200 tokens is drawn longer so it shows). Sizes from /context and the per-call usage of recorded Claude Code sessions with six tools; the section that owns each lever is named in its step.
/context then said 130.7k of 200k. The budget is checked between calls, so a single turn can overshoot it (section 1).| Lever | What it does | Measured here | What it costs or risks |
|---|---|---|---|
| Order for the cache (2) | Stable content first, so the provider reuses its work on the repeated prefix | A timestamp moved from the user message into the system prompt made a call cost 3.1x more on the input side MEASURED | Nothing if done from the start; one volatile byte early undoes it |
| Shape tool output (3) | Filter, clip, page, summarise or clear what tools return | A 491 KB log: about 228,000 tokens raw (over Haiku's 200K window), 148 filtered MEASURED | Clipping can cut the one line that mattered |
| Compaction (4) | Replaces the conversation with a model-written summary | 18,968 to 2,258 tokens in 23 s; 127,242 to 1,971 automatically MEASURED | Lossy: exact tool outputs went, and two of three summaries listed a next step nobody asked for |
| Memory files and skills (5) | Instructions loaded on every call (CLAUDE.md) or only when needed (skills) | The same 3,834-byte text: about 1,000 tokens as CLAUDE.md, about 40 as a skill description until used MEASURED | A skill that is never invoked never helps |
| Subagents (6) | A second loop with its own window does the reading; the parent gets a summary | Parent window 16,409 tokens instead of 64,533 on the same question MEASURED | Two to three times the tokens processed in total |
| Notes and memory layers (7, 8) | State outside the window: progress files, memory directories, fact stores, temporal graphs | CLAUDE.md content survived every compaction; the best memory layer answered 24 of 25 questions, pasting the history 23 MEASURED | Someone must write and keep them true; a write or read policy can silently lose facts |
You need: the agent loop (a model call, tool calls, results appended, repeat), built from scratch on Building a harness; this page starts where that loop sends its request. The parent's section 3 and Trace and context lab measure the startup context, the caching bill and a budget model on 22 recorded runs; they are linked here, not rebuilt.
textstats, with two planted bugs and the task "The tests in this repository fail. Find out why and fix the code so they pass. Do not edit the tests." Some runs add five 75 KB log files, a 30-module service package, a skill or a CLAUDE.md. Every run is Claude Code 2.1.290 headless (claude -p) on a Claude subscription, recorded on 6 October 2026, redacted, kept in src/recordings/. Dollar figures are the CLI's total_cost_usd: what the tokens would cost at Anthropic's list prices, not what the subscription paid.Models read and write tokens, about four characters of English prose each and fewer for code and logs. The window is 200,000 tokens for Claude Haiku 4.5 and 1,000,000 for Sonnet 5.5 as Claude Code configures them (model configuration, read 5 Oct 2026). A request that does not fit is refused: "Prompt is too long" came back when this page sent Haiku a 491 KB log in one piece MEASURED.
Four numbers make the budget: the startup context S, the growth per call g (the model's last reply plus the tool result it triggered), a reply reserve (Claude Code reports a 32,000-token output cap for Haiku 4.5), and a buffer before the harness acts. Claude Code's /context prints the window by category without calling the model. In a fresh session with six tools it reported 12.6k tokens, 6.3k of system prompt and 6.3k of tool definitions; the first real call read 13,320, so its figures are estimates within about 6% MEASURED (the parent's lab measured 13,242 on 2.1.289). With the auto-compact window set to 100K, a 33k "Autocompact buffer", a third of the window, was held free MEASURED.
/context said 130.7k of 200k MEASURED. A sixth file would have taken it near the limit in one step: harnesses check the budget between calls, and one turn of parallel tool calls can add more than the whole buffer.Call 12 of an agent is call 11 plus one reply and one tool result. To read a prompt the model computes a key and a value vector per token per layer (the KV cache; how big it is per model is Long context's subject), and those vectors depend only on the tokens before them. A prompt cache keeps the computed prefix, keyed by a hash of its content, and a later request that starts with exactly the same tokens reads it back instead of recomputing. Two consequences, both about order: a match must be exact from the first token, so one changed byte early invalidates everything after it; and whatever changes most often must come last.
The same rule at production scale. Cloudflare's AI code reviewer gave every review the same long system prompt followed by review-specific text, with one breakpoint after both, so each review's first request missed. Splitting the prompt at a marker so the shared part got its own breakpoint raised the first-request cache hit rate from 14 to 26% to 91 to 99.5%; cache writes had been 43% of spend, and with this and other changes the cost per review fell from $2.43 to $0.77, 68% (Cloudflare, 19 Oct 2026; the company's own figures). Whatever many requests share needs a breakpoint of its own, placed before the first byte that differs.
A cache saves the recompute; a server-held thread also saves the resend. With caching alone the client still sends the whole conversation on every call. The Claude API's message threads keep it on the server: the first request sends everything and starts a thread, later requests send only the new messages plus the previous response's ID, and the server holds the thread in memory and drops it 5 minutes after the last request (the client then sends everything again). Token usage does not change, because the model still reads the whole conversation; what falls is request size and time to first token, which matters most on very long sessions. The API stops being purely stateless, for five minutes at a time.
Public beta from 2 November 2026, enabled with a thread parameter; the thread is held encrypted, in memory only, never on disk. Anthropic reports median time to first token about 35% lower for 500K to 1M-token requests, measured on Claude Code, where threads are on by default (vendor-reported). Available on the Claude Platform, on AWS, in Microsoft Foundry and on Google Cloud (Anthropic).
tools, then system, then messages. A changed tool definition invalidates all three; a changed system prompt, system and messages; a changed tool choice or an added image, only messages DOCUMENTED.cache_control on a block) marks where an entry is written: up to four per request, or one automatic one on the last block. A read looks back from each breakpoint at most 20 block positions (consecutive tool_use or tool_result blocks count as one), so a turn that adds more than 20 blocks misses the last turn's entry unless a second breakpoint sits earlier DOCUMENTED.A prefix shorter than the model's minimum is silently not cached: 4,096 tokens for Haiku 4.5 (and Opus 4.6 and 4.5), 1,024 for Sonnet 4.5, 4.6 and 5, 512 for Sonnet 5.5 and Opus 5.5. An entry can be read only after the response that wrote it has started, so parallel requests sent at once all pay to write; caches are never shared between organisations, and on the Claude API not between workspaces DOCUMENTED. Usage fields: cache_read_input_tokens, cache_creation_input_tokens, and input_tokens, which counts only what comes after the last breakpoint. Source: prompt caching and pricing, read 5 and 6 Oct 2026.
OpenAI caches automatically from 1,024 tokens; for GPT-5.6 and later it bills reads at 0.1x and writes at 1.25x and keeps entries at least 30 minutes after last use, and a prompt_cache_key helps route related requests to the same cache on earlier models (OpenAI prompt caching, read 6 Oct 2026). Gemini caches implicitly on 2.5 and newer models with "no cost saving guarantee", and offers explicit caches with a default one-hour lifetime billed for storage time; minimums are 4,096 tokens on the 3.x models and 2,048 on 2.5 (Gemini caching, read 6 Oct 2026; its discount rate not checked here). Local servers do the same in memory: mlx_lm.server keeps a prompt cache bounded by --prompt-cache-bytes.
The rules, simulated. The simulator applies them block by block to a session you configure: a request is a row of blocks in the order tools, system, messages; an entry is written at each breakpoint and keyed on the exact prefix; a read looks back at most 20 positions; prefixes below the minimum are not cached; entries expire. Predict before you press a preset: with 25 blocks per turn and one automatic breakpoint, what share of input is read from cache by call 12?
What the presets show: one growing text block (the parent's Loop lab resent the transcript as one block) never matches past the system prompt, so it is written in full at 2x every call and nothing is read (one block per message, in order, fixes it); 25 blocks per turn falls outside the 20-position lookback, so nothing is read (a breakpoint at the start of each turn fixes it); pauses longer than the lifetime rewrite everything, so the 1-hour lifetime wins once a session pauses.
With the block sizes measured in the static run (tools plus the fixed system prompt 8,344 tokens, already cached by other sessions; the rest of the system prompt 3,855; the first user message 1,111, plus a 13-token timestamp when present) the rules give these reads. This reproduces the recordings by construction for the static run (its sizes are the inputs) and independently for the other three.
--system-prompt-snapshot on (the default) resends the first system prompt verbatim "until the conversation is compacted" (claude --help).The system prompt is fixed and a few thousand tokens; tool results are unbounded, arrive every call, and stay in the history, re-read on every later call, until something removes them. A tool-output policy decides what of a result the model sees now and what it sees of it later. The parent's Trace and context lab planted a 491 KB ci.log: 6,005 lines of heartbeat noise with five relevant lines at 3,101 to 3,105. Each policy below was applied to it by a script and the result's size counted by Claude Haiku 4.5 (one call each, tools off, minus the 529 tokens of an empty prompt).
grep) or the tool's author builds it in.src/tool_policies.py, data src/inputs/policies.json.Masking beats summarising as a default. On SWE-bench Verified with SWE-agent, keeping the last 10 turns' observations and replacing older ones with a placeholder roughly halved cost against an unmanaged context and matched or beat LLM summarisation's solve rate in four of five model settings (Qwen3-Coder 480B: 54.8% at $0.61 per instance masked, 53.8% at $0.64 summarised, 53.4% at $1.29 unmanaged) (Lindenbauer et al., arXiv 2508.21433, 29 Aug 2025; the four-of-five count from the JetBrains blog post, Dec 2025). Anthropic's API does it server-side: context editing's clear_tool_uses_20250919 strategy, once the prompt passes a trigger (100,000 input tokens by default), replaces the oldest tool results with a placeholder, keeps the most recent 3 tool uses, can exclude tools, and has clear_at_least because every clearing invalidates the cache and should free enough to be worth the rewrite (context editing, read 6 Oct 2026). Claude Code clears older tool outputs first when the window fills, before it compacts (how Claude Code works).
-v output put the test results at lines 92 to 95 of about 240, which head-and-tail clipping cut in the parent's Loop lab); cap every result and say what was cut and how to get the rest; offer a search or filter parameter; keep errors in the history, since a failed attempt is information (Manus: "keep the wrong stuff in"); clear old results with a stub that names the call, so the model can rerun it.Clearing keeps single results small, but the history still grows by every reply and action. Compaction replaces it: the harness asks a model to summarise the conversation, then starts a fresh window with the startup context, the summary and whatever it chooses to carry over. The designs, from crudest to most engineered:
drop (exclude chosen tokens' cached keys and values from attention) and repos (re-position the kept keys) instead; the serving engine must then track cache state, because the same token sequence can now have different caches. Dropping old tool responses on a rolling basis scored 1.7 points higher at 27.7% lower cost than summarising at a threshold, on the authors' benchmarks (Cache Engineering for Agents (arXiv 2610.28577)); it needs that engine, not a hosted API.compact_20260112 edit summarises past a trigger (150,000 input tokens by default); trained compressors and models that rewrite their own context go further (closed block below).Forcing Claude Code to compact (the parent's sessions never came near 200K). Manual: a script keeps one claude -p --input-format stream-json session open and sends the task, then /compact, then a question. Automatic: --autocompact 100000 shrinks the window Claude Code compacts against to its 100K minimum, and the task reads five 75 KB logs (CLAUDE_CODE_AUTOCOMPACT_PCT_OVERRIDE=16 as well left the buffer at 33k: size, not the percentage, triggered it MEASURED). Each first message also said "the reviewer for this change is Ilse Marten, and the ticket number is TS-4471", and the folder's CLAUDE.md held "Release codename: KESTREL."; afterwards each session was asked, tools forbidden, to recall them, quote what the test runner first printed, and say what it changed.
What happened, in all four runs. The three manual compactions took 18,968, 17,969 and 18,390 tokens down to 2,258, 2,357 and 2,472 in 23 to 32 seconds, and the turn that ran each cost $0.015 to $0.021 at list price MEASURED. The automatic one's cost is derived: the session's modelUsage input minus every streamed call. On a big history the summary is a large cost of its own. The first call after every compaction read the startup prefix (about 12,200 tokens) from cache and wrote the rest again: the summary is a new prefix. The card replays each session; "No compaction" is a different run of the same task.
What survived. The chat facts survived every compaction (the summary's section "All user messages" copies them), and the CLAUDE.md codename too, because Claude Code re-reads the project CLAUDE.md from disk after compacting. What went was verbatim tool output: all three uncompacted controls said correctly that the runner printed only "FAIL" lines and no assertion message; of the three manual compactions, two said they no longer had it and one confidently quoted its own later diagnostic output as what the tests printed. The large uncompacted run, at 130K tokens, put a maintainer note in two log files when it was in one.
Recall after the task, judged by hand against the recordings; hover a score for the reason. One run of each: what can happen, not rates.
git init and the permission layer refused it). In the automatic run it merged an unrelated log line into the plan: "Identify and remove/fix any Python 3.8 compatibility code that breaks in 0.2". That agent ignored the false lead; the next might not. Steer it (/compact focus on ..., a PreCompact hook that saves state first) and review it like any prompt. What Claude Code re-injects after compacting (project-root CLAUDE.md, invoked skills up to 25,000 tokens, recent files) is listed on Claude Code, taken apart, section 9.Driver for the manual sessions (the automatic ones used one task message that also asked for the five logs to be read in full):
claude -p --input-format stream-json --output-format stream-json --verbose \
--no-session-persistence --setting-sources project --strict-mcp-config \
--model haiku --permission-mode acceptEdits --tools "Read,Edit,Write,Bash,Grep,Glob" \
--allowedTools "Bash(python3:*)" "Bash(python:*)" "Bash(ls:*)" "Bash(cat:*)" \
--append-system-prompt "Never use the em-dash character." [--autocompact 100000]
# then, on standard input, one JSON line per user turn, each sent after the previous turn's result record:
{"type":"user","message":{"role":"user","content":"Before we start, note two things ... Do not edit the tests."}}
{"type":"user","message":{"role":"user","content":"/context"}}
{"type":"user","message":{"role":"user","content":"/compact"}}
{"type":"user","message":{"role":"user","content":"/context"}}
{"type":"user","message":{"role":"user","content":"Without using any tools, answer from memory ..."}}
/context answers without a model call; /compact runs the summarising call inside Claude Code and emits a compact_boundary record with the token counts before and after (the SDK documents both: commands in SDK sessions).
The answers, verbatim
What each compaction cost
"Compaction turn": the change in the CLI's total_cost_usd across the /compact turn (manual), or the hidden summarising call's input derived as modelUsage input minus every streamed call (automatic). "First call after": the next call's cache read and write.
Server-side. The Claude API's compact_20260112 edit (beta header compact-2026-01-12) summarises when the prompt passes a trigger, 150,000 input tokens by default and at least 50,000, takes your own instructions for the summary, and returns a compaction block that replaces everything before it; a newer on-demand form (beta compact-2026-09-04) is now the recommended one (compaction docs, read 6 Oct 2026).
Trained compressors. Cognition describes fine-tuning a smaller model whose only job is compressing history (12 Jun 2025); End-to-End Context Compression at Scale (the Latent Context Language Models paper) compresses the context into soft tokens inside the model. A lighter hybrid keeps the text summary and adds what it loses: REMORY trains a small network to append a bounded run of soft memory tokens after the summary so a frozen model continues as it would with the full history; on SummHay it approached the full-context joint score with 5.2% of the input positions, and Qwen3.8-27B and GLM-5.3-Flash repeated fewer tool outputs and made fewer tool errors on BrowseComp and Terminal-Bench 2.1 (REMORY (arXiv 2610.11287)).
The model manages its own context. A Context Language Model (CLM) is given its context as a file it may rewrite without restriction, so what to keep becomes model behaviour, and several agents' contexts become several files. Built zero-shot from existing models, CLMs beat the best harness-side strategies the authors compared: 11.4% higher accuracy with 21.5% fewer FLOPs on BrowseComp-Plus, 5% higher scores with 59% fewer FLOPs on 12-hour EdgeBench. The policy can be taught: evolved natural-language instructions added up to 35.9 points on a held-out context-management task, and online RL raised Qwen3.5-9B on BrowseComp-Plus by 47.6% over its untrained start with 12% fewer FLOPs, though a summary harness trained the same way ends within noise of it, so the trained advantage is mainly cost (Context Language Models; arXiv 2609.37725; not the Latent Context Language Models above). Training any compacting agent has a credit problem: one trajectory spans several sessions, and broadcasting one trajectory-level advantage to every session cannot tell which helped; Mosaic shapes each session's advantage by its estimated contribution and beat broadcasting on BrowseComp with Qwen3.5-4B, in compaction and subagent-forking runs, using fewer sessions (Mosaic (arXiv 2610.22174)).
Some instructions must reach every task (how to run the tests, what never to touch); others matter for one kind of task (how to write release notes). Anything in the startup context is paid on every call and competes for attention; anything outside must be found. Memory files are plain text loaded into every session: Claude Code reads CLAUDE.md (and, per its docs, AGENTS.md, the cross-vendor name). Skills use progressive disclosure: a folder with a SKILL.md whose short description sits in the startup context; the body is read only when the model calls the Skill tool, and files it links only if needed (the three levels in Anthropic's Equipping agents for the real world with Agent Skills, 16 Oct 2025). Load order and rule syntax belong to Claude Code, taken apart; here only the window cost.
Asked to "Write the release notes for textstats version 0.2", Haiku called the Skill tool on its first call, and the next call wrote 1,361 new tokens to the cache: the body, prefixed with the skill's base directory, delivered as a message in the history MEASURED. It then followed the procedure (ran the tests, listed the public functions, ended with "Reviewed-by: (pending)"). Enabling the Skill tool also changed the tool list, so that session's first call found nothing cached and wrote all 15,584 tokens: section 2's rule again.
.claude/skills/release-notes/SKILL.md with a one-sentence description; startup context from /context in fresh sessions (Claude Code 2.1.290, Haiku 4.5; tools Read, Edit, Write, Bash, Grep, Glob, Skill). The skill row includes the descriptions of 14 skills that ship with Claude Code (about 1.7k tokens).| Memory file (CLAUDE.md, AGENTS.md) | Skill | |
|---|---|---|
| Cost when unused | Full text, every call | Description only (about 40 tokens here) |
| Risk | Crowds the window and dilutes attention as it grows | Never loaded if the description does not match the request; a skill invoked is not a skill obeyed |
| After compaction | Project-root file re-read from disk; nested files only when a matching file is read again | Invoked bodies re-injected, 5,000 tokens each and 25,000 in all, oldest dropped first; truncation keeps the start, so put the important rules at the top |
| Use for | Facts every task needs: build and test commands, layout, hard rules | Procedures for one kind of task; long reference material |
The parent measured the other side of the trade: a four-line CLAUDE.md stating the test command cost 184 tokens and saved most runs several exploring calls, though one run explored anyway. Research: Demystifying Agent Skills (why skills help and when they misfire) and Repo-To-Skill (distilling repositories into skills).
Some subtasks read a lot and answer briefly: "which module defines a class?" over a whole package. Done in the main loop, every file read stays in the main history. A subagent is a second agent loop with its own fresh window: the parent writes it a task, it reads, and only its final text returns as one tool result. Measured on a 30-module Python package (121 KB) with "Read every module in service/ in full ... which module defines a class, and which module has the largest number of functions?", twice without the Agent tool and twice told to delegate to one general-purpose subagent (Haiku 4.5 throughout).
grep answers, the subagent only added cost: $0.057 against $0.020, 2.8x MEASURED.So a subagent buys isolation, not savings: the parent's later calls stay small, its attention is not spent on 46,000 tokens of code it no longer needs, and it compacts later. Anthropic's guidance has subagents return "a condensed, distilled summary" of about 1,000 to 2,000 tokens (29 Sep 2025). Two traps: the subagent sees nothing of the parent's history, so the task message must carry everything; and the CLI's result.usage leaves the subagent's calls out while modelUsage includes them (measured on the parent page). When several agents must make decisions that agree, isolation becomes a coordination problem: Multi-agent patterns owns that, including Anthropic's advice to fold most subagents back into one loop that discloses skills and tools progressively, since tool choice degrades beyond 30 to 50 tool definitions.
A task longer than one window or one session must leave its state where the next window can read it, and the history is not that place: compaction rewrites it and a new session starts without it.
todo.md as it goes, keeping the plan in the most recent part of the context, where it is least likely to be lost (18 Jul 2025); Claude Code's TodoWrite tool plays the same role.memory_20250818) gives the model file commands (view, create, str_replace, insert, delete, rename) on a /memories directory your application stores, with system-prompt text telling it to check the directory first and assume the window may be reset at any moment (memory tool, read 6 Oct 2026). On Anthropic's own evaluation, memory tool plus context editing improved performance by 39% over baseline, context editing alone by 29% (29 Sep 2025; vendor-reported).Who curates, and when. Just-in-Time Memory (Salesforce, 23 Sep 2026) curates an agent's memory at read time, once the task is known: untrained read-time curation beat untrained write-time memory in 15 of 17 comparisons, though most of the headline +16 points comes from RL training. Proactive Memory Agent (Meta AI, 9 Jul 2026) runs a second model beside the agent that keeps a small memory bank and injects reminders: Sonnet 4.5 went from 37.6% to 45.9% on Terminal-Bench 2.0 with an Opus 4.6 memory agent, single runs. Anthropic splits its own agent memory into three steps: capture (the model writes notes it predicts will be useful), consolidation, an offline pass it calls dreaming that rereads transcripts and notes, fixes wrong notes, builds wiki-style pages and promotes key notes into the start-of-session context, and retrieval (that small injected layer plus search). Its lessons: let a strong model judge what is salient, tell it what memory is for rather than how to keep it, and keep the injected layer small; on its own corpus test, a consolidated wiki plus search beat search alone (numbers below). Resident personal agents keep memory files across days: Personal agents.
On CL-Bench's database task, Opus 5.5 went from 0.655 mean reward without memory to 0.838 with a memory store. On a corpus of about 350,000 files with 25 questions, the wiki alone went from 13% to 48% of graded criteria as dreaming scaled from two sessions to 128; the wiki plus search reached 61% against 53% for search alone, saving about 20,000 tokens per question. Giving each contract its own page raised the facts kept from 41 of 57 to 57 of 57. Anthropic's own tasks; the article does not say how many runs each number is. Claude Code's auto memory loads only the first 200 lines or 25 KB of MEMORY.md (Anthropic, vendor-reported).
Notes (section 7) are files the agent writes and reads itself. A memory layer is a store a framework plugs in, where a model derives something smaller than the history (facts, a graph, a self-edited block) and decides what to do when new information contradicts old. Two policies define every one: a write policy (what is extracted, in what form, and whether a contradicted memory is overwritten, kept beside the new one, or closed with a date) and a read policy (who decides to look, the harness on every answer or the model when it chooses, with what query, and how many results go back into the prompt).
Every failure in the experiment below sits at one of the three links. Checking whether the evidence reached the prompt (no model needed) separates the first two from the third.
Four ways carry knowledge across sessions, in rising machinery: paste the full history (the baseline every product must beat, while it fits); notes the agent keeps (section 7); search the raw history, which is retrieval over your own chat log (rag-and-retrieval owns the mechanics) and keeps "tests run with test_core.py" beside "the test command is now pytest"; and a memory layer, which consolidates. LangGraph's store is the bare key-value form (LangChain and LangGraph, section 10). Three designs dominate:
Store what was learnt, not what was said: a model turns each conversation into short sentences ("User's tests run with pytest"), each embedded; before an answer the closest sentences are pasted into the prompt. Cheap to read, easy to inspect. Since v2.0.0 (16 April 2026) the open-source library is "single-pass, ADD-only": a changed fact becomes a second sentence beside the old one.
A model turns each conversation into entities and dated relations; a newer relation that contradicts an older one closes the older one's validity window: nothing is deleted, so the graph answers both "what now" and "what before". Built for "what changed, and when".
The model manages its memory with tools: a small block always in the prompt plus archives it writes to and searches, like an operating system paging between RAM and disk. Nothing is stored or found unless the model decides to.
One changing fact, four stores. Sam's gateway changed three times in twelve sessions; the chart follows what each store held about it, with the stored text under the chart.
The experiment. All three products ran on the same twelve invented sessions between a user, Sam, and an assistant (the parent frameworks root's four sessions extended to twelve; invented, assistant turns are fixed text so every system saw exactly the same history; about 1,400 tokens in all, so the full history fits and is an honest upper bound), then answered 25 questions in LongMemEval's five abilities, asked "on" 6 October 2026. Two measurements per answer: did the evidence words reach the prompt (no model needed), and was the answer right (keyword rules per question; an abstention question passes when the answer says it does not know or corrects the false premise; every answer was also read by hand). Writers and readers are Claude Haiku 4.5 and a local Qwen3-4B on Apple M1 Pro. A demonstration of mechanisms, not a benchmark MEASURED.
| Memory | Writer | Extraction 5 q | Multi-session 4 q | Update 6 q | Temporal 6 q | Abstention 4 q | All, Haiku reads | All, 4B reads | Evidence reached the prompt |
|---|---|---|---|---|---|---|---|---|---|
| No memory | none | 0/5 | 0/4 | 0/6 | 0/6 | 4/4 | 4/25 | 4/25 | n/a |
| Full history in the prompt | none | 5/5 | 4/4 | 6/6 | 4/6 | 4/4 | 23/25 | 24/25 | 21/21 |
| Mem0 2.2.1 (library) | Haiku | 4/5 | 3/4 | 6/6 | 5/6 | 4/4 | 22/25 | 21/25 | 20/21 |
| Mem0 paper loop | Haiku | 5/5 | 4/4 | 6/6 | 5/6 | 4/4 | 24/25 | 24/25 | 20/21 |
| Mem0 paper loop | local 4B | 4/5 | 4/4 | 5/6 | 2/6 | 4/4 | 19/25 | 17/25 | 18/21 |
| Graphiti 0.30.2 | Haiku | 2/5 | 2/4 | 3/6 | 4/6 | 4/4 | 15/25 | 17/25 | 14/21 |
| Graphiti 0.30.2 | local 4B | 0/5 | 0/4 | 0/6 | 1/6 | 4/4 | 5/25 | 5/25 | 1/21 |
| Letta 0.16.8, its own loop | local 4B | 0/5 | 0/4 | 0/6 | 0/6 | 4/4 | 4/25 | 4/25 | 1/21 |
| Letta's notes, pasted whole | local 4B | 4/5 | 4/4 | 6/6 | 3/6 | 4/4 | 21/25 | 21/25 | 21/21 |
Questions right by ability, read by Haiku (Letta's own loop: the local model); "evidence" is out of the 21 questions that have an answer. Recorded 6 Oct 2026: Mem0 2.2.1, Graphiti 0.30.2 on FalkorDB 4.22, the archived Letta 0.16.8 server; the paper loop is the parent frameworks root's minimal ADD/UPDATE/DELETE/NOOP implementation. Scripts and redacted recordings: src/memory_layers/.
What the table says. Pasting the whole history scored 23 of 25; the best memory, the paper loop with a Haiku writer, 24; Mem0 2.2.1 22; Graphiti 15, because only 14 of 21 answers' evidence reached the prompt; Letta's own loop 4, though its notes pasted whole gave 21: its write side worked and its read side did not (it searched on 5 of 25 questions). With no memory at all, 4. Swap the writer for the 4B model and the same designs lose facts: the paper loop fell to 19 and Graphiti to 5.
| Memory (writer) | Write calls, 12 sessions | Tokens in | Model time (s) | API-price equivalent | Search per question (ms) | Memory text per question (chars) |
|---|---|---|---|---|---|---|
| Mem0 2.2.1 (library) (Haiku) | 12 | 117,266 | 63 | $0.071 | 180 | 1,446 |
| Mem0 paper loop (Haiku) | 24 | 21,645 | 94 | $0.038 | 0 | 3,286 |
| Graphiti 0.30.2 (Haiku) | 71 | 177,234 | 251 | $0.278 | 65 | 1,227 |
| Graphiti 0.30.2 (local 4B) | 37 | 41,285 | 1,360 | local | 0 | 299 |
| Mem0 paper loop (local 4B) | 24 | 9,798 | 2,436 | local | 0 | 3,822 |
| Letta 0.16.8, its own loop (local 4B) | 29 | 139,926 | 842 | local | in-agent | - |
| Full history in the prompt | 0 | - | - | local | 0 | 5,796 |
Claude figures are the CLI's API-price equivalent at Haiku 4.5 list prices; local-model figures are tokens and seconds on a shared M1 Pro, comparable only with each other. Mem0's input is dominated by its extraction prompt (7,924 tokens with the Qwen tokenizer, over the shared local server's limit, which is why the library's writes used Haiku). Graphiti made 71 calls for 12 episodes: two is the minimum per episode (entities, then facts), and every new fact that resembles an old one costs another resolve_edge call (26 of them here). Letta has no separate search step: its 25 answers took 36 model calls inside its own loop.
At this size pasting everything is cheaper than any memory layer for a long time. The vendors' own numbers say the same at their scale: Mem0's paper puts full context at 26,031 tokens per LOCOMO conversation against 1,764 for Mem0, and its p95 latency at 17.12 s against 1.44 s (91% lower, while full context stays more accurate), Zep's about 115K against 1.6K on LongMemEval; the saving appears only once history is tens of thousands of tokens and is read many times.
No benchmark was rerun here. LOCOMO (Maharana et al., arXiv 2402.17753, Feb 2024) is long two-person chats scored by an LLM judge (the "J score"); the paper describes 50 conversations of about 300 turns and 9K tokens, up to 35 sessions; its public release has 10 conversations, 1,986 questions, and 444 of the 446 adversarial questions have no reference answer, so every product evaluation drops that category; it has no knowledge-update questions. LongMemEval (arXiv 2410.10813, ICLR 2025) has 500 questions over histories of about 115K tokens (setting S) or about 500 sessions and 1.5M tokens (M); counts in the released file: temporal 133, multi-session 133, knowledge update 78, single-session user 70, assistant 56, preference 30, with 30 abstention variants. DMR, MemGPT's test, has 5 short sessions per conversation, which fit in a window. MemoryAgentBench (UCSD, arXiv 2507.05257) is independent.
| Benchmark | System | Score | Runner | Answer model | Date | Note |
|---|---|---|---|---|---|---|
| LOCOMO | Full context (baseline) | 72.90 | baseline | gpt-4o-mini | 28 Apr 2025 | in Mem0's own table, above both Mem0 variants |
| LOCOMO | Mem0 | 66.88 (Mem0g 68.44) | vendor | gpt-4o-mini | 28 Apr 2025 | paper system (1.x pipeline); 1,764 memory tokens per conversation against 26,031 for full context |
| LOCOMO | Zep | 65.99 | rival | gpt-4o-mini | 28 Apr 2025 | run by Mem0 |
| LOCOMO | Zep | 84 (retracted) | vendor | gpt-4o-mini | 6 May 2025 | category-5 correct answers counted in the numerator only |
| LOCOMO | Zep | 58.44 | rival | gpt-4o-mini | 8 May 2025 | Mem0's rerun with Mem0's template |
| LOCOMO | Zep | 75.14 ± 0.17 | vendor | gpt-4o-mini | 12 May 2025 | 10 runs; Zep corrected the calculation error within a week |
| LOCOMO | Letta (file tools) | 74.0 | vendor | gpt-4o-mini | 12 Aug 2025 | grep, search_files, open, close over the conversation stored as files |
| LOCOMO | Zep | 69.62 to 80.32 | vendor | gpt-4o-mini (agent and grader) | 9 Dec 2025 | 5 edges / 2 nodes to 30 / 30 retrieved; default 15 / 5 gives 77.06 |
| LOCOMO | Mem0 platform | 92.5 (old 71.4) | vendor | not stated | Apr 2026 | "top_200" retrieval; managed platform, "proprietary optimizations not available in the open-source SDK" |
| LongMemEval S | Zep | 63.8 vs full context 55.4 | vendor | gpt-4o-mini | 20 Jan 2025 | 115K-token histories; Zep context 1.6K tokens |
| LongMemEval S | Zep | 71.2 vs full context 60.2 | vendor | gpt-4o | 20 Jan 2025 | the "+18.5%" is relative; Zep lower on single-session-assistant (94.6 to 80.4) |
| LongMemEval S | GPT-4o, no memory system | 60.6 (87.0 given only the evidence sessions) | independent | gpt-4o | 14 Oct 2024 | the benchmark paper: "30% to 60%" drops for long-context models |
| LongMemEval | Mem0 platform | 94.4 (old 67.8) | vendor | not stated | Apr 2026 | top_200 retrieval; managed platform |
| DMR | MemGPT | 93.4 (GPT-4 Turbo alone 35.3) | vendor | gpt-4-turbo | 12 Oct 2023 | baseline is a fixed window with recursive summaries; GPT-4: 32.1 against 92.5 |
| DMR | Zep | 94.8 (MemGPT 93.4, full conversation 94.4) | vendor | gpt-4-turbo | 20 Jan 2025 | each conversation "easily" fits in the window |
| MemoryAgentBench | Mem0 / Zep / MemGPT | 21.1 / 24.0 / 28.3 overall | independent | gpt-4o-mini | v4 28 Jun 2026 | BM25 41.5, long context 42.2 (Table 3); 2025 product versions, chunked documents |
| AMA-Bench | Mem0 / MemGPT | 0.210 / 0.330 average | independent | Qwen-32B | 26 Feb 2026 | agent trajectories, not chat; MemoRAG 0.461 best |
The same product, Zep, scored 58.44%, 65.99%, 75.14% and up to 80.32% on LOCOMO depending on who configured it, the retrieval template, how many results were retrieved and how one category was counted. Ask five things of any memory benchmark claim: who ran it; does the whole history fit the answer model's window (then full context is the baseline to beat, and it often wins); which answer and judge models; how many memories were retrieved per question; which product version. Sources read 6 Oct 2026, quotes in src/memory_layers/inputs/research_claims.md.
How each failed (all recorded here; the fix after each arrow):
| If your situation is | Use | Why |
|---|---|---|
| History still fits in the window, read a few times | Nothing: paste it | Within one question of the best memory here, and above both Mem0 variants in Mem0's own LOCOMO table (full context 72.90 against 66.88) |
| A coding or task agent that must survive a session boundary | Files the agent maintains (section 7) | Readable, diffable, editable by a person; read at start |
| Many users, preferences and stable facts, cheap reads | Fact memory (Mem0 or your own store) | One search, a few hundred tokens per answer; plan for duplicates and stale facts (the 2.x library never deletes: schedule a consolidation or call update/delete yourself) |
| Questions about change: what was true when | Temporal graph (Graphiti or Zep) | Validity windows answer "before" and "now" from one store; budget for many model calls per episode, a graph database and wrong closures, and search the raw episodes too |
| A long-lived assistant on a model strong at tools | Self-managed memory (Letta style, or files plus search tools) | The model decides what is worth keeping; only as good as its habits (a small model here filed diaries and rarely searched) |
| A large corpus of documents, not a conversation | Retrieval (RAG) | A memory layer is retrieval over a derived store; when nothing needs consolidating, search the source |
Who curates, and when, is the one design question under all of them: the harness at write time (Mem0, Graphiti), the model in the hot path (Letta, the memory tool), or a curator at read time (Just-in-Time Memory, section 7). When the agent itself decides what to search and how to rewrite the query, that loop is Agentic retrieval.
The paper (Apr 2025) and Mem0 1.x (Chhikara et al., arXiv 2504.19413, section 2.1): two phases with GPT-4o-mini. Extraction: a model sees the new message pair, a running summary and the last m = 10 messages, and lists candidate facts. Update: for each candidate the s = 10 most similar stored memories are retrieved and a model picks one operation by tool call: ADD, UPDATE ("augmentation of existing memories with complementary information"), DELETE ("removal of memories contradicted by new information") or NOOP. The store holds the current truth; a history table logs the edits. A minimal version of this loop was run for this page (it shows the whole store to the update call instead of the top 10); with a Haiku writer it made 40 ADDs, 11 UPDATEs and 5 NOOPs over the twelve sessions.
The library since v2.0.0 (16 Apr 2026), run here at 2.2.1: "Single-pass, ADD-only": one call per add(), "No separate UPDATE/DELETE pass ... Hash-based deduplication prevents exact duplicates; ranking at retrieval time handles the rest" (v2.0.0 release). The call sees the 10 stored memories most similar to the new messages (their ids replaced by small integers, "anti-hallucination"), the last 10 messages of the scope, and an observation date (main.py, _add_to_vector_store). The docs: "Nothing is overwritten or deleted" (memory evaluation). Memories are scoped by user_id, agent_id and run_id; there are no "layers with promotion between layers", as an old note here claimed (docs).
Reading in 2.2.1 is hybrid (score_and_rank): a vector search over-fetches max(4 × k, 60) candidates; BM25 runs on spaCy-lemmatised text; named entities in the question boost memories linked to the same entity; candidates under 0.1 cosine similarity are dropped, and the rest ranked by
Two limits of the open-source library. add() takes a timestamp documented as "Platform-only temporal parameter. Not supported in OSS", so the prompt's "Observation Date", the anchor for "yesterday", is the machine's current date: right in live use, wrong for every message of an imported history (this run patched the date to each session's). And the extraction system prompt alone is 7,924 tokens with the Qwen3 tokenizer, over the shared local server's limit, so the library's writes used Haiku.
Who is who. Zep published the design (Rasmussen et al., arXiv 2501.13956, 20 Jan 2025); its open-source engine is Graphiti (Apache-2.0, 31,489 GitHub stars on 6 Oct 2026). Zep stopped maintaining its self-hosted Community Edition on 2 April 2025 (announcement); Zep Cloud runs a proprietary engine. Graphiti 0.30.2 needs a graph database: Neo4j, FalkorDB, Amazon Neptune, or the embedded Kuzu, deprecated ("the upstream Kuzu project is no longer maintained"), which here failed on the first episode ('KuzuDriver' object has no attribute '_database'); this run used FalkorDB 4.22 in Docker.
Four timestamps per fact. The model is bi-temporal: "t'_created and t'_expired ... monitor when facts are created or invalidated in the system, while t_valid and t_invalid track the temporal range during which facts held true"; in Graphiti, created_at, expired_at, valid_at, invalid_at. In this replay every closed edge has expired_at 6 October 2026 (the day of the run) but invalid_at in September: the system's clock against the world's.
One add_episode (each session went in as one episode, the raw text kept as "a non-lossy data store", with reference_time set to its date) runs these prompts; calls for 12 episodes with Haiku: extract_nodes.extract_message (find the entities) 12, dedupe_nodes.nodes (is this "Sam" the node already there?) 11, extract_edges.edge (facts as relations, one sentence each) 12, extract_edges.extract_timestamps (valid_at and invalid_at relative to the reference time) 7, dedupe_edges.resolve_edge (which existing facts the new one duplicates or contradicts) 26, extract_nodes.extract_summaries_batch (rewrite the touched entities' summaries) 3; 71 in all.
Invalidation is a model's judgement. For each new edge Graphiti finds similar existing edges and asks a model which are duplicates and which the new fact contradicts (dedupe_edges.py); code then sets each contradicted edge's invalid_at to the new edge's valid_at, provided the old edge started earlier (resolve_edge_contradictions). An edge with no valid_at is never closed by that rule. Search combines cosine similarity over edge embeddings with BM25 and merges them by reciprocal rank fusion; the paper adds breadth-first graph search and rerankers (maximal marginal relevance, distance from a centre node, episode mentions, a cross-encoder). Only edges come back, so a detail that landed in an entity summary is invisible to it.
MemGPT (Packer et al., arXiv 2310.08560, 12 Oct 2023) splits the prompt into system instructions, a working context the model edits with function calls, and a queue of recent messages; outside sit recall storage (every past message, searchable) and archival storage (what the model chose to file, searched by embedding). Past a warning threshold ("e.g. 70% of the context window") the system tells the model; at the flush threshold it evicts about half the queue into recall storage and replaces it with a recursive summary. The analogy is operating-system paging (Virtual memory). On its own Deep Memory Retrieval test GPT-4 alone with a fixed window and recursive summaries answered 32.1%, inside MemGPT 92.5%; GPT-4 Turbo 35.3% against 93.4%; Zep later reported the full conversation pasted in at 94.4%: the baseline MemGPT beat was a deliberately small window.
Letta. In Sep 2024 MemGPT became Letta; "MemGPT should refer to the original agent design pattern" (Letta blog, 23 Sep 2024). The V1 server kept memory blocks (a label such as human or persona, a text value, a character limit) always in the prompt, tools to edit them (memory_insert, memory_replace), conversation_search, archival_memory_insert and archival_memory_search, over Postgres and pgvector. Its last PyPI release, 0.16.8 (14 May 2026), is the one run here; the repository was archived on 16 Aug 2026, and from 0.32.13 (17 Sep 2026) the PyPI name letta installs Letta Code, a terminal agent whose memory is MemFS: "a git repository that belongs to the agent", root files in the system prompt every turn, other folders read on demand, no vector index by default, background "dreaming" subagents consolidating (MemFS docs, read 6 Oct 2026). That is section 7's memory-files design, run by the agent itself.
Running the archived server took three repairs: pip install letta==0.16.8 resolves today to dependency versions that break its imports (installing with dependencies as of its release date fixed that); its database layer only speaks Postgres, though its settings still mention SQLite; and the wheel ships no migrations, so the tables came from its ORM and the message sequence default was added by hand. The agent was letta_v1_agent with archival tools, an 8,192-token window, temperature 0 and the local Qwen3-4B, the only model here that can drive its tool loop over an OpenAI-compatible endpoint; each question went to a fresh conversation with the blocks copied.
LongMemEval's five abilities (Wu et al., arXiv 2410.10813, ICLR 2025; 500 questions over histories of about 115K tokens in setting S), used for the 25 questions here: information extraction (one fact said once, by the user or the assistant: "In the talk outline you drafted for me, what was the second point?"), multi-session reasoning ("How many times in total did the fallback kick in?", 37 in one session and 12 in another), knowledge update ("What gateway setup do we use right now?"), temporal reasoning ("On what date did the agent delete the tests folder?", said as "yesterday" on 17 September), and abstention ("When is the team offsite in Tokyo?"; it is in Lisbon). With the whole history pasted (about 1,400 tokens) Haiku got 23 of 25: it dated the deletion to the day Sam reported it and put the OpenRouter outage on the wrong Saturday.
Vocabulary. LangMem's guide splits long-term memory into semantic (facts and preferences), episodic (past experiences, summaries, few-shot examples) and procedural (how to behave: prompt rules), and memory formation into "in the hot path" (the agent saves while it talks, adding latency) and in the background (LangMem conceptual guide, read 6 Oct 2026). Mem0 and Graphiti are semantic memory formed in the background; Letta forms it in the hot path.
Before trusting a memory layer: (1) write a question set like this one on your own data, all five abilities, with the full-history baseline while history fits; (2) measure evidence before answers: if the evidence is not in the prompt, no reader model fixes it; (3) read the store after every session for a while: duplicates, wrong dates and wrongly closed facts show long before they cause a wrong answer; (4) log write failures loudly: an extraction that fails to parse must be an alert, not an empty list; (5) swap the writer model and rerun: the same design with a 4B writer lost what the Haiku writer kept.
Rehearsal. "I moved from Austin to Seattle": what does each design store? Paper-style memory updates "lives in Austin" to "lives in Seattle" (history lost unless logged); Mem0 2.x adds the new fact beside the old and relies on ranking; a temporal graph closes the LIVES_IN Austin edge at the move date and opens one for Seattle; self-managed memory edits its core block if the model notices. Only the graph answers "where did I live in March" directly. Why can memory make an assistant worse? Stale or duplicated facts outrank current ones, wrong dates are repeated with confidence, retrieved snippets crowd out the instruction, and without a "say you don't know" rule abstention questions become confident answers built from near misses. Memory for a million support users? Scope per user and account; write in the background, not the hot path; short facts with source message ids and dates; hybrid search with a small top-k; raw transcripts kept for audit and re-extraction; explicit conflict resolution; a LongMemEval-style test set with abstention and updates; users can see and delete what is stored. Bi-temporal, why? When a fact was true in the world answers "what was true then"; when the system learnt or retired it audits what the agent knew when it acted.
A 200,000-token window does not mean 200,000 tokens used equally well. Context rot is the name that stuck: "as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases" (Anthropic, 29 Sep 2025). A needle test hides one fact at a chosen depth in long filler and asks for it back. Here the haystack is real Python (files of the Python 3.9 standard library in a fixed shuffled order, cut to each length) and three needles are each hard in a different way:
RELEASE_PORT = 8371 # port of the textstats release box; "What value is RELEASE_PORT set to in the file above?" shares the needle's words: a lookup.# Ops note: the textstats release box sits in the rack right next to the Semperoper.; "In which city is the textstats release box located? Use what the file says plus general knowledge." The answer, Dresden, is not in the file: find the line by meaning and add one known fact.RETRY_LIMIT = N assigned five times at random depths; "What is the value of RETRY_LIMIT at the end of the file?" needs all five, in order.Claude Haiku 4.5 found the literal needle in all 20 cases and the non-literal one in all 20, from 2,201 to 113,710 tokens MEASURED. Tracking was 28 of 32: the four misses (at 2K, 16K, 16K and 64K tokens) all named an earlier assignment, and at 64K and 120K four of the nine replies that listed the assignments found only four of the five yet named the right final value. Errors did not grow with length: this run shows no rot for Haiku at these lengths, only that lookup is easy and keeping order is not.
The local 4B model found the literal needle in all 13 cases from 781 to 11,622 tokens (its tokenizer counts the same code in fewer tokens). Asked directly "In which city is the Semperoper?" it answered Dresden; with the same fact as a comment inside 1K to 12K tokens of code it answered Dresden in 4 of 13 cases and otherwise Berlin, Boston, San Francisco, Seattle or Portland MEASURED: the code pushed aside knowledge it has. Drew Breunig calls this context distraction, "when a context grows so long that the model over-focuses on the context, neglecting what it learned during training" (22 Jun 2025); here it took only 781 tokens. Tracking: 10 of 20 with no trend in length (0 of 5 at the shortest, 5 of 5 at about 5,700 tokens): a capability limit, not rot.
claude -p (Claude Code adds about 420 tokens); the local model, Qwen3-4B-Instruct-2507 in 4-bit MLX on Apple M1 Pro, through mlx_lm.server at temperature 0 (a different and much smaller model, not comparable as the same). Graded automatically by src/needle/grade.py: the expected answer must appear; for tracking, the stated final value must equal the last assignment. Recorded 6 Oct 2026; results in src/inputs/needle_*.json.At scale the literature finds the same shape: position matters (the 75.8% to 53.8% "lost in the middle" figures are on Agentic retrieval); literal lookup saturates while tracking and non-literal tasks degrade (RULER's GPT-4, advertised at 128K, was effective to 64K; NoLiMa took GPT-4o from 99.3% to 69.7% at 32K; both on Long-context and multimodal benchmarks); and Chroma's "Context Rot" report (Hong, Troynikov and Huber, 14 Jul 2025) found performance falling with input length on 18 models even on simple tasks, faster with distractors and with needles less similar to the question. Why effective context is shorter than the window is Long context's subject. An agent's context is the worst case: the facts it needs are scattered through tool results, rarely share the question's words, and sit among near-duplicates; section 4's 130K-token session that put a note in two log files is a small instance, and the reason to keep the window lean.
For a harness of your own the levers become a short list of decisions, cheapest and safest first, each with the measurement that tells you it works.
LangChain names the same moves in four words: write (outside the window), select (pull in what is needed), compress, isolate (2 Jul 2025); the 12-factor-agents list puts "Own your context window" third; Topic: agentic-frameworks discusses when a framework owns these decisions for you. The parent's Loop lab (step 4) is a working example of points 2 and 3 in about 40 lines of Python.
/context or a character count as an exact token budget/context estimated 12.6k where the API counted 13,320; the same log is 228,000 tokens to Haiku 4.5 and 304,996 to Sonnet 5.5. Budget against the provider's own counts, per model, with a margin.Why does prompt order matter for cost, and what order do you use? Caches match exact prefixes, so a change invalidates everything after it. Tools, system prompt and memory files first, then the history appended one message at a time, anything volatile in the last message. On Anthropic's API a changed tool definition invalidates the whole cache; a read costs 0.1x, a 1-hour write 2x.
Your agent's 40th call costs ten times its 2nd. Where do you look? Per-call usage: is the cache read the previous prompt (if not, something early changes or a turn adds more than 20 blocks past the lookback); the largest tool results; whether old observations are ever cleared; then the startup context. Compaction only if the history itself is the cost.
Masking or summarisation for a coding agent? Masking by default: no extra model call, no invented summary, half the cost and the same solve rate in four of five JetBrains settings. Summarise when old observations hold something the agent still needs that a stub cannot point back to.
When does a subagent help? When a subtask's input is large, its answer small, and the parent will not need the raw input again; it keeps the parent's window small (16K against 64K here) but processes more tokens, and sees none of the parent's history.
How would you test for context rot on your own workload? Cases from your own data at several lengths and depths, with tasks beyond literal lookup (a needle phrased differently, a value that changes, several items to collect), graded automatically, several seeds, compared with the same task short.
How do you tell a memory failure from a model failure? Check whether the evidence reached the prompt. If not, the write or read policy failed; if it did, the reader failed. Section 8's evidence column separates the two without any model.
Recordings: Claude Code 2.1.290, claude -p with --output-format stream-json --verbose --setting-sources project --strict-mcp-config --no-session-persistence, Claude subscription, 6 October 2026; redacted copies, scripts and notes in this page's src/. Text in the recordings is shown as written, except that each em-dash, in model replies and in Claude Code's own tool messages, was replaced by a comma (34 in all, counted by src/redact.py). The memory-layer runs (Mem0 2.2.1, Graphiti 0.30.2, the Letta 0.16.8 server, 6 October 2026) and their redacted recordings are in src/memory_layers/.
Links checked on 6 October 2026. Times are estimates for a careful read.
The root: what a harness is, compared on its parts. Reading section 3 is this page's summary; its Loop lab (step 4: clipping and masking in a home-made harness) and its Trace and context lab (startup context, caching with and without, a budget model) are the measurements this page builds on. Reading 21 min, plus 3 in closed details.
The product's mechanisms: tools and their limits, permissions, hooks (PreCompact among them), memory-file load order, skills, subagents, headless runs. Reading 37 min, plus 24 in closed details.
The loop, tool calling at the API level, edit formats, stop conditions: where your context policy plugs in. Reading 41 min, plus 20 in closed details.
Permissions, sandboxes, prompt injection, egress: what enters the context from tools is also an attack surface. Reading 35 min, plus 9 in closed details.
Six other harnesses read at pinned commits and run on one task: their compaction thresholds, tool-output caps and repo maps. Reading 30 min, plus 22 in closed details.
Resident agents that never end a session: bootstrap file caps, memory files, compression thresholds over days rather than minutes. Reading 32 min, plus 29 in closed details.
Scaffold sensitivity and RL environments: context policy is part of the scaffold a score depends on. Reading 36 min, plus 25 in closed details.
Needle in a haystack, RULER, NoLiMa, MRCR: the benchmarks behind section 9, in depth. About 27 min.
The KV cache and prefix caching on the server side. Reading 34 min, plus 3 in closed details.
Selecting context by retrieval rather than by reading. About 21 min.
The sibling root: libraries, orchestration, gateways, tracing. Reading about 28 min.
Section 10: LangGraph's store, the plain key-value form of cross-thread memory. Reading 34 min, plus 10 in closed details.
Section 7: sessions, resume and fork, the history a harness keeps, which is not a memory of facts. About 29 min.
The OpenAI Agents SDK's sessions and ADK's session state with user: and app: scopes. About 28 min.
When the agent decides what to search and when; lost in the middle; write-time against read-time curation. About 35 min.
Budgets and caching for the extra model calls a memory layer makes. About 37 min.
Tracing the calls compaction, subagents and memory layers add to every turn. Reading 34 min, plus 9 in closed details.
Its child on when separate contexts help or hurt. Reading 32 min, plus 14 in closed details.
Curating memory at read time, once the task is known. About 19 min.
A second model that reminds the agent of what it dropped. About 27 min.
Why skills help and when they misfire. About 25 min.
Distilling repositories into skills. About 22 min.
Compressing context into soft tokens inside the model. About 26 min.
Models that rewrite their own context as a file.
Many research agents sharing memory through a git repository, the idea behind Letta's MemFS. About 32 min.
Grading agent outputs with judges, which section 8's experiment replaced with keyword rules. About 30 min.
Anthropic, 29 Sep 2025: the attention budget, just-in-time context, compaction, note-taking, subagents. 15 min.
Yichao Ji, 18 Jul 2025: the KV-cache hit rate as the key metric, mask don't remove, the file system as context, recitation. 15 min.
The rules section 2's simulator applies. 20 min.
An interactive session timeline and the table of what survives compaction. 10 min.
Clearing tool results and summarising on the server. 20 min.
Lindenbauer et al., 2025: observation masking against LLM summarisation on SWE-bench Verified. 30 min.
Chroma, 14 Jul 2025: 18 models, performance against input length on simple tasks. 25 min.
Anthropic, 26 Nov 2025: the initializer agent, progress log and feature list. 12 min.
Drew Breunig, 22 Jun 2025: poisoning, distraction, confusion, clash. 10 min.
LangChain, 2 Jul 2025: write, select, compress, isolate. 12 min.
The 2025 extract-then-update design, then the 2026 ADD-only redesign in the vendor's words. 40 min and 10 min.
The bi-temporal graph, its retrieval, and its LongMemEval results. 35 min and 10 min.
Virtual context management in 2023, and what Letta's memory became in 2026. 35 min and 10 min.
The benchmark section 8's questions imitate, with design findings (store rounds, expand keys with facts, time-aware queries); and the independent comparison against BM25 and long context. 40 min and 35 min.
The 2025 LOCOMO dispute in the vendors' own words. 25 min.
Semantic, episodic and procedural memory; and memory as files the model edits, with no extraction pipeline at all. 15 min and 10 min.