Cross-Session Memory: From Retrieval to Reasoning
Agents often fail across sessions not because a single reply is weak, but because memory does not reliably carry identity, agreements, and corrections forward. This article explains why storing similar text is not the same as understanding it, contrasts fragment memory with structured fact memory, and outlines write, read, evaluation, and engineering boundaries for memory that can be updated, expired, and traced.
Agents are often hard to use not because a single-turn answer is not smart enough, but because they have no reliable memory across sessions. When a conversation ends, who the user is, what was agreed last time, and which conclusions have already been corrected all return to a blank slate. The system can only ask again, or guess from similar text. This is not a UI problem. The memory model itself treats “it was stored” as “it was understood.”
The problem is disconnected facts, not storage capacity
A common approach is to chunk the conversation, embed it, and retrieve a few passages by similarity. That works for restating something like “the filename mentioned last time.” It is weak for questions that require reasoning.
Suppose the system knows “fire gives off light” and also knows “fire is hot.” The user later asks, “Can something that gives off light be hot?” If the two facts are only independent vectors, retrieval may return one of each, but the model is never required to form a causal link. The answer then wavers or denies the connection. Time is just as easy to lose. Last week’s preference, yesterday’s correction, and today’s temporary exception cannot be ordered by similarity, so an old conclusion can override a newer one.
Long-term memory therefore has to answer at least four questions at once: what was recorded, when it holds, whom it concerns, and whether it can still be used for reasoning. Optimizing only the number of recalled items does not fix the disconnect.
Two architectures, and why they differ
Common industry designs can be abstracted into two paths rather than tied to any single product.
1. Fragment memory
On write, store the original text or a summary vector. On read, run a similarity search and place the matching fragments into context.
The advantages are fast implementation, fidelity to the original wording, and few engineering dependencies. The drawback is that time, entities, contradictions, and causation all sit implicitly in the text, where the retriever cannot see them. As context grows, noisy fragments crowd out the facts that actually matter. This fits support scripts, document Q&A, and short-lived task drafts.
2. Structured fact memory
On write, first extract entities, attributes, events, time ranges, and confidence, then build relationships that can be queried. On read, do more than ask “how similar is this?” Filter by subject, time, and conflict rules, and combine facts across hops when needed.
The advantages are the ability to distinguish “once true” from “true now,” and to assemble scattered facts into an answer. The drawbacks are extraction errors, loss of original wording when the schema is poorly designed, and higher write cost. This fits personal assistants, long-running project collaboration, and cases that must audit “why it was remembered this way.”
Most production systems should be hybrid: original text or summaries as an evidence layer, and structured facts as a reasoning layer. Factual questions go through the reasoning layer; questions about the original wording fall back to the evidence layer.
Writing: decide before you store
Storing everything indiscriminately dirties the memory store quickly. Collapse a turn into candidate memories, then decide what to keep.
An illustrative flow:
def retain(turn, store):facts = extract_facts(turn) # subject, predicate, object, time, source sentencefor fact in facts:if is_ephemeral(fact): # small talk, one-time verification codes, and similar itemscontinueold = store.find_conflicts(fact)if old and fact.newer_than(old):store.supersede(old, fact) # expire the old fact; do not physically erase itelif not store.covers(fact):store.add(fact, evidence=turn.span)store.add_episode(summary=turn.summary, time=turn.time)
Five points matter.
First, separate episodic from semantic memory. An episode is “we discussed the release window last Wednesday.” A semantic fact is “this service releases on Thursday by default.” Keep both, but query them on different paths.
Second, update by superseding, not by overwriting and deleting. Keep the expiry time and the evidence so the system can explain “why I changed my answer.”
Third, deduplicate and merge before writing. The same preference phrased differently should not become two records that fight each other.
Fourth, keep sensitive fields out of long-term memory by default, or encrypt them separately and shorten their retention. The longer memory lasts, the larger the exposure.
Fifth, if extraction fails, fall back to a short summary so structure does not discard the only clue.
Reading: constrain reasoning, do not only recall
Recall should not return only top-k text. A more reliable read locates the entity and the time first, then fetches evidence, and only then lets the model answer within the given facts.
def recall(query, store, now):entities = link_entities(query)facts = store.query(entities=entities,valid_at=now,limit=20,)facts = resolve_conflicts(facts) # newer supersedes older; higher confidence winsevidence = store.fetch_spans(facts)return reason(query, facts, evidence)
Three rules belong on the read path. By default, time means “still valid now”; widen that only when the user explicitly asks about history. Do not dump conflicting facts into the prompt and let the model choose; resolve them first. If evidence is insufficient, say so instead of filling the gap with a similar but unrelated fragment. Multi-hop questions—light and heat, people and responsibilities, plans and delays—should be joined at the fact layer, not left to one vector search that happens to hit both passages.
How to tell whether a design is better
Do not judge from how a demo conversation feels. Measure repeatable tasks.
- Correctness: preferences, project agreements, and revoked decisions are still right when asked again the next day.
- Temporal consistency: after a correction is inserted, the old answer expires, while historical questions can still be traced.
- Reasoning connectivity: two facts written separately can answer a question that requires combining them.
- Resistance to pollution: small talk, bad extraction, and contradictory input do not make memory steadily worse.
- Cost and latency: extraction on write, relationship queries, and context length stay acceptable.
- Explainability: the system can point to which memory it used and when it was written.
If the workload is mainly document retrieval, fragment memory is enough. Forcing structure only adds extraction errors. If the workload is a multi-day assistant, ongoing project state, or personalized policy, fragment memory alone starts to fail noticeably by the second week. There, a fact layer is worth the complexity.
Engineering boundaries in production
The memory service should be split from the conversation runtime. The conversation owns the current turn; memory owns what crosses sessions. Keep the interface to four operations: write, read by condition, expire, and delete. Do not hard-code vendor-specific parameters into the business logic.
Isolate permissions by user and workspace. Do not recall across tenants from a global vector store. A deletion request must clear facts, episodes, and vectors together, so the record is not gone from the UI while retrieval still finds it. Observe the count of hit facts, the number of conflicts, and the extraction rejection rate, not vector similarity alone.
A longer model context does not replace explicit memory. A larger window only lets more old fragments in together. Time and contradiction problems remain. Design “remembering” as facts that can be updated, expired, and traced, not as an ever-growing chat log. Only then does an agent stop starting from zero every time.
