Design and implement memory systems that let agents survive context window rotation and maintain continuity across sessions.
LLM agents have finite context windows. Memory is lost when:
Durable memory is not a nice-to-have — it is the agent's continuity substrate.
Three dominant architectures for persistent agent memory:
Agent maintains flat/hierarchical markdown files, reads selectively at boot, writes on state change. Best for: operational state, ongoing projects, agent identity.
This is the default pattern for OpenClaw agents.
Agent embeds facts into a vector store; retrieval uses embedding similarity. OpenClaw's built-in memory uses node-llama-cpp with 768-dim embeddings (all-MiniLM-L6-v2 compatible).
Agent builds a knowledge graph with valid_at/invalid_at on every fact edge. Graphiti (open source, wraps Neo4j) is the leading implementation.
Recommendation: Use CMA + semantic RAG for all agents. Add temporal KG only for high-value long-horizon use cases (months of state).
See references/memory-architecture.md for detailed comparison and deployment notes.
workspace/
├── HEARTBEAT.md # Current pulse state (keep SHORT — < 40 lines)
├── memory/
│ ├── CORE_MEMORY.md # Identity and continuity anchors
│ ├── GOALS.md # Long-horizon aims
│ ├── OPEN_LOOPS.md # Unresolved tasks and promises
│ ├── WORLD_MODEL.md # Verified facts about environment
│ ├── CAPABILITIES.md # Verified tools, channels, limits
│ ├── RUNTIME_REALITY.md # Live channel/mutation/config state
│ └── research/ # Durable research artifacts
└── operator-outbox.jsonl # Async operator messages
| Fact type | File |
|---|---|
| ----------- | ------ |
| Who I am, values, drives | CORE_MEMORY.md |
| Current open work | OPEN_LOOPS.md |
| Infrastructure/env facts | WORLD_MODEL.md |
| What tools/channels work | CAPABILITIES.md |
| Live config/channel state | RUNTIME_REALITY.md |
| Research findings | memory/research/*.md |
| Current pulse state | HEARTBEAT.md |
Add [YYYY-MM-DD] timestamps to facts in memory files. Mark superseded facts explicitly:
- [2026-03-27] Telegram: enabled, account "Morrow Operator Bot"
~~[2026-03-20] Telegram: disabled~~ SUPERSEDED 2026-03-27
This is lightweight temporal KG discipline without a full graph backend. See references/temporal-discipline.md.
At every session start, an agent should:
Never trust session transcript alone for state that should be in memory. Transcripts get compacted.
OpenClaw's lossless-claw plugin (or similar LCM) compacts older session history. Defend against lossy compression:
lcm_grep and lcm_expand_query to retrieve compacted history before answering questions about prior work.If OpenClaw's local semantic memory is active:
memory_search(query) — semantic search across all memory filesmemory_get(path, from, lines) — safe snippet readUse memory_search before reading memory files directly. It's faster, scoped, and context-efficient.
To verify semantic memory is active: check for memory_search in your tool surface. If absent, memory files must be read explicitly.
For temporal KG memory (advanced use):
# 1. Install
pip install graphiti-core --user --break-system-packages
# 2. Neo4j (persistent)
docker run -d --name neo4j \
--restart=unless-stopped \
-p 7687:7687 -p 7474:7474 \
-v neo4j-data:/data \
-e NEO4J_AUTH=neo4j/yourpassword \
neo4j:5.26
# 3. Configure to use OpenClaw /v1 as LLM + embedder backend
# See references/memory-architecture.md for OpenClawLLMClient patch
Important: Graphiti's add_episode requires 5-10 LLM calls per episode. Use it via cron/batch job, not inline during agent pulses.
共 1 个版本