Memgraph
Back to blog
Why AI Memory Should Keep Agent History Instead of Summarizing It Away

Why AI Memory Should Keep Agent History Instead of Summarizing It Away

By Sara Tilly
10 min readDecember 4, 2026

One agent session can generate 214 events.

File reads. Shell commands. Messages. Tool calls. Edits. Intermediate guesses. Corrections. Failed approaches. The sequence of actions that eventually led to an answer.

From that session, an AI memory system may add three useful memories:

  • the failure came from the shared token cache
  • the fresh_token_cache fixture fixed it
  • Ana owns auth-service

In AI Memory on Memgraph, we used this session to show how memories point back into the history instead of replacing it. This post asks what that buys you when the next question isn't the one the memories were built for, and how to keep the history without making the agent reread it.

AI memory does not need to choose between two bad extremes. One compresses the past until most of it disappears. The other pushes the entire past back into the model every time something related comes up.

There is a third option.

Keep the history. Structure it. Retrieve what matters. Go back to the evidence when necessary.

Three Memories Do Not Replace 214 Events

Long-term memory is often treated as a compression problem.

A session ends. The system summarizes it, extracts the facts that appear important, stores those facts, and uses them later.

The approach is attractive for an obvious reason. Most future questions will not require every command, message, or intermediate hypothesis from an old session.

The difficult part is deciding what can safely disappear.

When a memory pipeline extracts three facts from 214 events, it is making a prediction about the future: these are the parts later agents will need.

That prediction may be right for the next question and wrong for the one after it.

The three memories are enough when CI goes red on test_login again. They point to the shared token cache, the fixture that fixed it, and the person who owns the service. Now ask a different question:

Why did we use fresh_token_cache instead of changing the cache TTL?

The extracted memory tells you what fixed the problem. It may not tell you why that fix was chosen.

The answer may live in the earlier session: which approaches failed, what was inspected, what someone rejected, and what trade-off led to the final change.

The compact memory gets the agent to the right place.

The raw history explains what happened there.

Diagram of Memgraph Context Graph: memory files and extracted facts form an index over two agent sessions kept in full as history, and recall answers "Why fresh_token_cache instead of changing the cache TTL?" with the dated messages from session A, using about 5,900 tokens instead of 115,000

The Alternative Is Not to Reread Everything

Keeping raw history creates an obvious objection.

If the system preserves hundreds of events per session, does the agent eventually have to read all of them?

It should not.

The point of memory is not to replay the past. It is to find the right part of it.

This distinction is showing up in our benchmark work as well.

On LongMemEval-S, a public long-memory benchmark, each question comes with roughly 115,000 tokens of chat history. An agent that rereads everything sends all of it to the model for every question.

Memgraph Context Graph, our open-source AI memory for coding agents and custom agents, retrieves just under 6,000. In the published results for version 0.12.0, recall returned 5,863 tokens per question on average, and the answers scored 87.4%.

LongMemEval-S tests memory over long conversations rather than coding-agent sessions full of tool calls. It still tests the same trade-off: how little of the history an agent can read and still answer correctly.

The architectural point is more important than the exact ratio:

Preserving history does not mean putting all of history into every prompt.

You can keep the source record while giving the agent a much smaller path into it.

Memory Can Point Into History Instead of Replacing It

Context Graph records each agent session in Memgraph as it happens: every prompt, reply, tool call, and tool result. On top of that history, it adds two kinds of compact structure. Memory files are notes the agent chooses to save, such as a project decision. After a session, a step called reconciliation extracts the entities the session mentions and the facts that connect them.

Neither replaces the session. Both point back into it. A simplified view of the graph Context Graph builds:

(:User)-[:HAD_SESSION]->(:Session)
                          ├─[:HAS_ACTION]->(:Action)         prompts, replies, tool calls, results
                          └─[:PRODUCED_MEMORY]->(:Memory)    notes the agent chose to save
(:Action)-[:HAS_CHUNK]->(:Chunk)<-[:MENTIONED_IN]-(:Person)  an extracted entity, labeled by type

Each memory file links to the session that produced it. Each extracted fact is a relationship between two entities, stored with the sentence it was read from and linked to the message that sentence came from.

That structure changes the role of a memory.

A memory no longer has to be a miniature replacement for everything that happened. It can act as an entry point.

