Consolidate repeated and conflicting memory facts while keeping the latest trusted state.
The full prompt is available without an account.
Implement deduplicate(messages).
- messages is a list of {"role": ..., "content": ...} dicts.
- Normalize each message content before comparison: lowercase, strip
whitespace, collapse internal whitespace, and remove punctuation.
- When two messages have the same normalized content, keep only the
**latest** occurrence (the one appearing later in the list).
- Preserve the relative order of unique messages.
- Return the deduplicated list.
Read-only Python 3.12 preview. Sign in to edit and execute it.
import string
_NORM_TABLE = str.maketrans("", "", string.punctuation)
def _normalize(text: str) -> str:
return " ".join(text.lower().translate(_NORM_TABLE).split())
def deduplicate(messages: list[dict]) -> list[dict]:
# TODO
return messages