· Source: Ziyan Yang, Taiwei Shi, Jieyu Zhao (University of Southern California), Forget Freely, Grep Later: Lossless, Index-Free Memory for Long-Horizon LLM Agents, arXiv:2611.25123, 18 Nov 2026. Surfaced by Pascal Biese (LLM Watch).
The short version
When a long-running agent fills its context window, the usual fixes are summarisation, masking old tool outputs, or a structured memory store. Each decides in advance what to keep, and anything it drops is gone. GrepMem keeps summarising to hold working context small, but first appends every message and tool output, verbatim, to a plain-text log. The agent gets one extra tool, regular-expression search over that log, and can pull back an exact value whenever it needs one. No embeddings, no retrieval index, no memory-extraction step and no second model are involved.
Results, with Qwen3.5-9B trained by reinforcement learning under five context-management strategies:
On ContextBench (recalling exact values and log lines from histories far past the window), GrepMem scores 95 to 97% where lossy baselines manage at most 21%.
On BCP-Multi (multi-question research sessions), it beats SUPO-style summarisation by 8.8 points.
It stays on the accuracy versus token-cost Pareto frontier across all five evaluation tasks and scales as input streams grow.
How it works
Append-only log. Every turn (user message, model output, tool call and tool result) is written to a text file before anything is compressed.
Normal context management. When the window fills, the agent summarises as usual. The summary is the working memory, and the log is the archive.
Grep as a tool. After the first summary, the agent can call a regex search over the log and get matching lines, with surrounding context, back into the window.
Trained to use it. The model is RL-trained with the tool available, so it learns when a detail is missing from the summary and worth looking up.
Compare lossy memory, which decides what matters at write time, with GrepMem, which keeps everything and decides at read time. That is the old log-structured storage argument: append cheaply, query later.
Why it matters
Most agent memory stacks are premature. Before adding a vector store, a knowledge graph or an extraction pipeline, try a log file and grep. That baseline is already lossless and cheap.
Exact recall is the common failure. IDs, file paths, error strings and numbers are the details summaries lose and agents need. Regex search finds them by construction.
Operationally boring. A text file needs no index to rebuild, no embedding model to version and no schema to migrate, and it doubles as an audit trail.
Tradeoffs and limits
Keyword-dependent. Regex only finds what the agent can name. Paraphrased or conceptual recall ("the earlier approach we rejected") needs semantic retrieval or a good summary.
One model, controlled benchmarks. The authors and the curator both flag the evidence as preliminary.
Training matters. The model was RL-trained with the tool. An off-the-shelf model may under-use it or over-search.
Overhead when not needed. Searching when the summary already holds the answer costs tokens and turns.
Unbounded growth. The log grows without limit. Long-lived agents need rotation or per-task scoping, or search output gets noisy.
Failure modes to watch
Over-broad patterns that flood the context with hundreds of matching lines. Cap the result count and line length.
Secrets in the log. A verbatim log keeps every token and credential a tool ever printed. Redact on write, or keep the log out of shared storage.
Stale facts. Grep returns the first match it finds, not the latest truth. Prefer newest-first output, or include timestamps in each line.
Summary drift. If summaries silently drop the fact that a detail exists, the agent never thinks to search for it. Summaries should keep pointers ("the full error is in the log at step 14").
Review checklist
Is every tool output appended to a log before summarisation or truncation?
Does the agent have a bounded, line-capped search tool over that log?
Are secrets redacted on write, and is the log's retention and access controlled?
Do evals include exact-value recall past the context window, not only task success?
Do summaries keep pointers to what was archived, so the agent knows what to search for?
Have you compared against this baseline before adding embeddings or a memory database?
Related entries
R059 Memory Tax: when agent memory loses to searching the raw history. Earlier evidence for the same point: raw history plus search is a strong baseline.
R226 Jetriever: rank every agent memory by usefulness, not similarity. It is the opposite design, using model-scored semantic retrieval for links that keywords miss.
R088 MemCredit: pick agent memories by decision utility, not relevance.
R147 Anthropic's components of agent memory: notes, dreaming, wikis, injected context.