{"skill":{"slug":"memory-attention-router","displayName":"memory-attention-router","summary":"Deterministic long-term memory routing for OpenClaw. Route, write, reflect on, and refresh reusable memory for multi-step agent work. Use when the task depen...","description":"---\nname: memory-attention-router\ndescription: Deterministic long-term memory routing for OpenClaw. Route, write, reflect on, and refresh reusable memory for multi-step agent work. Use when the task depends on prior sessions, durable user preferences, reusable procedures, past failures, project summaries, or stale memories that need replacement. Trigger on explicit memory phrases like \"from now on\", \"remember this\", \"always\", \"prefer\", \"avoid\", \"my rule is\", \"replace my previous rule\", and \"going forward\", and whenever an agent step needs a compact working-memory packet instead of raw history or plain RAG.\n---\n\n# Memory Attention Router Skill\n\nTurn long-term memory into a small, role-aware working-memory packet.\n\nDo not use this skill as plain document RAG.\nDo not dump raw memory lists into model context.\nRoute to the right memory blocks, compose a compact packet, write back new learnings, and retire stale memory when better evidence appears.\n\n## Trigger cues\n\nTrigger immediately when the user states a durable rule or asks to preserve or replace memory, especially with phrases like:\n\n- from now on\n- remember this\n- always\n- prefer\n- avoid\n- my rule is\n- replace my previous rule\n- going forward\n\nAlso trigger when a planning, execution, critique, or response step needs compact memory state rather than raw history.\n\n## Step roles\n\nChoose the current step role before reading memory:\n\n- `planner`\n- `executor`\n- `critic`\n- `responder`\n\nCurrent type preferences:\n\n- `planner` -> `preference`, `procedure`, `summary`\n- `executor` -> `preference`, `procedure`, `episode`, `reflection`\n- `critic` -> `reflection`, `preference`, `summary`\n- `responder` -> `preference`, `summary`, `procedure`\n\nImportant implication:\n\n- `executor` should preserve durable hard constraints as well as reusable procedures\n\n## Read flow\n\n1. Build a route request with:\n   - `goal`\n   - `step_role`\n   - `session_id` if known\n   - `task_id` if known\n   - `user_constraints`\n   - `recent_failures`\n   - `unresolved_questions`\n2. Run:\n   `python3 {baseDir}/scripts/memory_router.py route --input-json '<JSON>'`\n3. Read the `packet`.\n4. Use the packet in downstream reasoning.\n5. Inspect `debug.selected_blocks` and `debug.selected_memories` when you need to understand why a memory was selected.\n\nThe router uses a deterministic two-stage flow:\n\n1. select the best blocks from `task_scoped`, `session_scoped`, `durable_global`, and `recent_fallback`\n2. score memories only inside the selected blocks\n\n## Write flow\n\nStore memory after important outcomes:\n\n`python3 {baseDir}/scripts/memory_router.py add --input-json '<JSON>'`\n\nWrite memory when:\n\n- a durable user preference or rule is learned\n- a reusable procedure becomes clear\n- a tool result will matter later\n- a failure pattern should influence future behavior\n- a stable summary is worth keeping\n\nIf a new memory replaces an older one, include `replaces_memory_id`. The router will retire the old memory, link it forward to the replacement, and persist a retirement reason.\n\n## Reflect flow\n\nAt the end of meaningful work or after a failure cluster, create reflection and optionally procedure memory:\n\n`python3 {baseDir}/scripts/memory_router.py reflect --input-json '<JSON>'`\n\nUse reflection for:\n\n- lessons\n- warnings\n- failure patterns\n- reusable procedures derived from successful work\n\n## Refresh flow\n\nWhen new evidence invalidates or replaces older memory:\n\n`python3 {baseDir}/scripts/memory_router.py refresh --input-json '<JSON>'`\n\nUse refresh to:\n\n- deactivate stale memories\n- mark replacements with `replacement_memory_id`\n- persist why the memory was retired with `refresh_reason`\n- create contradiction links when a replacement exists\n\n## Packet rules\n\nA good packet contains:\n\n- `hard_constraints`\n- `relevant_facts`\n- `procedures_to_follow`\n- `pitfalls_to_avoid`\n- `open_questions`\n- `selected_memory_ids`\n\nCurrent compactness targets:\n\n- `selected_memory_ids` -> cap at 5\n- `hard_constraints` -> cap at 4\n- `relevant_facts` -> cap at 3\n- `procedures_to_follow` -> cap at 3\n- `pitfalls_to_avoid` -> cap at 3\n- `open_questions` -> cap at 5\n\nPrefer small, high-signal packets over broad recall.\n\n## Routing rules\n\n- Prefer durable, reusable memory over noisy transient notes.\n- Preserve hard constraints for execution steps, not only planning steps.\n- Use `support` edges to help validated memories win borderline ranking decisions.\n- Treat `contradicts` edges directionally: penalize the stale target, not the newer memory asserting the contradiction.\n- Use `summary` instead of verbose raw history when both carry the same signal.\n- Retire stale memory when replacement is clear; do not allow conflicting active memories to accumulate indefinitely.\n\n## Bootstrap\n\nInitialize the database:\n\n`python3 {baseDir}/scripts/memory_router.py init`\n\nDefault DB path behavior:\n\n- if `MAR_DB_PATH` is set, that path is used\n- otherwise, when installed at `<workspace>/skills/memory-attention-router`, the default is `<workspace>/.openclaw-memory-router.sqlite3`\n\nInspect stored memories:\n\n`python3 {baseDir}/scripts/memory_router.py list --limit 20`\n\nInspect one memory:\n\n`python3 {baseDir}/scripts/memory_router.py inspect --memory-id <ID>`\n\n## File guide\n\nSee:\n\n- [reference guide](references/REFERENCE.md)\n- [memory schema](references/MEMORY_SCHEMA.md)\n- [prompt templates](references/PROMPTS.md)\n- [testing guide](references/TESTING.md)\n","tags":{"latest":"1.1.0"},"stats":{"comments":0,"downloads":563,"installsAllTime":0,"installsCurrent":0,"stars":1,"versions":2},"createdAt":1773678230948,"updatedAt":1778491953611},"latestVersion":{"version":"1.1.0","createdAt":1774462692824,"changelog":"- Improved SKILL.md for clarity and conciseness, with updated descriptions and trigger cues.\n- Added new trigger phrases like \"replace my previous rule\" and guidance on when to trigger for agent steps.\n- Clarified that executor steps should preserve hard constraints alongside reusable procedures.\n- Defined stricter caps for packet sizes to ensure compact, high-signal working-memory packets.\n- Expanded routing rules, including use of support/contradicts edges and priority for durable, reusable memories.\n- Refined write, reflect, and refresh flow instructions for better memory lifecycle management.","license":"MIT-0"},"metadata":null,"owner":{"handle":"kaiqiangh","userId":"s177eg4w8by1njx9xmdf9q48d583f13h","displayName":"Kai","image":"https://avatars.githubusercontent.com/u/9014062?v=4"},"moderation":{"isSuspicious":false,"isMalwareBlocked":false,"verdict":"clean","reasonCodes":["review.llm_review"],"summary":"Review: review.llm_review","engineVersion":"v2.4.24","updatedAt":1780090106826}}