Agentic Memory Under Context Constraint
Memory systems for LLM agents are mostly judged on retrieval benchmarks: can the right fact be fetched? I asked a different question: when an agent's context window is too small to hold everything it has read, does the way its memory is represented change whether it finishes the task?
To answer it I built an agent harness where every layer can be swapped from config, then ran controlled experiments that change one thing at a time: the memory.
Same task, same model, same seed. Only the memory changes.
A real recorded run, replayed step by step. The agent must find the access code for site_000_02. Three facts in 19 documents chain to the answer, mixed in with 16 look-alike distractors:
The context budget is 2,000 tokens, about seven documents. By the time the agent reads doc_18, the first two facts were dropped from its window long ago. It can only answer if its memory brings them back.
Green chips are the three facts the answer needs. "In window" is what the context still holds after the budget evicts older reads; "memory returned" is what retrieval added back on that step. Data: the run traces, unedited.
Results
Six memory conditions, 30 generated tasks, 2 seeds each, 360 runs at a 2k budget on Gemini 3.5 Flash-Lite. The NoOp (no memory) and Oracle (handed exactly the right facts) conditions bracket what any real memory can do.
Task success on three-fact chains, with 95% confidence intervals
I declared the expected outcome before the paid run: graph beats vector, with a confidence interval excluding zero. It held: +0.62 [0.48, 0.75], paired over tasks with 2,000 cluster-bootstrap resamples. Vector memory returns the root fact because it reads like the goal, but among sixteen near-identical "the access code for X is N" documents it misses the middle link. Graph memory follows entity links from the goal to the chain.
Episodic memory scored zero: with no time range in the query it returns the newest items, which the window still holds anyway. Recency answers "what happened around step 4"; this task needs "what is linked to the thing I was asked about".
A metric that agrees with task success
On the easier two-fact pilot, standard retrieval recall ranked the memories in a way that contradicted their task success. So I introduced dropped-fact recall: of the facts the context window has lost, how many did memory bring back? It is the only one of three definitions consistent with which agents finished.
| Memory | Task success | Step-averaged recall | Final-step recall | Dropped-fact recall |
|---|---|---|---|---|
| vector | 0.98 | 0.97 | 0.61 | 1.00 |
| graph | 0.93 | 0.07 | 0.93 | 0.95 |
| episodic | 0.00 | 0.04 | 0.06 | 0.00 |
Two-fact pilot, 60 runs per row. Step-averaged recall says graph memory is nearly useless (0.07) while it finishes 93% of tasks.
How it is built
The premise: no single agent configuration is best for every task, so whoever runs the agent should be able to choose each component. That is only worth building if the choice actually matters, which is what the study measures.
- Four memories behind one contract. Vector (exact cosine over Qwen3 embeddings), episodic (time-window retrieval, newest first), entity-graph (entities extracted on write, multi-hop walks from the entities a query names, a small GraphRAG), and hybrid (cosine and graph fused by reciprocal rank). The query type carries entities, hop depth and time range, so no representation is forced to smuggle structure through a string.
- Single-variable control. Language model, embedding model, chunking, planner and tools are pinned and hashed into every result row; only the memory changes between conditions.
- Procedural tasks. A generator builds reference chains, distractors, padding and ground-truth labels from a seed, so every result can be re-derived from one number.
- Swappable by config. Each layer has frozen payload types, at least two implementations, a conformance suite, and plugin registration through entry points: a component written outside the repository can be dropped in without forking.
- Built to be trusted. 567 tests at 100% coverage,
mypy --strict, a crash-safe resumable runner, and a spend kill-switch.
What I learned, and what is next
- Graph and hybrid usually fail with the facts in hand. In 16 of graph's 21 failures, memory had returned every lost fact and the model still did not answer. Better memory moves the bottleneck to how the model uses what it is given.
- The ranking depends on difficulty. On two-fact chains vector, graph and hybrid tie with Oracle; on three-fact chains they separate by 60 points. A leaderboard at one difficulty would mislead.
- Next: the context budget as an axis. The full experiment sweeps the budget to find where the choice of memory stops mattering, so the advice becomes "below this budget pick X; above it, it does not matter".
These are pilot results: graph versus hybrid is not yet separated at this sample size, and I report that rather than a winner.