Build a memory system for AI agents that is:
- structured instead of ad hoc
- searchable instead of bloated
- layered instead of stuffing everything into one prompt
This repo packages a reusable skill for OpenClaw/Codex-style workspaces with:
MEMORY.mdfor curated long-term memorymemory/YYYY-MM-DD.mdfor raw daily context- three scheduled sync layers
- qmd-first semantic retrieval
- ripgrep fallback when qmd is unavailable
- macOS
launchdsupport for local index refresh
Most agent memory setups fail in one of two ways:
- everything gets dumped into one giant memory file
- daily logs exist, but retrieval is so weak that nobody actually uses them
This skill separates memory by lifecycle:
- Daily captures raw source material
- Weekly compounds it into durable memory
- Micro catches fresh context before it gets lost
The result is a system that remembers more without turning every session into a full-history replay.
flowchart TD
A["Recent sessions / activity"] --> B["L3 Micro-Sync<br/>append one brief note"]
A --> C["L1 Daily Context Sync<br/>write structured daily log"]
B --> D["memory/YYYY-MM-DD.md"]
C --> D
D --> E["L2 Weekly Memory Compound<br/>distill durable patterns"]
E --> F["MEMORY.md"]
D --> G["qmd query / vsearch"]
F --> G
G --> H["Targeted recall instead of full-file reads"]
- schedule: every day at 23:00
- source: the day's session history
- output: structured raw notes in
memory/YYYY-MM-DD.md
Daily is the main capture layer. Its job is to avoid losing the day.
Its daily output should also include a compact ## Tags section containing inline hashtag tags such as #system #investment #travel.
- schedule: Sunday 22:00
- source: the last 7 daily logs
- output: updates to
MEMORY.md
Weekly is the compounding layer. Its job is to turn raw notes into durable memory.
- schedule: 10:00 / 13:00 / 16:00 / 19:00 / 22:00
- source: meaningful activity from the last 3 hours
- output: at most one brief note appended to today's daily log
Micro is the safety net. Its job is to stop fresh context from falling through the cracks. When useful, it can refresh the day's tags, but those tags should stay in inline hashtag form rather than heading-style labels.
Never bulk-read MEMORY.md or the whole memory/ tree by default.
The retrieval order is:
- qmd query
- targeted snippet fetch
- ripgrep fallback
- full-file reads only when targeted retrieval fails
SKILL.md- the skill entrypoint and workflow
agents/openai.yaml- metadata for OpenAI/Codex-style skill loaders
scripts/- search, snippet, refresh, and weekly finalize helpers
references/- architecture notes, qmd setup, AGENTS snippet, example jobs
templates/launchd/- macOS
launchdtemplate for scheduled qmd refresh
- macOS
bash install.sh /path/to/your/workspaceThe installer is non-destructive:
- copies scripts into
<workspace>/tools - copies references into
<workspace>/.three-layer-memory/references - copies launchd templates into
<workspace>/.three-layer-memory/templates/launchd - creates
memory/andlogs/ - creates
MEMORY.mdonly if it does not already exist
It does not automatically overwrite your existing AGENTS.md or scheduler config.
If qmd is available, the scripts use semantic retrieval first. If not, they fall back to ripgrep.
Use:
references/agents-snippet.md
to merge the mandatory retrieval-first rule into your agent instructions.
Use:
references/jobs.example.json
Important:
- this file is a template
- in many runtimes, it is not the live scheduler source by itself
- you may need to import or merge it into your actual runtime jobs store
The recurring qmd refresh is configured separately from the three agent jobs.
For macOS, use:
templates/launchd/com.openclaw.qmd-refresh.plist.template
Recommended scripts:
scripts/memory_query.shscripts/memory_get.shscripts/search_memory.shscripts/refresh_memory_index.shscripts/qmd_refresh.shscripts/weekly_memory_finalize.sh
Run these in order:
bash scripts/memory_query.sh "memory"bash scripts/memory_get.sh 2026-03-07.md:1 5bash scripts/refresh_memory_index.sh- manually run Micro
- manually run Daily
- manually run Weekly last
This catches retrieval and indexing issues before anything starts rewriting MEMORY.md.
This skill is a good fit if you want:
- a memory system for a real working agent
- durable recall without stuffing everything into context
- a local-first retrieval path
- a workflow that can run on laptops and servers
This repo is not trying to be:
- a fully managed hosted memory product
- a generic vector database wrapper
- a plugin that deeply rewires your runtime
It is a skill-first, file-first architecture that stays inspectable.
- This repo contains no private runtime state, secrets, or workspace-specific logs.
- qmd is optional.
- The scripts are intentionally small and inspectable.
- the three agent layers and the qmd refresh schedule are usually configured in different places
This project was informed by ideas shared publicly by:
The implementation here is an adapted, engineering-focused packaging of those ideas for a reusable memory skill. It is not claimed as the original source of the underlying concept.
MIT. See LICENSE.