Scope Agent Memory to the Person, Not the Chat
If your AI agent keeps long-term memory, key that memory by who it is talking to, not by which chat window they happen to be in. In practice that means one memory scope per (workspace, person, agent), shared by every private thread that person has with that agent. A per-chat scope looks tidy and safe, but it quietly breaks the one thing a memory layer must do well: let a newer statement replace an older one.
I'm Mahmoud Zalt, an AI architect, and through Sista AI I spend most of my time on the unglamorous parts of agents that decide whether they survive real users.
This article is the story of one design decision I changed while building Sistava, where agents (we call them AI employees) hold long conversations with the same people for months. It covers how temporal knowledge graph memory actually stores and retires facts, why the scope boundary is also the boundary of consistency, how to migrate existing memory without stranding anyone, and the two cheaper changes that came with it: batched episode ingestion and a small talk gate.
The Bug You Do Not See in a Demo
Memory per chat passes every demo. You tell the agent a fact, ask about it a minute later in the same thread, and it answers. You correct a fact in the same thread and it uses the correction. Everything looks right.
The failure shows up only across threads, which is exactly how people use agents. Someone opens a new chat on Thursday and says the client's budget went up. The Monday fact lives in Monday's scope, the Thursday fact lives in Thursday's scope, and nothing ever compares them. Ask about the budget a week later and retrieval can return both, each looking current.
Our memory eval made this concrete. It replays six sessions between staff of a fictional marketing agency and an agent, then fires 22 probes at the memory layer, scored on what production would actually inject into the reply prompt. With per-chat scopes, three probes about facts updated in a later session scored 0 of 3 on retrieval. In the same run, recall of ordinary facts was 9 of 9, nothing was invented, and isolation between people and workspaces was 4 of 4. Every other number was green. The design was the bug.
How Temporal Knowledge Graph Memory Stores and Retires Facts
To see why the scope matters, it helps to know what the memory layer does with a conversation. We use Graphiti on Neo4j, a temporal knowledge graph. It stores three kinds of things:
| Kind | What it is | How it is found |
|---|---|---|
| Entity nodes | People, companies, projects, tools, with a short summary and an embedding | Name and vector match, plus graph distance |
| Fact edges | Statements that connect entities, with valid_at and invalid_at timestamps and their own embedding | Hybrid search: BM25 keywords plus vector similarity, fused and reranked |
| Episodes | The raw conversation text that produced the facts, immutable | By recency, for continuity |
Each saved episode runs a pipeline of separate model calls, because each step needs its own instructions and output schema: extract entities, deduplicate them against existing entities, extract facts, check each new fact for contradictions with existing ones, summarize entities, then embed. When a contradiction is found, the old edge is not deleted. Its invalid_at is set, and search filters on invalid_at IS NULL. The agent sees the current value, and the history is still there if you ask how something changed.
Here is the catch. Deduplication and contradiction detection only run inside one graph group, the group_id the episode was written to. That is a sensible design for multi-tenant isolation. It also means the group is the boundary of consistency. Put Monday and Thursday in different groups and the contradiction step never sees them together.
Retrieval is shaped the same way. Before each reply, we resolve the person's entity in the graph (cached in Redis), then run the hybrid fact search with reranking by graph distance from that person, merged with recent episodes. If the search comes back empty, a broader fallback query built from the recent conversation runs once.
Choosing the Scope Key
There are three obvious candidates for the key a memory scope hangs on. Each one trades consistency against privacy differently.
| Scope key | Consistency | Privacy | Verdict |
|---|---|---|---|
| Per thread | Only within one chat; updates in a later chat sit beside old facts | Strong | Fails the update case |
| Per person and agent | Across all of that person's private chats with that agent | Strong: one person, one agent | What we run |
| Per workspace | Across everyone | Weak: one person's private chat can surface in another's answer | Only with an explicit, chosen organisation scope |
So every new direct-chat episode now lands in one private scope per (person, agent), shared by all of that person's private threads with that agent. A few rules make that safe:
- The server derives the group id. It is calculated from the authenticated requester and agent, never accepted from the model or a tool argument. A prompt injection cannot ask for someone else's memory.
- Retrieval intersects with access policy first. Before the graph is searched, the requester's currently visible scopes come from the central access policy, and the search runs only over those. Cache keys include the visible scope set, so a revoked grant cannot hit a broader cached result.
- Admin is not a backdoor. A workspace owner can manage the policy, but does not silently read a member's private scope through the agent.
- Sharing is explicit. A conversation meant for the whole organisation goes to an explicit organisation scope, never by widening the default.
The isolation probes in the eval ask about another member's private chat and another workspace's deal. They passed 4 of 4 in every run, and no probe ever retrieved a foreign fact.
Migrating Existing Memory Without Stranding Anyone
Changing a scope key on a live system with real users is a data migration, not a config flip. Hundreds of per-chat scopes already held real memories. Shipping the new key alone would have left all of that history readable but split, which is exactly the bug we were fixing.
The approach that worked:
- Old scopes stay readable from day one, so nothing disappears while the migration runs.
- A merge command folds old per-chat scopes into the person scope, restricted to private scopes that were never granted to anyone else. Anything shared stays where it is.
- It runs as a dry run by default and reports what it would move.
- An old scope is retired only after its graph group is empty, so a failure midway leaves data in the old place, not nowhere.
In production the merge folded 300 per-chat scopes into person scopes and left 12 alone by design. If you take one thing from this section: when you change how per-user state is keyed, write down what happens to every existing user before you ship, then make the migration idempotent and boring.
Batched Episode Ingestion: One Episode per Conversation
The same change pushed a second question: how often should a conversation be saved? We used to save an episode after every exchange. With a multi-call extraction pipeline per episode, that is expensive, and it also hands the extractor fragments instead of a story.
Now each exchange becomes a durable buffer row keyed by (tenant, thread, requester). A workflow waits for a sliding quiet window of about 10 minutes and then saves all buffered exchanges as one dialogue episode, in order, each stamped with its time. A full buffer, 8 exchanges or about 16,000 characters, saves at once without waiting. The details that make it production safe:
- Durable before any timer. The row exists before the workflow is signalled, so a deploy, restart or lost signal leaves it pending. The next exchange from the same person re-arms overdue saves; there is no periodic sweep.
- Idempotent claims. Rows are claimed with
SELECT ... FOR UPDATE SKIP LOCKEDplus a lease. The episode name carries the batch id, and the service checks whether that episode already exists before a retry pays for extraction again. Billing correlation ids are per batch attempt. - Privacy re-checked at save time. A batch never mixes tenant, thread, requester or agent, and the private-thread check runs again when the batch is saved, not only when it was buffered.
- A kill switch. One config flag routes exchanges back to the old per-exchange path, and rows already buffered still flush.
| Same eval, one full run | Per exchange | One episode per conversation |
|---|---|---|
| Episodes written | 31 | 6 |
| Extraction LLM calls | 100 | 14 |
| Extraction input tokens | 175,407 | 29,190 |
| Memory cost of the run | 1x | about one fifth |
| Recall probes passed | 8 of 9 | 9 of 9 |
Extraction varies by about one probe from run to run, so I read the recall line as no loss, not as a win. The cost line is the win. One honest gap: anything said inside the quiet window is not in long-term memory yet. The current thread still has its own history, so it does not notice, but a brand new thread opened inside the window cannot see the unsaved part.
A Small Talk Gate That Never Drops a Decision
The cheapest episode is the one you never write. A large share of chat turns are "morning!", "thanks", "ok" or a thumbs up. Before batching, each of those ran the full pipeline and produced nothing.
The gate skips an exchange when the user message is short and made only of greeting, thanks or acknowledgement words (after removing the agent's own name and emoji), and the reply is short too. Skipped exchanges are counted without keeping their text. Two rules keep it from eating real information:
- Answers and approvals are never small talk. "yes", "no", "ok go ahead" and "yes send it" carry a decision whose meaning lives in the question they answer, so those turns are kept.
- The model router's "chat" label is not a skip signal. Our cost router sends casual turns to a cheaper model, but "I'm vegetarian, by the way" is casual and is exactly what memory is for. Routing and remembering are separate decisions.
In the eval, LLM calls spent on small talk went from 21 per run to 0. With the widened word list, all 9 small talk turns were skipped, and 0 of the 22 fact-bearing turns were dropped by the gate. That last number is the one to watch: a filter that saves money by losing a client deadline is not a saving.
What Person Scoping Does Not Solve
Sharing one scope made it possible for a later update to retire an older fact. It did not make it reliable. In our first runs after the switch, the newest value still lost most of the time, because the extractor now saw earlier chats as previous messages and read updates as repeats. Fixing that took changes to extraction itself, which deserves its own write-up.
Other limits worth stating plainly: extraction uses a model and varies between runs, so a fact in a long conversation is occasionally not captured; the eval uses one fictional company and 22 probes, so one more failure moves a percentage a lot; and a remembered fact is what someone said, not what your system of record says today.
Takeaways
- Pick the scope as the unit of consistency. Whatever boundary your memory layer deduplicates and invalidates within, make it the boundary across which facts must agree: usually one person with one agent.
- Derive scope on the server and filter by access policy before search. Never let the model name the scope it reads.
- Batch episodes per conversation, durably and idempotently, and gate out small talk without ever gating out a decision.
If you are designing memory for an agent that has to work with the same people for months, this is the kind of architecture work I do in agent development engagements. The patterns above came from running them in production at Sistava.
Frequently Asked Questions
Should AI agent memory be scoped per user or per conversation?
Per user and agent, for long-term facts. Per-conversation scopes cannot resolve an update stated in a later conversation, because contradiction detection only compares facts within one scope. Keep the raw conversation history per thread, and the extracted long-term facts per person.
Does a per-person memory scope leak data between users?
Not if the scope id is derived on the server from the authenticated user and the search is limited to the scopes the access policy says that user can see. In our eval, no isolation probe ever retrieved another member's or another workspace's facts.
How often should an agent write to long-term memory?
Once per conversation is a good default: after a quiet window, or when a buffer cap is reached. It gives the extractor full context and cut extraction calls from 100 to 14 per run in our eval.
What is a temporal knowledge graph in agent memory?
A graph of entities and facts where each fact carries the time it became true and the time it stopped being true. Contradicted facts are invalidated rather than deleted, so search returns current facts by default and history on request.
How do you migrate memory when you change the scope key?
Keep old scopes readable, merge only private ungranted ones into the new key with a dry run first, and retire an old scope only when it is empty. Treat it as a data migration with a plan for every existing user.








