How to Build a Zero-Cost AI Memory System: Complete 17-Day Iteration Log
Source: https://x.com/wangray/status/2022833678595035519 Author: Ray Wang (@wangray) Date: 2026-02-15 Stats: 4 retweets / 38 quotes / 176 likes / 16.8K views
From "forgets everything after each chat" to structured persistent memory. A complete 17-day iteration log from a real OpenClaw multi-agent production environment.
Why Agents Need a Memory System
AI agents have one fatal flaw: no real memory.
Every conversation runs inside a context window. It looks like memory, but it gets compressed, degrades, and resets on restart. You spend a whole day with your agent — decisions, preferences, progress — and the next morning it's all gone.
Worse, the agent doesn't know what it forgot. It'll confidently repeat the same suggestions, make the same mistakes, ask questions you already answered.
There's only one fix: write memory to files.
Anything you don't write to a file = something you never knew.
That's the first law from 17 days of real-world use.
Architecture: Three Memory Layers + Three Retrieval Layers
Three Memory Layers
- Workbench:
NOW.md— current status board, refreshed every heartbeat - Journal:
memory/YYYY-MM-DD.md— daily event log, appended in real time - Long-term wisdom:
MEMORY.md— cross-day lessons, updated rarely
Key rule: never mix them.
NOW.mdholds only factual state (who's doing what, what's blocked) — no lessons- Journal holds everything in detail — it's the most complete source
MEMORY.mdholds only genuinely universal wisdom — at most once a day
Three Retrieval Layers
L1: INDEX.md (directory scan, ~1 sec)
↓ not found
L2: directory + grep (file-level search, ~3 sec)
↓ not found
L3: QMD / semantic search (full-text vector, ~5 sec)
Most queries hit at L1. INDEX.md is the entry point for the whole system.
V1: The Naive Approach (Days 1–10)
MEMORY.md — all long-term memory
NOW.md — current state
memory/
2026-01-29.md
2026-01-30.md
...
Problems
MEMORY.mdkept growing (43 lessons in one file), slow to read- Journal was a raw stream — finding a decision meant scanning days of logs
- No categorization — investment lessons mixed with cron scheduling lessons
- Writes unreliable — the Edit tool's exact-match logic silently dropped appended content
- Duplicate work — checkpoint cron ran every 45 min but couldn't see conversation content; heartbeat could see conversations but didn't write memory
V2: Structured Memory (Days 11–15)
The Counterintuitive Finding
After studying the ClawVault project:
Plain Markdown files had 74% memory accuracy — higher than purpose-built vector databases at 68.5%.
Why? Structured Markdown is naturally LLM-friendly. No embedding step, no retrieval pipeline.
The Restructure
memory/
INDEX.md ← master index (first file agent reads on startup)
YYYY-MM-DD.md ← daily journal (unchanged)
decisions/ ← decision records (with frontmatter)
lessons/ ← lessons by topic
people/ ← person profiles
projects/ ← project records
preferences/ ← preference settings
.obsidian/ ← Obsidian-compatible config
Decision Record Template
---
date: 2026-02-08
type: decision
status: active
tags: [community, monetization]
---
# Build community before monetizing
## Context
Considered launching a paid course, but community trust wasn't established yet.
## Decision
Grow the community first, then push the paid course.
## Alternatives Considered
- Launch paid bootcamp directly → rejected (no trust base, low conversion)
- Run free + paid simultaneously → rejected (splits focus)
Lessons Organized by Topic, Not Date
# Cron Scheduling Rules
## US Market Timezone Alignment (2026-02-13)
Beijing time maps to US trading days Tue–Sat. Set cron to `2-6`.
## Write vs Edit Trap (2026-02-13)
Isolated cron sessions tend to use Write and overwrite entire files.
All memory/ writes must use printf >> to append.
Phase 2: Backfill
Used a sub-agent (Sonnet) to scan 17 days of journals and extract:
- 17 decisions
- 10 lesson topics
- 6 person profiles
- 6 project records
Total: 54 Markdown files, 838 lines of structured content.
Obsidian Compatible
The entire memory/ directory is an Obsidian vault. Graph View colored by directory type — decisions red, lessons green, projects blue, people yellow. Install Obsidian + Sync on your phone and browse your agent's memory anywhere.
Write Mechanism: printf >> Is All You Need
Pitfalls Along the Way
Pitfall 1: Edit tool exact-match OpenClaw's Edit tool requires exact text matching. In isolated cron sessions, agents frequently failed because file content didn't match expectations. 15–20% failure rate.
Pitfall 2: Write overwrites Gemini Flash running cron tended to rewrite entire files with Write. On 2/13, a daily-summary run wiped 12 hours of checkpoint content.
Pitfall 3: Checkpoint cron can't see conversations An isolated memory-checkpoint cron has zero visibility into the main session's conversation. It missed the most important information source.
Pitfall 4: Duplicate work Heartbeat ran hourly in the main session and could see conversation context — but only did flywheel checks, not memory writes. Two systems doing overlapping work, both doing it poorly.
Solution: Consolidate Into the Heartbeat Skill
Heartbeat fires (every 1 hour)
↓
Phase 1: Memory writes
1.1 Scan conversation context → find decisions/completions/lessons/preference changes
1.2 Append to daily log (printf >>)
1.3 Route to decisions/ or lessons/ if applicable
1.4 Update INDEX.md (only when new files are created)
1.5 Refresh NOW.md (every time)
1.6 Update MEMORY.md (rarely)
↓
Phase 2: External scan
2.1 Check sub-agent activity
2.2 Check cron health
↓
Phase 3: Flywheel check
The Write Command
printf '\n### 14:30 — Memory system docs complete\n\n- Finished full iteration doc\n- Saved to community/shares/memory-system-v2.md\n' >> memory/2026-02-15.md
Why printf >>?
>>appends — never overwritesprintfis more reliable thanecho(handles special characters)- No dependency on exact-match logic
- Creates the file automatically if it doesn't exist
Cost savings: Consolidating saved $2–3/day, and write quality improved because heartbeat runs in the main session with full conversation visibility.
Backup: Three Layers
# Runs automatically at 23:00 every night
cd memory && git add -A && git commit -m "backup: $(date +%Y-%m-%d)" && git push
- Local files (real-time)
- Obsidian Sync (real-time to phone)
- Private GitHub repo (nightly, with version history)
Anti-Patterns
❌ Don't
- Use Edit to append to memory/ files
- Use Write to overwrite existing files
- Write filler like "system idle, no changes"
- Create a new file for every lesson
- Write entries longer than 15 lines
- Put lessons in NOW.md
- Put daily records in MEMORY.md
✅ Do
- Use
exec printf >> - Only use Write when the file doesn't exist
- Skip writing if there's nothing worth recording
- Append to existing topic files
- Keep entries 3–10 lines: specific but not bloated
Summary
- Files are memory. Markdown files are more reliable than vector databases
- Three-layer separation. Workbench (NOW), journal (daily), wisdom (MEMORY) — never mix
- Organize lessons by topic, not date. All investment lessons in one file beats hunting through 30 days of journals
- Write mechanism matters more than write content.
printf >>will never corrupt your data - Merge overlapping systems. Consolidating saves money and improves accuracy
- INDEX.md is the key. One file to navigate the entire memory library on startup
- Obsidian compatible. Lets humans browse agent memory intuitively
Stack: OpenClaw + Markdown + Git + Obsidian Cost: Near zero (Gemini Flash heartbeat + free private GitHub repo) Result: Agent maintains consistency across sessions, days, and context compactions