Enhanced Memory
by @fatcatmaofei
An enhanced memory system for OpenClaw agents that replaces the default single-file MEMORY.md with a complete memory architecture: hierarchical directory org...
clawhub install openclaw-enhanced-memory๐ About This Skill
name: enhanced-memory description: > An enhanced memory system for OpenClaw agents that replaces the default single-file MEMORY.md with a complete memory architecture: hierarchical directory organization by category, [category:value] tag indexing with multi-tag AND search, automatic lifecycle management (active โ archive, never delete), and intelligent cross-category retrieval that auto-routes queries to the right memory module. Gives your agent structured, searchable, long-lived memory out of the box.
Enhanced Memory
A structured memory system that gives your OpenClaw agent organized, searchable, long-lived memory instead of a single monolithic MEMORY.md.
Why?
The default MEMORY.md approach hits a wall fast:
Tagged Memory fixes all of this.
Core Features
1. Hierarchical Directory Organization
Memories are stored in purpose-built directories:
memory/
โโโ current/ # Active memories (last 6 months)
โโโ archived/ # Auto-archived older memories (permanent, never deleted)
โ โโโ YYYY-MM/ # Organized by month
โโโ RELATION/ # One file per person (relationship context)
โโโ food/ # Meal and food logs
โโโ training/ # Exercise and workout records
โโโ connections.md # Global relationship graph
โโโ system/ # System config and logs
โโโ misc/ # Everything else
2. Tag-Based Indexing
Tag any line in any memory file with [category:value] markers:
## 2026-02-20Had lunch with Zhang Hao [ไบบ็ฉ:ๅผ ๆตฉไธ] [็ฑปๅ:่้ค] [ๅฐ็น:campus]
Discussed the new project deadline [้กน็ฎ:openclaw] [็ฑปๅ:ไผ่ฎฎ]
Yoyo learned a new trick today [ๅฎ ็ฉ:ๆ ๆ ] [็ฑปๅ:milestone]
Tags support multi-tag AND search โ find the exact memory you need:
# Single tag search
python3 scripts/memory_tag_search.py "ไบบ็ฉ:ๅผ ๆตฉไธ"Multi-tag AND search (all tags must match)
python3 scripts/memory_tag_search.py "ไบบ็ฉ:็้ๅฒ" "็ฑปๅ:ๅผ็ฅจไฟกๆฏ"List all tags in the system
python3 scripts/memory_tag_search.py --list-tagsList tags under a specific category
python3 scripts/memory_tag_search.py --list-tags --category ไบบ็ฉ
3. Lifecycle Management
Memories age gracefully โ never lost, always accessible:
| Age | Location | Status |
|-----|----------|--------|
| 0โ6 months | memory/current/ | Active, auto-retrieved |
| 6โ12 months | memory/archived/YYYY-MM/ | Archived, searchable on demand |
| 12+ months | memory/archived/ | Permanent archive, manual query |
Run the lifecycle manager manually or via cron:
# Default: archive memories older than 6 months
python3 scripts/memory_lifecycle_manager.pyCustom threshold (e.g., 90 days)
python3 scripts/memory_lifecycle_manager.py 90
4. Smart Cross-Category Retrieval
The retrieval strategy script auto-classifies queries and searches the right directories:
python3 scripts/memory_retrieval_strategy.py "What did I eat yesterday?"
โ Searches memory/food/ + memory/current/
python3 scripts/memory_retrieval_strategy.py "How is Yoyo doing?"
โ Searches memory/RELATION/ๆ ๆ .md + memory/connections.md
python3 scripts/memory_retrieval_strategy.py "Yang Lingxiao"
โ Searches memory/RELATION/ + memory/connections.md
Query type detection covers: food, training, relationships, pets, system, mood, projects, and more.
Scripts
| Script | Purpose |
|--------|---------|
| scripts/memory_tag_search.py | Tag-based indexing and search (single/multi-tag AND queries, tag listing) |
| scripts/memory_retrieval_strategy.py | Smart retrieval โ auto-classifies queries and routes to relevant memory directories |
| scripts/memory_lifecycle_manager.py | Automatic archival of old memories (configurable threshold, never deletes) |
Integration
AGENTS.md
Add the following to your AGENTS.md memory section:
## MemoryDirectory Structure
memory/current/ โ active memories (6 months)
memory/archived/ โ permanent archive
memory/RELATION/ โ per-person relationship files
memory/food/ โ meal logs
memory/training/ โ workout logsRetrieval Strategy
Exact queries (names, dates, codes) โ grep the file system
Fuzzy/semantic queries โ python3 scripts/memory_retrieval_strategy.py ""
Tag search โ python3 scripts/memory_tag_search.py ":" Tagging Convention
When writing memory entries, tag important lines:
[ไบบ็ฉ:name] [็ฑปๅ:type] [ๅฐ็น:place] [้กน็ฎ:project] [ๆ
็ปช:mood]
HEARTBEAT.md
Add periodic memory maintenance to your heartbeat checklist:
## Memory Maintenance (every few days)
[ ] Run python3 scripts/memory_lifecycle_manager.py to archive old memories
[ ] Run python3 scripts/memory_tag_search.py --list-tags to review tag health
[ ] Check memory/current/ file count โ if growing large, verify archival is running
Cron (optional)
Set up monthly auto-archival:
# Run on the 1st of every month at 03:00
0 3 1 * * cd /path/to/workspace && python3 scripts/memory_lifecycle_manager.py
Customization
ARCHIVE_THRESHOLD_DAYS in memory_lifecycle_manager.py (default: 180 days)QUERY_TYPES in memory_retrieval_strategy.pyMODULES_TO_ARCHIVE in memory_lifecycle_manager.py[category:value] in any .md file