Skip to content
AI-grafen
FAI engineeringMemory systems· about 90 min· fast-moving, sources checked often· verified 2026-09-20· EN

Contradictions and updating facts

Be able to detect and handle contradictory memories with timestamps and sources.

Prerequisites

Intuition

The memory contains «prefers code examples» from March. In October the user says «I would rather have the formulas first». Now there are two contradictory facts.

Detection: at consolidation, new facts are compared with the existing ones within the same type and subject. An NLI model or an LLM decides whether they are contradictory.

The resolution, in priority order:

  1. Explicit over derived. Something the user has expressly said beats something the system guessed from behaviour.
  2. Newer over older — but only when both are equally explicit.
  3. More support over less. Three episodes beat one.
  4. A draw → ask the user, or keep both with a low confidence and avoid acting on them.

Rule four is the most important: guessing wrong in a contradiction is worse than asking.

Code

from datetime import datetime

SOURCE_WEIGHT = {"explicit": 3.0, "confirmed": 2.0, "derived": 1.0}

def resolve_conflict(a: dict, b: dict, now: datetime) -> dict:
    """Returns {'keep': fact, 'remove': fact} or {'ask': (a, b)}."""
    def score(f):
        age_d = (now - datetime.fromisoformat(f["ts"])).days
        freshness = 0.5 ** (age_d / 180)
        return SOURCE_WEIGHT[f["source"]] * freshness * (1 + 0.2 * len(f["sources"]))
    pa, pb = score(a), score(b)
    if abs(pa - pb) < 0.25 * max(pa, pb):        # too close → do not guess
        return {"ask": (a, b)}
    winner, loser = (a, b) if pa > pb else (b, a)
    return {"keep": winner, "remove": loser, "motivation": f"{score(winner):.2f} > {score(loser):.2f}"}

# Always log which fact replaced which — otherwise it is impossible to debug
# when the agent suddenly behaves differently towards a user.

The trap to avoid: silent deletion. When a fact is replaced it should be visible in the log — and preferably to the user in the settings. A memory that changes invisibly is impossible to trust.

Mastery means

  • Detects contradictory facts
  • Resolves conflicts with the time, the support and the source
  • Knows when the user should be asked

Sign in to do the exercises and build your mastery up.

Sources

All the sources and licences