Grafy News
Try Grafy free

New GrepMem method offers lossless memory for AI agents

Researchers have introduced GrepMem, a memory mechanism that uses plain-text logs and regular expressions to prevent information loss in long AI tasks.

Illustration for the news story: New GrepMem method offers lossless memory for AI agentsSource: Grafy Research Lab

Long-horizon Large Language Model (LLM) agents often struggle to retain critical details when their interaction history exceeds their context window. Researchers from the University of Southern California have introduced GrepMem, a memory mechanism designed to prevent the information loss typically caused by context compression or summarization.

What is the problem with current AI memory?

As AI agents perform complex, long-term tasks—such as deep research involving multiple documents—they accumulate vast amounts of data. Because every model has a finite context window, they must eventually discard or compress older information to make room for new inputs. According to the researchers, existing strategies like summarization, masking, or structured memory often rely on "lossy" compression. This means the agent makes a preemptive decision about what is important to keep, potentially discarding specific details that might become crucial later in the session.

How does GrepMem work without an index?

Unlike traditional retrieval-augmented generation (RAG) systems that require complex vector embeddings and retrieval indices, GrepMem operates on a much simpler principle. The system consists of two primary components: an append-only, plain-text log that records the agent's entire history, and a regular-expression search tool for on-demand recall.

When the agent's active working context reaches a certain limit, the system performs a "compaction" step, where the history is summarized to keep the immediate reasoning loop efficient. However, instead of deleting the original details, GrepMem appends every message and tool output to a persistent log. If the agent needs to recall a specific fact or identifier encountered much earlier, it can use a tool called grep_history to search the raw text log using regular expressions. This allows for lossless retrieval without the need for additional models or complex memory extraction infrastructures.

How does it compare to existing methods?

The researchers tested GrepMem against several established context management strategies, including ReAct, observation masking, SUPO (a summarization-based approach), and MemGPT-style memory. They trained a Qwen3.5-9B model using reinforcement learning to optimize these different approaches.

In terms of accuracy, GrepMem demonstrated significant advantages in tasks requiring precise recall. On the ContextBench benchmark, GrepMem achieved accuracy rates between 95% and 97%. In contrast, the researchers reported that lossy baselines, such as SUPO's summarization and observation masking, achieved at most 21% accuracy on the same task. On the BCP-Multi benchmark, GrepMem outperformed SUPO's summarization by 8.8 percentage points and exceeded MemGPT by 7.0 percentage points.

Does this method increase computational costs?

While maintaining a full history log might seem resource-intensive, the study suggests that GrepMem remains highly efficient. The researchers found that GrepMem stays on the accuracy–token-cost Pareto frontier across all five evaluation tasks. This means it provides a superior balance of high accuracy and manageable token usage compared to other methods. For instance, on the ContextBench task, GrepMem utilized only 29% of the tokens required by MemGPT while achieving substantially higher performance in specific areas like Log Triage.

What are the practical implications for AI development?

The findings suggest that complex, structured memory infrastructures may not always be necessary for long-horizon tasks. A simple, searchable text log can provide a competitive and scalable way for agents to manage long-term memory. This could lead to more reliable agents in fields like automated research or software engineering, where missing a single line of code or a specific data point can cause a total task failure.

For researchers and developers looking to explore how AI handles large volumes of information, tools like Reader allow for deep interrogation of extensive PDF documents and research papers. While GrepMem is a specialized architectural approach for autonomous agents, the ability to search and question large datasets is a core requirement for modern AI-driven workflows.

Frequently asked questions

Does GrepMem require vector embeddings?

No, GrepMem does not require embeddings or a retrieval index. Instead, it relies on a plain-text log of the agent's complete history and uses regular-expression searches via a grep_history tool to perform on-demand, lossless recall of specific information.

Why is GrepMem considered lossless?

GrepMem is considered lossless because it preserves every message and tool output in an append-only log. While the active working context is compressed through summarization to save space, the original, uncompressed details remain available for the agent to retrieve whenever necessary.

How does GrepMem scale with long input streams?

GrepMem scales effectively as input streams grow longer. Because it separates the bounded working context from the persistent history log, it can maintain high accuracy on recall tasks even when the total history far exceeds the model's primary context window.

Source: Ziyan Yang, Taiwei Shi, and Jieyu Zhao, "Forget Freely, Grep Later: Lossless, Index-Free Memory for Long-Horizon LLM Agents"


Source: Grafy Research Lab — Forget Freely, Grep Later: Lossless, Index-Free Memory for Long-Horizon LLM Agents