Learn

Architecture & pattern guides

Read the idea, build it on a Grid, prove it in a challenge. Short, practical guides — illustrated with RodGrid's own nodes — on system design, design patterns, flow modeling, and how to get the most out of the app.

All articles

Long-term memory for assistants: write, recall, update, forget

How an assistant remembers a user across conversations: what to write down after each reply and what not to keep, how to recall a few relevant lines within a token budget, how to replace a fact that changed, and how users see and delete what was kept.

Same as last Saturday, but for six

Tomás opens the cooking assistant in his supermarket's app on a Friday evening and types Same as last Saturday, but for six. Last Saturday it planned him a vegetarian lasagne and a lentil soup. Tonight it asks: Could you tell me what you made last Saturday? Nothing is broken. This is a new conversation, and a new conversation starts empty.

A model keeps nothing between calls; it reads what the application sends each time. Within a conversation the app resends the recent turns, and a long thread has to be trimmed or summarised once it outgrows its budget, so by turn 200 turn 1 may be gone (Context windows: what an agent keeps, trims & hands off). Across conversations nothing carries over unless the application stores it and brings it back.

Resending 14 months of conversations, some 700,000 tokens, would overflow many context windows and be paid for on every call. The assistant needs a few lines: last Saturday's plan, that the household is vegetarian, that he lives in Porto. Long-term memory is a store of those lines, outside the model and per user, with one path that writes it and another that reads it back.

An episode and a fact

Tonight's request needs two kinds of record. Last Saturday points to an episode. A conversation summary, written when a conversation ends, says what happened in it and when: Sat 7 Mar: planned vegetarian lasagne and lentil soup for four; list sent to basket. Vegetarian is a fact about Tomás, true until it stops being true: Household is vegetarian. Cooks for four on weekdays. Dislikes coriander.

A summary describes the past and stays as written. A fact describes the present and has to change when Tomás's life does. Both are written by a model, both can be wrong, and both are personal data.

Writing happens after the reply

Facts arrive in passing. When a turn ends, the chat service sends its reply first and then puts the new turns on a queue. A memory extractor, a worker reading that queue, makes its own model call: here are the latest turns, and here are this user's existing memories that look similar; which durable facts or preferences do the turns contain, and is each one new, an update to an existing memory, or already known?

Running it after the reply keeps that call out of Tomás's wait and lets it retry without touching the conversation. The price is a lag: a fact said seconds ago may not yet be recallable from another conversation, though it is still in the current one.

The comparison is what catches duplicates: we're vegetarian at home and household is vegetarian are one fact, and near-copies would crowd everything else out at recall. Each memory that survives is a record holding:

  • the user it belongs to, taken from the authenticated session;
  • the text, short and readable on its own: Household is vegetarian, not he said they don't;
  • the conversation and turn it came from, and when;
  • the extractor's confidence, so that a guess (my sister is vegan read as Tomás being vegan) can be kept out of recall until he confirms it;
  • its status: active, or replaced by a later record.

What the extractor lets pass

In March Tomás asks for a dessert and adds: nothing too sweet, since the diabetes diagnosis I keep sugar down. The assistant should use that in this conversation. Keeping it is a separate decision, because data protection laws such as the EU's GDPR put health in a special category, with religion, ethnic origin, political opinions, sexual orientation and a few others, under stricter conditions. Tomás asked for a dessert, not for his diagnosis to be kept.

So the write path has a filter: the extractor is told not to propose such memories, and a separate check drops any proposed record in those categories unless the source turn shows the user asked for it to be remembered. Remember that I'm allergic to peanuts is such a request, and in this design that record is stored, marked sensitive; whether a request made in chat meets the law's conditions is a legal question the filter does not settle. Prefers sugar-free recipes for medical reasons still records a health condition, and classifiers miss cases, so the filter narrows the risk and the memory page below is the second line.

Recall: a few lines, picked for this message

Before every reply, the memory service embeds Tomás's message, with the recent turns when it depends on them, and searches an index of memory embeddings, restricted to his user id, for the nearest few dozen (the search itself is Vector search: embeddings, nearest neighbours & hybrid search). A relative date is resolved first: last Saturday becomes 7 March, and that day's summary is fetched by its date, since similarity alone may miss it or prefer an October lasagne. The rest are ranked by relevance and recency, and lines are taken from the top until a 600-token budget is full. The lines go into the prompt with their dates.

Similarity has a blind spot. Something quick for tonight has little in common with allergic to peanuts, so a pure search can leave the allergy out of the very request that ends in a satay sauce. So the few records that matter on every request, diet and allergies here, are pinned and sent every time; everything else earns its place by relevance.

Recall before the reply, writing after it

Recall runs before the model call and returns only this user's lines, within a budget. The extractor runs after the reply and decides whether each fact is new, an update or already known.

Porto, then Lisbon

In September Tomás writes: We moved to Lisbon last month, can you plan the week? If the extractor only adds, the store now holds lives in Porto from January and lives in Lisbon from September, both active. Recall returns both, the model guesses, and sometimes it fills a basket from a store about 300 km away.

Recency only orders the two records; nothing says one replaced the other. That is decided at write time. When a new fact contradicts an active one on the same subject, the extractor treats it as an update, so the store does not keep both as live memories: the Porto record is marked superseded, with a pointer to the Lisbon record and to the conversation where Tomás said it, and recall stops returning it. It stays only as history, which explains last week's order and lets a misread sentence be undone. Not every change is that clean: we eat fish on Fridays now leaves household is vegetarian no longer true as written, so the update is a new diet record, no meat, but fish on Fridays, that supersedes the old one the same way. Telling an update from a separate new fact is the extractor's hardest call.

Tomás's memories, and only his

A recall bug that drops the user filter puts one customer's allergies into another customer's prompt: a data breach, not a bad recommendation. So the user id comes from the authenticated session, never from anything the model wrote, and the store's query applies the filter, or each user gets a namespace of their own.

A store written by a model from things said in passing also has to be readable by the person it describes. The app lists Tomás's memories with where each one came from, and lets him correct one (not vegetarian any more), delete one, or delete them all; a correction supersedes the old record like any other update. Deleting has one trap of its own: the summary of the conversation where he mentioned the peanut allergy was written before the deletion and still says so. Removing every copy, the record's vector in the memory index included, is Deleting a person's data: erasure across every copy.

Why a document index is not enough

The read path uses the same tools as The RAG stack: embed, retrieve, rerank, but documents are usually written by people and shared by everyone allowed to read them. Memory is written by a model from one user's conversations, changes week to week and can contradict itself. That is why it needs supersession, a source on every record and a filter on what may be written at all.

The Long-Term Memory for an AI Assistant Challenge asks for this assistant used by millions, and two designs fail it in ways this article has shown. One only adds records, so after September it still sends Tomás's basket to a store in Porto. The other deletes from the records table alone, and a year later recall finds the peanut allergy in an old summary.

Practice this