When an agent calls Context Graph's recall tool, the extracted entities and facts help find the parts of past sessions that matter. Recall returns those parts as exchanges: each matching message with its neighbors and its date, so a question stays with its answer. For a question about a problem, it also adds the exchanges that show how the problem was resolved. Memory files and exchanges share a 6,000-token budget by default.

Context Graph does not write a session summary at all. An earlier design stored a summary node for each session, but recall never read it. It cost an LLM call per session and added nothing the messages themselves did not already provide, so it was dropped.

Structure Reduces the Need to Predict the Future

A memory pipeline could try to anticipate every useful future fact while processing the session.

The more aggressively it does that, the more decisions it has to make before anyone knows what the future question will be.

Another approach is to preserve more of the source material and spend more effort on making it navigable:

  • Identify the entities.
  • Connect the facts.
  • Preserve time and sequence.
  • Link memories to sessions.
  • Keep ownership and provenance.
  • Give retrieval a way to move between compact memory and richer evidence.

The system no longer needs a perfect answer to:

Which parts of this session will matter six months from now?

It needs enough structure to find the relevant part when six months from now arrives.

Better Retrieval Can Make Old Data More Valuable

There is another reason not to discard useful raw history too early: retrieval systems change.

The model querying the memory next year may be better than the model that created the memory today. Search can improve. Ranking can improve. The ontology can change. New retrieval strategies can make previously difficult material easier to find.

Data that looked too messy to use when it was stored may become useful later.

Deleted data does not get that opportunity.

This is what makes the distinction between storage and retrieval important.

The raw history can remain stable while the way agents navigate it improves.

The storage decision may last much longer than the retrieval implementation.

Provenance Survives With the Source

Consider a memory:

Ana owns auth-service.

That fact is useful.

The graph becomes more useful when it can also preserve where the fact came from:

  • Which session produced it?
  • When was it recorded?
  • What was happening at the time?
  • Has a later session contradicted it?

The same applies to a technical decision:

fresh_token_cache fixed the test.

The memory says what worked.

The underlying session can preserve why it was chosen, which alternatives failed, and whether the fix was intended to be permanent.

That route back to the source matters whenever an agent needs more than a recalled fact.

History Also Preserves Change

AI memory becomes more useful as it accumulates.

That also means facts can change. One session might record:

Ana OWNS auth-service

Months later:

Marco OWNS auth-service

If the system stores only the latest extracted fact, it can answer:

Who owns auth-service now?

Keeping the underlying history makes other questions possible:

Who owned it during the March incident?

When did ownership change?

Which decisions were made while Ana owned it?

Context Graph's recall returns messages with their dates, and its results tell the model that a later message about the same thing replaces an earlier one. The current answer wins, and the earlier one stays available for questions about the past.

Long-lived memory needs the current state, but sometimes it also needs the path that produced it.

Keeping Raw History Does Not Mean Keeping Everything Forever

Preservation has costs.

Agent sessions accumulate quickly. Tool outputs can be large. Some data should be redacted. Some should expire. Different organizations will have different retention requirements.

So the argument is not:

Keep every byte forever.

It is:

Do not throw information away merely because today's extraction pipeline did not consider it important.

Retention, archival, redaction, and compaction can still be deliberate policies.

Context Graph's privacy controls follow that pattern. Before anything is stored, it drops text marked <private> and redacts recognized secrets. By default, it also keeps at most 100,000 characters of any single text field, such as a tool's output. You can exclude tools or projects from recording, and forget deletes a session along with the facts extracted from it.

That is different from allowing an early summarization step to make an irreversible decision about what future agents will be able to know.

Keep the History. Do Not Make the Agent Reread It.

A useful memory system should not replay 214 events every time a related problem appears.

It also does not have to throw away 211 of them.

The three memories can give the agent a fast route back into previous work. The underlying session can remain available when the next question requires more than those memories captured.

That is the architectural distinction:

Keep the whole history. Do not make the agent reread the whole history.

As models and retrieval improve, preserved evidence gives them something richer to work with.

Memory does not have to predict every question the future will ask.

It needs to preserve a good path back to the answer.

Context Graph is open source in the Memgraph AI Toolkit. To try it with your own coding agents, start with the AI memory docs. If you work in Claude Code or Codex, the Memgraph plugins add it alongside Memgraph skills and the docs.

Further Reading

Join us on Discord!
Find other developers performing graph analytics in real time with Memgraph.
© 2026 Memgraph Ltd. All rights reserved.