Lesson 3 of 4
Resolve Conflicting Memories
Estimated time: 10 minutes
Resolving Conflicting Memories
An agent that keeps notes across runs collects facts from different times and sources. Sooner or later two of them disagree. The tempting fix is to overwrite with the newest write, which silently discards an older entry even when that older entry was the correct one.
Store the context, not just the fact
A fact without a time or a source cannot be weighed against another. Write both alongside each value, so a later conflict can be settled by recency and by whom it came from rather than by write order.
Prefer newest verified, keep the superseded
When one entry is both newer and from a source that can be trusted, let it win and mark the other as superseded instead of deleting it. Keeping the loser means a reversal is auditable, and a wrong win can be undone.
def resolve(a, b):
if a["source"] == b["source"]:
return max((a, b), key=lambda m: m["ts"])
# different sources disagree: this is not ours to settle silently
return None
Surface what you cannot settle
When two sources disagree and neither is clearly newer, write the conflict down and hand it back rather than picking a side. A guessed resolution looks like a fact later and is far harder to correct than an open question.
Tips
- Always store a source and a timestamp with each memory so conflicts are decidable.
- Let the newest verified fact win but keep the superseded entry for reversals.
- Return an unresolved conflict to the caller instead of choosing silently.
- Gotcha: last-write-wins quietly destroys a correct older note whenever a wrong newer one lands.
- Gotcha: two entries from the same source are not independent, so agreement between them proves little.