Memory Attention Router Skill
This skill turns long agent memory into a small, role-aware working-memory packet.
Trigger this skill immediately when the user states a durable preference or rule, especially with phrases like:
- from now on
- remember that
- record to memory
- always
- prefer
- avoid
- my rule is
- going forward
Do not treat this as normal document RAG. Do not dump large raw memory lists into model context. Route to the right memory blocks, select a small set of memories, compose a compact packet, write back new learnings, and retire stale memories when better evidence appears.
Step roles
Choose the current step role before reading memory:
plannerexecutorcriticresponder
Default type preferences:
planner->preference,procedure,summaryexecutor->procedure,episode,reflectioncritic->reflection,preference,summaryresponder->preference,summary,procedure
Read flow
- Build a route request with:
goalstep_rolesession_idif knowntask_idif knownuser_constraintsrecent_failuresunresolved_questions
- Run:
python3 {baseDir}/scripts/memory_router.py route --input-json '<JSON>' - Read the
packet. - Use the packet in downstream reasoning.
- Inspect
debug.selected_blocksanddebug.selected_memorieswhen you need to understand why the router picked a particular packet.
The router uses a deterministic two-stage flow:
- select the best blocks from
task_scoped,session_scoped,durable_global, andrecent_fallback - score memories only inside the selected blocks
Write flow
Store memory after important outcomes:
python3 {baseDir}/scripts/memory_router.py add --input-json '<JSON>'
Write memory when:
- a tool call succeeds and the result will matter later
- a tool call fails in a reusable way
- the user states a durable preference or rule
- the agent learns a reusable procedure
- the agent reaches a stable summary worth keeping
If a new memory replaces an older one, include replaces_memory_id in the add payload. The older memory will be retired, linked forward to the new memory, and marked with a stored retirement reason.
Reflect flow
At the end of a meaningful task or after a failure cluster, create reflection and optionally procedure memory:
python3 {baseDir}/scripts/memory_router.py reflect --input-json '<JSON>'
Refresh flow
When new evidence invalidates or replaces older memory:
python3 {baseDir}/scripts/memory_router.py refresh --input-json '<JSON>'
Use refresh to:
- deactivate stale memories
- mark replacements with
replacement_memory_id - persist why the memory was retired with
refresh_reason - create contradiction links when a replacement exists
Packet rules
A good packet contains:
hard_constraintsrelevant_factsprocedures_to_followpitfalls_to_avoidopen_questionsselected_memory_ids
Keep packets small:
- prefer 4 to 8 selected memories
- never include more than 10 unless the user explicitly wants a retrospective
- prefer summaries and procedures over raw episodes when both exist
Bootstrap
Initialize the database:
python3 {baseDir}/scripts/memory_router.py init
Default DB path behavior:
- if
MAR_DB_PATHis set, that path is used - otherwise, when installed at
<workspace>/skills/memory-attention-router, the default is<workspace>/.openclaw-memory-router.sqlite3
Inspect stored memories:
python3 {baseDir}/scripts/memory_router.py list --limit 20
Inspect one memory:
python3 {baseDir}/scripts/memory_router.py inspect --memory-id <ID>
File guide
See:
Important behavior rules
- Prefer long-lived, verified, reusable memory over noisy transient notes.
- When in doubt, write a
summaryinstead of a verbose raw note. - Use
preferenceonly for stable user or system constraints. - Use
procedureonly for instructions that should be reused later. - Use
reflectionfor lessons, pitfalls, and failure patterns. - Use
episodefor concrete events or observations. - If two active memories conflict, retire the stale one or add a contradiction edge.
- Treat prompt templates as optional reference material; the default router is fully deterministic and local.