MemoryRouter
/install memory-router
MemoryRouter ⚡
Never lose context. Never forget decisions. Never repeat mistakes.
The memory problem is the single biggest reason agents feel dumb over time. Not the models. Not the prompts. Memory management.
MemoryRouter fixes it with one tool, zero dependencies, zero setup.
The Problem — In 30 Seconds
Agent memory files grow unbounded. After a week, you've got thousands of lines across dozens of files. Every session loads everything — even when the user asks "what's the weather?"
That's tokens burned on irrelevant memories, every interaction, forever.
Then compaction kicks in and details vanish.
The bottleneck isn't the model. It's what the model gets to see.
Why Memory Fails
| Failure Mode | Cause | Fix |
|---|---|---|
| Forgets everything | Loads irrelevant files, context window fills up | Smart manifest — load only what matters |
| Repeats mistakes | Lessons not captured or loaded | Entity index + audit for conflicts |
| Repeats work | No session state persistence | WAL protocol — write state before responding |
| Slow responses | Loads 50+ files when only 3 matter | Token budgeting — cap context window |
| Duplicates everywhere | No automated cleanup | --audit finds high-similarity pairs |
The Architecture
┌──────────────────────────────────────────────────────┐
│ MEMORYROUTER ⚡ │
├──────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ AUTO-TIER │ │ MANIFEST │ │
│ │ MEMORY.md │ → │ GENERATOR │ │
│ │ │ │ │ │
│ │ Core (always │ │ Required: │ │
│ │ loaded) │ │ MEMORY.md │ │
│ │ + Archive │ │ Recent logs │ │
│ │ (on demand) │ │ Boosted: │ │
│ └──────────────┘ │ entity files │ │
│ └──────┬───────┘ │
│ │ │
│ ┌──────────────▼──────────────┐ │
│ │ ENTITY RESOLUTION │ │
│ │ "alice" → preferences.md, │ │
│ │ notes.md, decisions.md│ │
│ └──────────────┬──────────────┘ │
│ │ │
│ ┌──────────────▼──────────────┐ │
│ │ TOKEN BUDGET FILTER │ │
│ │ 20K budget → 7 files │ │
│ │ 100K budget → 16 files │ │
│ └──────────────┬──────────────┘ │
│ │ │
│ ┌──────────────▼──────────────┐ │
│ │ AGENT LOADS ONLY WHAT │ │
│ │ MATTERS → 70-85% REDUCTION │ │
│ └─────────────────────────────┘ │
└──────────────────────────────────────────────────────┘
Quick Start
Fix a bloated MEMORY.md in one command
node skills/memory-router/memory-router.js --tier
Output:
[memory-router] MEMORY.md: 7809 lines, 309254 chars
[memory-router] Tiered: 202 core sections, 1002 archived
[memory-router] MEMORY.md reduced from 7809 lines to 2222 lines
Generate a smart manifest in one command
node skills/memory-router/memory-router.js --compact
Creates memory/memory-manifest.json — the agent's shopping list of what to load.
With entity boosting
node skills/memory-router/memory-router.js --compact --query "alice"
Files linked to "alice" get priority. No AI, no embeddings — just fast entity resolution.
With a token budget
node skills/memory-router/memory-router.js --compact --budget 20000
Only loads files that fit within 20K tokens. Tight budgets load core only. Generous budgets load archive on demand.
Other commands
node skills/memory-router/memory-router.js --audit # Find duplicates & conflicts
node skills/memory-router/memory-router.js --status # Health overview
node skills/memory-router/memory-router.js --entity add alice person preferences.md
How It Works
The Core Insight
Memory management is the bottleneck, not model capability. Every agent system hits the same wall — context window fills up, everything loads, irrelevant memories dilute the signal.
MemoryRouter takes a routing approach rather than a compression approach:
- Auto-tiering splits MEMORY.md into core sections (identity, preferences, boundaries — always loaded) and archive sections (everything else, loaded on demand)
- Manifest generation creates a per-session file list: which files to load, which to skip, which to boost
- Entity-aware boosting links people, projects, and systems to files — search for "alice" → load preferences.md first
- Token budgeting caps how many files load based on available context window
The Flow
User query → --compact --query "alice"
↓
Manifest generated
↓
Load required files (MEMORY.md, recent daily logs)
↓
Boost entity-matched files (preferences.md, notes.md)
↓
Agent loads only what matters → 70-85% context reduction
The 4 Engines
⚡ Engine 1: Auto-Tier (--tier)
When MEMORY.md exceeds configurable thresholds (default: 500 lines or 25KB), splits into:
- Core file — Identity, preferences, relationships, projects, patterns, boundaries
- Archive files — Everything else, stored with timestamps in
memory/active/
Sections are classified by header keywords (identity, preferences, etc.) or by content heuristics.
📋 Engine 2: Manifest Generator (--compact)
Creates memory/memory-manifest.json with a file list:
{
"generated": "2026-05-21",
"files": [
{ "path": "MEMORY.md", "tier": "core", "required": true, "size": 50346 },
{ "path": "memory/2026-05-21.md", "tier": "recent", "required": true, "size": 2034 },
{ "path": "self-improving/memory.md", "tier": "domain", "required": false, "size": 670 }
]
}
Options:
| Flag | Description |
|---|---|
--query "text" |
Entity-aware boosting — files linked to matching entities get priority |
--budget N |
Token budget — only loads files that fit within N tokens |
🔍 Engine 3: Audit Scanner (--audit)
Scans all memory files for:
- High-similarity pairs — Files with >70% text overlap (potential duplicates)
- Revision keywords — "revised", "updated", "changed", "no longer", "actually", "correction" (facts that may have been superseded)
Output: memory/memory-audit-report.md
🏥 Engine 4: Health Monitor (--status)
Quick snapshot of MEMORY.md line/char counts, file counts per directory, archive count, manifest status, entity index size, and WAL state.
Additional Tools
Entity Index (--entity)
| Command | Description |
|---|---|
--entity add \x3Cname> \x3Ctype> \x3Cfiles...> |
Add entity (e.g., alice person preferences.md) |
--entity list |
List all entities |
--entity search \x3Cquery> |
Search entities (direct and fuzzy match) |
WAL Protocol (--wal)
| Command | Description |
|---|---|
--wal init |
Initialize SESSION-STATE.md with template |
--wal get |
Show current session state |
--wal update \x3Csection> --content "\x3Ctext>" |
Update a section |
Configuration
Edit config.json to customize behavior:
{
"thresholds": {
"memoryMdMaxLines": 500,
"memoryMdMaxChars": 25000,
"tierArchiveMinAgeDays": 3,
"auditMaxFiles": 50
},
"tiering": {
"archiveDir": "memory/active",
"retentionDays": 90,
"keepInMemory": [
"identity", "preferences", "relationships",
"projects", "patterns", "boundaries", "key_facts"
]
},
"manifest": {
"generateOnTier": true,
"manifestPath": "memory/memory-manifest.json"
},
"audit": {
"reportPath": "memory/memory-audit-report.md",
"duplicateThreshold": 0.7,
"conflictKeywords": [
"revised", "updated", "changed", "no longer",
"actually", "correction", "mistake"
]
}
}
| Setting | Default | Description |
|---|---|---|
memoryMdMaxLines |
500 | Auto-tier trigger (lines) |
memoryMdMaxChars |
25000 | Auto-tier trigger (characters) |
tierArchiveMinAgeDays |
3 | Minimum age before archiving |
retentionDays |
90 | Archive retention period |
keepInMemory |
see above | Headers/keywords that stay in core |
generateOnTier |
true | Auto-generate manifest after tiering |
duplicateThreshold |
0.7 | Similarity score to flag as duplicate |
conflictKeywords |
see above | Words that signal fact revision |
Agent Memory Loading Protocol
When the agent wakes up, use the manifest instead of loading all memory files:
- Read
memory/memory-manifest.json - Load all
required: truefiles - For
required: falsefiles, usememory_searchto check relevance - Load only the top 3-5 most relevant optional files
Result: 70–85% context reduction — load what matters, skip the rest.
Heartbeat Integration
Add to your HEARTBEAT.md:
### ⚡ MemoryRouter
- Run `node skills/memory-router/memory-router.js --tier` if MEMORY.md is bloated
- Run `node skills/memory-router/memory-router.js --compact` to update manifest
- Run `node skills/memory-router/memory-router.js --audit` to check for issues
- Check `memory/memory-audit-report.md` for any flagged conflicts
Performance
| Metric | Result |
|---|---|
| Tiering speed (8K lines) | 25ms |
| Tiering speed (15K lines) | 30ms |
| Token reduction | 96% (7,809 → 222 lines) |
| File count reduction | 53 → 15 files |
| Memory footprint | ~2MB (Node.js runtime) |
Comparison
| Approach | Tokens Saved | Setup Effort | Maintenance | Privacy |
|---|---|---|---|---|
| Raw file injection | 0% | None | Manual | ✅ |
| MemoryRouter | 70–85% | None | Automated | ✅ |
| Obsidian vault | 40–60% | High | Medium | ⚠️ Cloud |
| Vector DB (ChromaDB) | 70–85% | Very High | High | ✅ |
| mem0 | 70–85% | High | Medium | ⚠️ Cloud |
MemoryRouter gives you the best token savings of the vector DB approach with zero setup effort.
Entity Naming
Pick one canonical name per entity and reuse it consistently:
- Use full descriptive names: "machine learning" not "ML", "JavaScript" not "JS"
- Same string after lowercasing = same entity. Different strings = different entities
- Call
--entity searchperiodically to verify your index
Examples:
# ✅ Good — consistent, descriptive
node memory-router.js --entity add alice person preferences.md
node memory-router.js --entity add openclaw system AGENTS.md
# ❌ Bad — inconsistent, ambiguous
node memory-router.js --entity add alice person preferences.md
node memory-router.js --entity add Alice person notes.md
node memory-router.js --entity add JS person docs.md
Manifest Format
The manifest JSON tells the agent which files to load:
{
"generated": "2026-05-21",
"version": 2,
"query": "memory management",
"budget": 20000,
"files": [
{
"path": "MEMORY.md",
"tier": "core",
"required": true,
"size": 50346
},
{
"path": "memory/2026-05-21.md",
"tier": "recent",
"ageDays": 0,
"required": true,
"size": 2034
},
{
"path": "self-improving/memory.md",
"tier": "domain",
"required": false,
"size": 670
}
]
}
| Field | Type | Description |
|---|---|---|
tier |
string | core, recent, domain, or archive |
required |
bool | Always load this file |
size |
int | File size in bytes |
boosted |
bool | Entity match — higher priority |
entityMatch |
string | Entity name that matched |
load |
bool | Included under budget mode |
budgetUsed |
int | Total tokens loaded (budget mode) |
budgetEfficiency |
string | Percentage remaining (budget mode) |
Troubleshooting
| Problem | Fix |
|---|---|
| "No MEMORY.md found" | Create one: echo "# MEMORY.md" > MEMORY.md |
| "Memory directory not found" | Create it: mkdir -p memory |
| Tiering not working | Check thresholds — if under 500 lines and 25KB, nothing happens (by design) |
| Manifest shows wrong files | Run --compact again — it regenerates fresh each time |
| Entity search returns nothing | Add entities first: --entity add \x3Cname> \x3Ctype> \x3Cfiles...> |
| Budget too small | Core files always load. Budget only controls optional files. |
Security
Built with defense-in-depth:
- Path validation — rejects file paths outside workspace root
- Regex escaping — prevents injection in WAL section names
- Symlink protection — refuses to read/write symlinks
- Size limits — 10MB max file size
- Entity name validation — alphanumeric + hyphens/underscores only
- Content sanitization — prevents header injection in WAL updates
- Audit keyword validation — rejects regex metacharacters in conflict keywords
Design Principles
- Zero user friction — Everything runs automatically during heartbeats
- No external dependencies — Pure Node.js, no npm packages
- Configurable — Thresholds, keywords, retention policies
- Transparent — Generates reports, nothing is silently deleted
- Reversible — Archives use dated filenames, original content preserved
- Privacy-first — All local, no cloud APIs
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install memory-router - 安装完成后,直接呼叫该 Skill 的名称或使用
/memory-router触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
MemoryRouter 是什么?
Intelligent memory routing for OpenClaw agents. Auto-tiers bloated MEMORY.md, generates smart per-session manifests, loads only what matters. 70-85% context... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 86 次。
如何安装 MemoryRouter?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install memory-router」即可一键安装,无需额外配置。
MemoryRouter 是免费的吗?
是的,MemoryRouter 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
MemoryRouter 支持哪些平台?
MemoryRouter 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 MemoryRouter?
由 jlacroix82(@jlacroix82)开发并维护,当前版本 v1.0.3。