Memory that is never evaluated becomes folklore. Agents keep using it because it feels helpful, while nobody measures whether it improves outcomes, whether it injects stale facts, or whether it quietly teaches the agent to trust its own notes over fresh evidence. This skill covers how to evaluate memory, meaning metrics, failure taxonomies, regression harnesses, and controlled comparisons, so that memory changes are decisions backed by numbers instead of vibes. It builds on ../memory-recall/SKILL.md and ../memory-retrieval-strategies/SKILL.md, which cover how recall works, and adds the measurement layer that judges whether that recall helps.
Quick Workflow
- Build a fixed evaluation set of questions with known correct answers drawn from the store's own sources.
- Run each question twice, once with memory enabled and once without, and record both outcomes.
- Score recall quality separately from task quality, so a good answer built on bad recall is still visible as a failure.
- Classify every failure using the taxonomy in section 3, and count failures by class before fixing anything.
- Add the failing cases to a regression set that runs on every memory change.
- Ship a memory change only when the regression set passes and the controlled comparison shows no harm.
1. Recall metrics that mean something
Precision and coverage are the two metrics that matter most for recall, and both need a judged answer set, not vibes. Precision asks how much of what was returned was correct. Coverage asks how much of what was needed was returned. The scorer below computes both from a simple judged format, and it keeps the judgement separate from the retrieval code so judges can disagree without touching the harness.
"""Recall scoring: precision and coverage from judged result sets."""
def score_recall(returned_ids, needed_ids):
returned = set(returned_ids)
needed = set(needed_ids)
hits = returned & needed
precision = len(hits) / len(returned) if returned else 0.0
coverage = len(hits) / len(needed) if needed else 0.0
return {"precision": round(precision, 3), "coverage": round(coverage, 3)}
# Example: 4 of 5 returned records were needed, and 4 of 6 needed
# records were returned, so precision 0.8 and coverage 0.667.
print(score_recall(
["mem_011", "mem_042", "mem_007", "mem_103", "mem_210"],
["mem_011", "mem_042", "mem_007", "mem_103", "mem_301", "mem_302"]))
Interpretation rules:
- High precision with low coverage means the retriever is timid. It returns safe rows and misses the decisive fact, which usually means expansion or filters are too narrow.
- Low precision with high coverage means the retriever is noisy. It finds everything and buries it, which usually means reranking is weak or the context budget is too small.
- Both low means the knowledge is missing, misworded, or stored in the wrong layer, which is a capture problem, not a retrieval one.
- Report metrics per layer. A store-wide average hides a semantic layer that works and an episodic layer that does not.
2. Controlled comparison and faithfulness checks
A controlled comparison isolates the effect of memory by holding everything else fixed, same task, same model behaviour, same tools, with memory on versus memory off. Run at least 20 tasks per arm before drawing conclusions, because small samples flip on noise. Faithfulness checks then ask whether the answer actually follows from the recalled records, or whether the agent invented a plausible bridge between them.
"""Controlled comparison harness: memory on versus memory off."""
import json
def run_arm(tasks, memory_enabled):
results = []
for task in tasks:
outcome = run_task(task, memory_enabled=memory_enabled)
results.append({"task": task["id"], "passed": outcome.passed})
passed = sum(1 for r in results if r["passed"])
return {"arm": "memory_on" if memory_enabled else "memory_off",
"tasks": len(results),
"passed": passed,
"pass_rate": round(passed / len(results), 3) if results else 0.0}
# run_task is supplied by the task harness. This harness only records
# outcomes, so the comparison cannot be gamed by changing the scorer.
Faithfulness check procedure:
- For each factual claim in the answer, find the recalled record it rests on, or mark it unsupported.
- A claim that restates a record with changed numbers, dates, or names is a hallucination, even if the rest of the sentence is correct.
- A claim with no supporting record but marked as recalled knowledge is an attribution failure, covered in depth by the sub-skill sub/memory-source-attribution/SKILL.md.
- Report the unsupported claim rate alongside the pass rate. A task can pass for the wrong reason, and that pass teaches nothing.
3. Failure mode taxonomy
Classify before fixing, because different failure classes need different fixes, and fixing the wrong class wastes the effort. The taxonomy below covers the failures seen most often in agent memory systems, with the diagnostic question that separates each class.
# memory-failure-taxonomy.yaml - classes and their diagnostic questions
failure_modes:
stale_recall:
symptom: correct at capture time, wrong now
diagnose: compare record date against live source date
fix: shorten TTL for fast-changing facts, verify before acting
missing_capture:
symptom: retrieval returns nothing useful
diagnose: check whether the fact was ever stored
fix: capture gap, not a retrieval fix
vocabulary_mismatch:
symptom: fact exists but queries never match it
diagnose: compare query terms against stored terms
fix: query expansion, better tags, or reworded capture
over_trust:
symptom: agent follows low-confidence recall without checking
diagnose: check confidence floor for the action taken
fix: raise the floor, require fresh verification for actions
contamination:
symptom: one agent or tenant pollutes another scope
diagnose: check reader scope and promotion paths
fix: scope enforcement, promotion gates, and cleanup
summary_drift:
symptom: summary states something the sources never said
diagnose: diff summary claims against source records
fix: summary validation checks, stricter summarization rules
attribution_loss:
symptom: fact survives, its source does not
diagnose: check source links on semantic records
fix: require sources at promotion, demote sourceless facts
Count failures by class over a fixed window, and fix the largest class first. A taxonomy with counts beats a list of anecdotes, and it stops the team from fixing the failure that was loudest instead of the failure that was commonest.
4. Regression harness
A regression set is a small, fixed set of questions and expected records that runs on every memory change, including schema changes, TTL changes, reranker tuning, and summarization updates. The harness below runs the set and fails loudly on any regression, so a change that improves one query at the cost of three others cannot slip through quietly.
#!/bin/bash
# memory-regression.sh - run the fixed regression set, fail on any miss
set -euo pipefail
python3 memory_regression.py --set regression/questions.jsonl \
--min-precision 0.8 --min-coverage 0.7
echo "Memory regression set passed."
"""Regression runner: every question must return its expected records."""
import json
import sys
def run_regression(path, min_precision, min_coverage):
failures = []
with open(path, encoding="utf-8") as handle:
for line in handle:
case = json.loads(line)
hits = recall(case["query"], limit=10)
score = score_recall(hits, case["expected_ids"])
if (score["precision"] < min_precision
or score["coverage"] < min_coverage):
failures.append((case["id"], score))
return failures
# recall and score_recall are supplied by the store and section 1.
# A non-empty failures list exits non-zero, so CI catches regressions.
Keep the regression set small, around 30 to 50 questions, and curated by hand. A large auto-generated set measures the generator more than the memory, and a set nobody maintains rots into noise. Review the set quarterly, retire questions whose answers changed, and add a case for every production failure that reached a user.
Edge cases
- Memory helps on average but hurts one critical task class. Report per-class results, not just the average, and gate memory use per task class when the harm is concentrated.
- The evaluation set leaks into the store. If test questions or answers were captured as memory, the evaluation measures memorized test data, not retrieval quality. Exclude evaluation material from capture.
- Judges disagree on what counts as needed. Record disagreements and report the range, not a single number, when agreement is low.
- A memory change improves metrics but agents complain. Trust the complaint enough to investigate, because metrics miss latency, readability, and context crowding that agents feel immediately.
- Failure counts drop to zero. That usually means the evaluation set is stale or the harness broke, not that memory became perfect. Refresh the set before celebrating.
Key references
- CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor): why evaluation exports need scoping.
- SQLite documentation: https://sqlite.org/docs.html
- Python sqlite3 module: https://docs.python.org/3/library/sqlite3.html
- ../memory-recall/SKILL.md and ../memory-retrieval-strategies/SKILL.md in this repo.
