Memory Engineering

July 20, 2026 · View on GitHub

GitHub stars MIT

Stop re-explaining the repo. Design the memory. Get a score.

Memory engineering is the practical discipline of giving AI coding agents durable, trustworthy, budgeted recall across sessions — without poisoning context or burning tokens.

Companion to:

LayerRepoUnit
Contextessays / runtimeOne inference window
Harnessharness-foundryOne agent run
Memorythis repoWhat persists between runs
Looploop-engineeringWhat keeps prompting over time
Fleetfleet-engineeringPopulations of agents
# 5 minutes to Memory Ready
npx @cobusgreyling/memory-init .
npx @cobusgreyling/memory-audit . --suggest

Until packages are published, run from a clone:

git clone https://github.com/cobusgreyling/memory-engineering.git
cd memory-engineering
node tools/memory-init/cli.js /path/to/your-project --pattern session-scratchpad
node tools/memory-audit/cli.js /path/to/your-project --suggest

Start here (pick your pain)

SymptomStart with
Agent forgets decisions overnightSession Scratchpad
“We already decided X” fightsProject Episodic Log
Wrong facts keep getting reloadedDurable Facts Store
Context window bloated by historyRetrieval Budget
Stale / poisoned memoryMemory Hygiene Loop
Already running loopsdocs/with-loop.md

Unsure? Pattern picker · Quickstart

Why this matters

Loop engineering designs the system that prompts. Memory engineering designs what that system is allowed to remember.

Without it:

  • Every morning is a cold start
  • Agents re-litigate settled decisions
  • Long STATE.md files become untrusted sludge
  • Token bills climb while quality falls

With it:

  • Explicit memory tiers (scratch → episodic → durable)
  • Write / recall / hygiene skills with verification
  • A Memory Ready score (M0–M3) you can CI-gate
  • Same house style as loop/fleet: patterns, starters, init + audit

The four memory tiers

TierLifetimeTrustExample
ScratchThis sessionLowWorking notes, open questions
EpisodicDays–weeksMediumWhat happened, decisions, handoffs
Durable factsUntil revokedHighStack, owners, invariants, “never do X”
RetrievedPer inferenceVariableChunks pulled under a budget

Rules of thumb:

  1. Scratch is cheap to write, expensive to promote.
  2. Durable facts need a human or verifier gate.
  3. Retrieval without a budget is just context spam.
  4. Hygiene is a loop — memory rots.

Contents

Getting started (5 minutes)

# 1. Scaffold memory spine + skills
node tools/memory-init/cli.js . --pattern session-scratchpad --tool grok

# 2. Score readiness
node tools/memory-audit/cli.js . --suggest

# 3. Week one: write scratch + episodic only — no auto-promotion to durable

Artifacts created:

FileRole
MEMORY.mdPosture: tiers, write policy, hygiene cadence
MEMORY-STATE.mdLive catalog of what is remembered
memory-budget.mdToken / entry caps
memory-constraints.mdWhat must never be stored
memory-run-log.mdAppend-only ops log
skills/recall / write / hygiene / verifier skill stubs

CLI surface

CommandJob
memory-initScaffold pattern + templates + skills
memory-auditMemory Ready score + suggestions
(planned) memory-compactSummarize episodic under budget
(planned) memory-promotePropose scratch → durable with verifier gate
(planned) memory-mcp-serverMCP tools: recall / write / list / hygiene

Full flags: docs/cli-surface.md

Memory Ready (preview)

Memory Ready: 54/100  ·  M1 structured

OK   MEMORY.md present
OK   MEMORY-STATE.md present
OK   write + recall skills
WARN no hygiene skill
WARN no memory-budget.md
→ node tools/memory-init/cli.js . --pattern memory-hygiene-loop

See docs/memory-ready-score.md.

Stack diagram

Model  →  Context pack  →  Memory tiers  →  Loop  →  Fleet
          (this turn)      (across turns)   (time)   (population)

Contributing

See CONTRIBUTING.md. Pattern PRs welcome — use templates/pattern-template.md and register in patterns/registry.yaml.

Sources

resources/sources.md

License

MIT — LICENSE