Production-grade agent memory that learns and improves over time.
OpenClaw agents can now retain, recall, and reflect — automatically extracting structured knowledge from daily logs, searching semantically and semantically, updating confidence in learned opinions, and optimizing their own memory design.
This system implements the Hindsight Memory Architecture (retain/recall/reflect) combined with ALMA (Algorithm Learning via Meta-learning Agents) to make agent memory both human-readable (Markdown-backed) and machine-optimizable.
OpenClaw's native memory is append-only Markdown. Great for journaling, terrible for recall:
- ❌ "What did I decide about X?" — requires re-reading 100 files
- ❌ "What changed about Alice?" — no version history of beliefs
- ❌ "Why did that strategy fail before?" — no searchable failure log
- ❌ "Which memories actually matter?" — no optimization
This system solves it:
- ✅ Automatic fact extraction from daily logs (Observational Memory)
- ✅ Entity-centric summaries (
bank/entities/Alice.md) - ✅ Confidence-bearing opinions that evolve with evidence
- ✅ Temporal queries ("what was true in November?")
- ✅ ALMA learns which memory designs maximize agent performance
- ✅ Everything stays offline, auditable, and git-backed
Your workspace is the source of truth — human-readable Markdown:
~/.openclaw/workspace/
├── MEMORY.md # core: durable facts + preferences
├── memory/
│ ├── 2026-02-24.md # daily log (append-only)
│ ├── 2026-02-23.md
│ └── ...
└── bank/ # curated, typed memory
├── world.md # objective facts
├── experience.md # what happened (first-person)
├── opinions.md # prefs/judgments + confidence + evidence
└── entities/
├── Alice.md
├── The-Castle.md
└── ...
An offline-first SQLite index powers fast, semantic search:
~/.openclaw/workspace/.memory/index.sqlite
- FTS5 for lexical search (fast, tiny, no ML)
- Embeddings for semantic search (optional, local or remote)
- Always rebuildable from Markdown (never the source of truth)
Daily Log (YYYY-MM-DD.md)
↓
[Retain] Extract structured facts
↓
SQLite Index (FTS + embeddings)
↓
[Recall] Agent queries via tools
↓
bank/entities/*.md, bank/opinions.md
↓
[Reflect] Daily job updates summaries & beliefs
↓
MEMORY.md grows with stable facts
| Component | What It Does | Language |
|---|---|---|
| ALMA (meta-learning) | Evolves memory design to maximize agent performance | Python (1,270 LOC) |
| Observational Memory | Extracts temporal, entity-linked facts from logs | Python (1,529 LOC) |
| Knowledge Indexer | Builds FTS + embedding index over Markdown | Python (248 LOC) |
| Scripts | Automation: bootstrap, sync, compress, stress-test | Shell (905 LOC) |
| Integration | ALMA optimizer, reranker, PAOM exporter | Python (1,072 LOC) |
Total: 11,695 lines of real, working Python code.
git clone https://github.com/arosstale/openclaw-memory-template.git
cd openclaw-memory-template
pip install -r requirements.txt# Creates ~/.openclaw/workspace with initial structure
bash .openclaw/scripts/init.shIn your OpenClaw config (~/.openclaw/openclaw.json):
{
"agents": {
"defaults": {
"workspace": "~/.openclaw/workspace",
"memorySearch": {
"enabled": true,
"provider": "openai",
"model": "text-embedding-3-small"
}
}
}
}Write to daily log:
# Append to today's log
echo "## Retain
- W @Alice: Still prefers async communication
- B: Fixed the connection pool leak in server.ts
- O(c=0.92) @Alice: Values speed over perfection" >> ~/.openclaw/workspace/memory/$(date +%Y-%m-%d).mdAgent recalls:
User: "What does Alice prefer?"
Agent: [calls memory_search] → returns facts tagged @Alice with sources + confidence
Reflection job (daily):
# Updates bank/entities/Alice.md + bank/opinions.md
python .openclaw/alma/alma_agent.py --reflectRetain: Structured fact extraction
- Type tags:
W(world),B(biographical),O(opinion),S(summary) - Entity mentions:
@Alice,@The-Castle - Opinion confidence:
O(c=0.0..1.0)
Recall: Smart search
- Lexical (FTS5): exact names, IDs, commands
- Semantic (embeddings): "what does Alice prefer?" vs "Alice's preferences"
- Temporal: "what happened in November?"
- Entity-centric: "tell me about Alice"
Reflect: Auto-update summaries
bank/entities/*.mdupdated from recent facts- Opinion confidence evolves with reinforcement/contradiction
MEMORY.mdgrows with stable, durable facts
The agent can improve its own memory system by:
- Proposing mutations to the memory structure
- Evaluating which designs maximize performance
- Archiving best designs for future use
(Research-grade; useful for long-running agents)
Captures when things were decided, not just what was decided:
2026-02-24 14:30 [High] User stated Alice prefers async > sync. (meaning Feb 24, 2026)
2026-02-24 14:45 [Medium] Implemented connection pool retry logic.
Your agent gets two tools automatically:
# Semantic search over memory
memory_search(query, k=5, since="30d")
# Returns: [{ kind, timestamp, entities, content, source }, ...]
# Direct file read
memory_get(path, start_line=None, num_lines=None)
# Returns: { text, path }- Daily standup: Agent reads yesterday's log + today's MEMORY.md
- Session: Agent calls
memory_searchto recall relevant facts - End of session: Pre-compaction flush writes durable facts to
memory/YYYY-MM-DD.md - Overnight: Reflection job runs → updates
bank/→ feeds into next day's MEMORY.md
{
"agents": {
"defaults": {
"workspace": "~/.openclaw/workspace"
}
}
}{
"agents": {
"defaults": {
"memorySearch": {
"enabled": true,
"provider": "openai",
"model": "text-embedding-3-small",
"remote": {
"apiKey": "sk-..."
}
}
}
}
}{
"agents": {
"defaults": {
"memorySearch": {
"provider": "local",
"local": {
"modelPath": "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf"
}
}
}
}
}Three principles:
- Markdown is source of truth. Humans read it, git tracks it, agents extend it.
- Offline-first. Works on laptop, castle, RPi. No cloud required.
- Explainable recall. Every fact is citable (file + line). Confidence is tracked.
.openclaw/alma/— ALMA agent (meta-learning).openclaw/observational_memory/— Fact extraction + temporal anchoring.openclaw/knowledge/— Indexer + searcher.openclaw/integrations/— ALMA optimizer, reranker, exporters.openclaw/scripts/— Automation (init, sync, compress, stress-test)scripts/— MSAM export, health checks
- ✅ ALMA agent (working)
- ✅ Observational Memory (working)
- ✅ Knowledge indexing (working)
- ✅ OpenClaw integration (ready)
- ⏳ CI/CD (in progress)
- ⏳ Full docs (in progress)
This is a research-grade production system. Fork, customize, and PR improvements back.
See CONTRIBUTING.md for details.
MIT — Use, modify, share freely. Attribution appreciated.
- Hindsight Technical Report — Retain/Recall/Reflect architecture inspiration
- ALMA Paper (arXiv 2602.07755) — Meta-learning agents
- OpenClaw — The framework we're optimizing for
- Artale — Implementation & integration
🧠 Your agent now has a production-grade memory system. Time to build.