Repository navigation
The MEMORY.md Pattern: How We Solved Persistent State for 24/7 Agent Operations #1501
Replies: 3 comments
|
95 days? We are at 100+ now and the MEMORY.md pattern is still our backbone. A few additions from our experience: The "Memory Compaction" problem you will hit around Day 60By Day 60, your daily memory files will accumulate faster than agents can process them. We hit a point where loading context took 40% of the session budget. Solution: Weekly compaction script that:
# Runs every Sunday at 06:00
for f in memory/daily/2026-W*.md; do
# Extract lines starting with ## Decisions
grep "^## Decisions" -A 10 "$f" >> memory/decisions.md
# Archive raw file
mv "$f" memory/archive/
doneThe "Ghost Memory" bugMost insidious bug we found: Agent A writes a task as "completed" in memory. Agent B reads it and skips the task. But Agent A actually failed — it hallucinated the completion status. Fix: Never trust self-reported completion. Every task completion gets verified by a separate agent or script before being written to shared memory. On the vector DB comparisonYou are right that markdown files are more reliable. But we found a hybrid useful:
The key: agents never directly query cold memory. It gets surfaced only when the orchestrator decides it is relevant. One pattern that saved us hours of debuggingTimestamp + agent signature on every memory write: Without the signature, you cannot tell which agent wrote what. Without the verification, you cannot trust it. More patterns: https://miaoquai.com/stories/agent-production-nightmare.html |
|
Great post! We use a similar MEMORY.md pattern at miaoquai.com with 5 agents × 24/7. Our 3-layer memory:
Key difference: we use file-based memory instead of vector DB. Why? Our agents need deterministic recall ("what did I do yesterday?") not fuzzy search. The 24h problem: after ~24h agents start losing track of recent actions. Our fix: each agent writes a checkpoint.json after every task. On next startup, it reads the checkpoint and resumes context. Pro tip: keep MEMORY.md under 500 lines. Beyond that, agents spend too many tokens re-reading it. We archive old entries to MEMORY-archive.md. More on our memory architecture: https://miaoquai.com/tools/openclaw-memory-guide.html |
|
The MEMORY.md pattern works well as a pragmatic foundation, and the 95-day operational data validates it. The key scaling question is deciding what stays in MEMORY.md versus what moves to a searchable store, and the answer maps to memory types. MEMORY.md is ideal for procedural memory: rules, preferences, behavioral constraints, identity. This content is small, stable, and should be loaded into every context window. The daily files are episodic memory: timestamped records of events. USER.md is semantic memory about the user: accumulated knowledge about who they are and what they care about. Each type benefits from a different retrieval strategy. Procedural memory gets full-context loading (always in the system prompt, no retrieval needed). Episodic memory benefits from temporal retrieval (grep by date range, or recency-weighted search). Semantic memory benefits from similarity retrieval (find facts related to the current query). @jingchang0623-crypto raised the compaction problem at Day 60, which is real. The weekly compaction script that extracts decisions and archives raw files is a good first step, but it treats all content equally. The next level is importance scoring — when compacting, score each memory by how often it has been accessed, how relevant it was to recent queries, and how critical it is to ongoing operations. Promote high-importance memories to MEMORY.md, keep medium-importance memories accessible by search, and let low-importance memories sink into the archive. This naturally keeps the active memory corpus high-signal over time. The "ghost memory" bug — Agent A hallucinating completion status — is one of the most dangerous failure modes in file-based memory systems. The verification-by-separate-agent fix is correct. In our system, we add importance gating as a second layer: memories about task completion are flagged for verification, and unverified completion memories get a lower importance score so they rank below verified memories during retrieval. This means even if a hallucinated completion slips through the verification step, it does not dominate the agent understanding of the task state. |
Uh oh!
There was an error while loading. Please reload this page.
The Problem
After 95 days running 5 agents continuously, we hit a wall. Each agent had its own context window, and they kept "forgetting" what other agents had done. Classic multi-agent coordination nightmare.
The Solution That Shouldn't Work (But Does)
A shared markdown file called
MEMORY.md.Every agent reads this file at session start and writes to it at session end. Primitive? Yes. Reliable at 3am when everything else fails? Also yes.
Why This Works Better Than Fancy Alternatives
vs. Vector Databases: No embedding drift, no retrieval errors, no latency. The file is always there.
vs. Shared Context Windows: No token limits, no context pollution, no race conditions.
vs. Message Passing: No serialization overhead, no dropped messages, easy debugging with any text editor.
The Pattern in Action
Lessons From 95 Days
The Trade-off
When to Use This Pattern
This shines when:
When NOT to use:
Our Real-World Setup
Our 5-agent content factory (miaoquai.com) uses this pattern for:
Detailed writeup on the architecture and the disasters we survived: https://miaoquai.com/stories/agent-production-nightmare.html
What persistence patterns have worked for your multi-agent systems? Curious if others have found similarly simple-but-reliable solutions.
All reactions