@smyslenny/agent-memory 3.1.0 → 4.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,12 +1,127 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.0-alpha.1 (2026-03-09)
4
+
5
+ ### 🚀 Repositioning
6
+
7
+ AgentMemory v4 is now documented and packaged as an **agent-native memory layer
8
+ with lifecycle management**.
9
+
10
+ What changed at the product level:
11
+
12
+ - README is now **English-first** and generic-runtime-first
13
+ - OpenClaw is still supported, but now documented as an **optional host example**
14
+ - `memory/*.md + MEMORY.md` is treated as an **optional workflow**, not the
15
+ product definition
16
+ - CLI, MCP stdio, and HTTP/SSE are all first-class integration paths
17
+
18
+ ### ✨ Added in Phase 1 — optional vector retrieval layer
19
+
20
+ - Added **optional embedding provider support** for hybrid retrieval:
21
+ - `openai-compatible`
22
+ - `local-http`
23
+ - Added **hybrid recall** with BM25 + vector fusion
24
+ - Added embedding-aware storage and reindex support:
25
+ - `provider_id`
26
+ - `content_hash`
27
+ - `status`
28
+ - Added **`reindex`** support for backfill / rebuild workflows
29
+ - Added provider configuration via environment variables:
30
+ - `AGENT_MEMORY_EMBEDDING_PROVIDER`
31
+ - `AGENT_MEMORY_EMBEDDING_BASE_URL`
32
+ - `AGENT_MEMORY_EMBEDDING_MODEL`
33
+ - `AGENT_MEMORY_EMBEDDING_DIMENSION`
34
+ - `AGENT_MEMORY_EMBEDDING_API_KEY`
35
+ - Kept **BM25-only mode** as a supported fallback when no provider is configured
36
+
37
+ ### ✨ Added in Phase 2 — semantic dedup + lifecycle reliability
38
+
39
+ - Upgraded **Write Guard** from simple duplicate checks to semantic dedup flow
40
+ - Added **typed merge policy** so similar memories can be merged more safely
41
+ - Added **maintenance job tracking** for lifecycle operations
42
+ - Added checkpoint-aware **reflect orchestrator** for:
43
+ - `decay`
44
+ - `tidy`
45
+ - `govern`
46
+ - Improved lifecycle observability and recovery-friendliness for interrupted
47
+ maintenance runs
48
+
49
+ ### ✨ Added in Phase 3 — HTTP/SSE API + better surface
50
+
51
+ - Added long-lived **HTTP API** transport
52
+ - Added **SSE progress streaming** for long-running jobs
53
+ - Added HTTP routes for:
54
+ - `POST /v1/memories`
55
+ - `POST /v1/recall`
56
+ - `POST /v1/surface`
57
+ - `POST /v1/feedback`
58
+ - `POST /v1/reflect`
59
+ - `POST /v1/reindex`
60
+ - `GET /v1/status`
61
+ - `GET /v1/jobs/:id`
62
+ - `GET /health`
63
+ - Added CLI server mode:
64
+ - `agent-memory serve`
65
+ - Upgraded **surface** into a more **context-aware** API using:
66
+ - `task`
67
+ - `query`
68
+ - `recent_turns`
69
+ - `intent`
70
+ - type filters
71
+ - feedback priors
72
+ - Added **feedback events** so runtimes can record whether `recall` / `surface`
73
+ results were actually useful
74
+
75
+ ### 🧰 Tooling / interface changes
76
+
77
+ - MCP toolset is now **10 tools**:
78
+ - `remember`
79
+ - `recall`
80
+ - `recall_path`
81
+ - `boot`
82
+ - `forget`
83
+ - `reflect`
84
+ - `status`
85
+ - `ingest`
86
+ - `reindex`
87
+ - `surface`
88
+ - CLI now includes:
89
+ - `db:migrate`
90
+ - `reindex`
91
+ - `serve`
92
+
93
+ ### 📚 Documentation and examples overhaul
94
+
95
+ - Rewrote `README.md` for OSS evaluation and generic runtime adoption
96
+ - Removed the split `README.md` / `README.en.md` homepage model
97
+ - Added dedicated docs:
98
+ - `docs/architecture.md`
99
+ - `docs/integrations/generic.md`
100
+ - `docs/integrations/openclaw.md`
101
+ - `docs/migration-v3-v4.md`
102
+ - Reorganized examples into:
103
+ - `examples/quick-start/`
104
+ - `examples/http-api/`
105
+ - `examples/mcp-stdio/`
106
+ - `examples/openclaw/`
107
+
108
+ ### ✅ Compatibility notes
109
+
110
+ - Existing CLI and MCP usage remains available
111
+ - HTTP/SSE is **additive**, not a replacement
112
+ - Existing SQLite deployments can upgrade incrementally
113
+ - Full embeddings are **optional** and can be enabled later with `reindex`
114
+
115
+ ---
116
+
3
117
  ## 3.0.1 (2026-02-24)
4
118
 
5
119
  ### 🛠️ OpenClaw P0 fixes
6
120
 
7
121
  - **Fixed memory-sync session path mismatch** in cron prompt:
8
122
  - removed hardcoded `~/.openclaw/agents/main/sessions/*.jsonl`
9
- - switched to dynamic discovery with `noah` + env-derived agent path + `main` fallback
123
+ - switched to dynamic discovery with `noah` + env-derived agent path + `main`
124
+ fallback
10
125
  - **Aligned memory-tidy prompt** with the same session path health check strategy
11
126
  - **Added memory-sync health output contract**:
12
127
  - `session_scan_glob`
@@ -39,7 +154,8 @@
39
154
  ### 📚 Documentation realigned to v3 reality
40
155
 
41
156
  - Rewrote `README.md` and `README.en.md` to match actual v3 capabilities
42
- - Removed stale v2-era claims (embedding/reranker/link/snapshot/hybrid stack narrative)
157
+ - Removed stale v2-era claims (embedding/reranker/link/snapshot/hybrid stack
158
+ narrative)
43
159
  - Added explicit auto-ingest watcher behavior and env vars
44
160
 
45
161
  ---
@@ -51,11 +167,13 @@
51
167
  - Repositioned agent-memory as a structured companion to memory-core
52
168
  - Removed redundant v2 capabilities at API/tooling level
53
169
  - MCP toolset finalized at 9 tools:
54
- - `remember`, `recall`, `recall_path`, `boot`, `forget`, `reflect`, `status`, `ingest`, `surface`
170
+ - `remember`, `recall`, `recall_path`, `boot`, `forget`, `reflect`, `status`,
171
+ `ingest`, `surface`
55
172
  - Added narrative warm-boot and human-readable reflect report
56
173
 
57
174
  ---
58
175
 
59
176
  ## 2.x (legacy)
60
177
 
61
- v2.x included embedding/reranker/link/snapshot-era behavior. See git history and design docs for full details.
178
+ v2.x included embedding/reranker/link/snapshot-era behavior. See git history and
179
+ design docs for full details.
package/README.md CHANGED
@@ -1,88 +1,183 @@
1
- # 🧠 AgentMemory v3
1
+ <p align="center">
2
+ <img src="docs/assets/banner.jpg" alt="AgentMemory" width="800" />
3
+ </p>
2
4
 
3
- > 面向 AI Agent 的结构化长期记忆层:可写入、可检索、可衰减、可自动摄取。
5
+ <p align="center">
6
+ <strong>Agent-native memory layer with lifecycle management for AI agents.</strong>
7
+ </p>
4
8
 
5
- [![npm](https://img.shields.io/npm/v/@smyslenny/agent-memory)](https://www.npmjs.com/package/@smyslenny/agent-memory)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
- [![Node.js](https://img.shields.io/badge/Node.js-≥18-green.svg)](https://nodejs.org/)
8
- [![MCP](https://img.shields.io/badge/MCP-9_tools-orange.svg)](https://modelcontextprotocol.io/)
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@smyslenny/agent-memory"><img src="https://img.shields.io/npm/v/@smyslenny/agent-memory" alt="npm" /></a>
11
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT" /></a>
12
+ <a href="https://nodejs.org/"><img src="https://img.shields.io/badge/Node.js-%E2%89%A518-green.svg" alt="Node.js" /></a>
13
+ <a href="https://modelcontextprotocol.io/"><img src="https://img.shields.io/badge/MCP-10_tools-orange.svg" alt="MCP" /></a>
14
+ </p>
9
15
 
10
- **简体中文** | **[English](README.en.md)**
16
+ **English** | [简体中文说明](docs/README-zh.md)
11
17
 
12
- ---
18
+ AgentMemory is a SQLite-first memory layer for AI agents. It lets an agent:
13
19
 
14
- ## 项目定位(v3)
20
+ - **write** durable memories with typed records, URIs, and Write Guard dedup
21
+ - **read** them back through `boot`, `recall`, and context-aware `surface`
22
+ - **maintain** them over time with `reflect`, `reindex`, and feedback signals
23
+ - **integrate** through **CLI**, **MCP stdio**, or **HTTP/SSE**
15
24
 
16
- AgentMemory v3 中明确定位为 **OpenClaw memory-core 的结构化补充层**,而不是第二套全栈检索系统:
25
+ Current release: **`4.0.0-alpha.1`**.
17
26
 
18
- - Markdown(`memory/*.md` + `MEMORY.md`)是可读可编辑的事实源
19
- - agent-memory 是派生索引层,负责结构化记忆生命周期
27
+ Without an embedding provider, AgentMemory still works in **BM25-only mode**.
28
+ With one configured, it adds **hybrid recall** and **semantic dedup**.
20
29
 
21
- 核心能力:
30
+ ## 1) What is this project?
22
31
 
23
- - **类型化记忆**:`identity / emotion / knowledge / event`
24
- - **URI 路径寻址**:`core://`、`emotion://`、`knowledge://`、`event://`
25
- - **Write Guard**:写入前做去重与冲突门控
26
- - **BM25 检索**:带 priority × vitality 加权
27
- - **睡眠周期**:`reflect` 触发 decay / tidy / govern
28
- - **ingest 自动摄取**:从 markdown 提取并入库
29
- - **surface 只读浮现**:无副作用地补充上下文
30
- - **warm boot / reflect 报告**:人类可读输出
31
- - **多 Agent 隔离**:同库不同 agent_id 互不污染
32
+ AgentMemory is **not** a general document database and **not** a full RAG
33
+ framework. It is an **agent-native memory layer with lifecycle management**.
32
34
 
33
- ---
35
+ That means it is designed around the things agent runtimes actually need:
34
36
 
35
- ## 快速开始
37
+ - a place to store durable user facts, preferences, events, and identity
38
+ - a write path that can reject duplicates or merge near-duplicates safely
39
+ - a read path for explicit lookup (`recall`) and proactive context (`surface`)
40
+ - a lifecycle path for decay, governance, reindexing, and recovery-friendly jobs
41
+ - a local-first deployment model that stays useful even without extra infra
36
42
 
37
- ### 安装
43
+ Core building blocks in v4:
38
44
 
39
- ```bash
40
- npm install -g @smyslenny/agent-memory
41
- ```
45
+ - **Typed memories**: `identity`, `emotion`, `knowledge`, `event`
46
+ - **URI paths** for stable addressing
47
+ - **Write Guard** with semantic dedup + typed merge policy
48
+ - **Hybrid retrieval**: BM25 first, optional vector search
49
+ - **Context-aware surfacing** for task/recent-turn driven context injection
50
+ - **Lifecycle jobs**: `reflect`, `reindex`, job checkpoints, feedback signals
51
+ - **Three transport modes**: CLI, MCP stdio, HTTP/SSE
42
52
 
43
- ### CLI 示例
53
+ ## 2) How is it different from a vector DB, a RAG pipeline, or memory summaries?
44
54
 
45
- ```bash
46
- # 初始化数据库
47
- agent-memory init
55
+ | Thing | Good at | What AgentMemory adds |
56
+ | --- | --- | --- |
57
+ | Vector DB | Similarity search over embeddings | Write quality control, typed memory model, decay, governance, BM25 fallback, agent-scoped lifecycle |
58
+ | RAG pipeline | Retrieving external knowledge for prompts | Durable per-agent memory, surfacing, feedback, memory-specific maintenance |
59
+ | Markdown / summary files | Human-readable notes and editing | Structured retrieval, scoring, dedup, recall APIs, lifecycle operations |
60
+
61
+ A useful mental model:
62
+
63
+ - **Not a vector DB**: vectors are optional, not the product definition
64
+ - **Not a RAG pipeline**: memory is the primary object, not document chunks
65
+ - **Not just summarization**: memories can age, merge, be surfaced, and be
66
+ governed over time
67
+
68
+ If you want a short positioning sentence:
69
+
70
+ > AgentMemory is a **memory layer for agents**, not a generic search backend.
71
+
72
+ ## 3) When should I use it?
73
+
74
+ Use AgentMemory when your runtime needs one or more of these:
75
+
76
+ - **cross-session continuity** for a single agent or multiple scoped agents
77
+ - **durable preferences and facts** that should survive conversation boundaries
78
+ - **local-first deployment** with SQLite, not a mandatory external service stack
79
+ - **memory maintenance** instead of unbounded memory accumulation
80
+ - **multiple integration choices**: shell jobs, MCP tools, or HTTP services
81
+ - **optional semantic retrieval** without making embeddings mandatory
48
82
 
49
- # 写入记忆
50
- agent-memory remember "用户偏好深色模式" --type knowledge --uri knowledge://preferences/theme
83
+ It is a strong fit for:
51
84
 
52
- # 检索
53
- agent-memory recall "用户偏好" --limit 5
85
+ - personal assistants and copilots
86
+ - agentic workflows with scheduled maintenance
87
+ - multi-session chat agents
88
+ - local/offline-friendly agent runtimes
89
+ - systems that want a human-auditable memory store plus retrieval APIs
54
90
 
55
- # 启动时加载(叙事格式)
56
- agent-memory boot
91
+ It is probably **not** the right tool if you only need:
57
92
 
58
- # 触发睡眠周期
59
- agent-memory reflect all
93
+ - a high-scale standalone vector database
94
+ - classic document RAG over large corpora
95
+ - a one-shot conversation summarizer with no lifecycle management
96
+
97
+ ## 4) What does the architecture look like?
98
+
99
+ Write path, read path, and lifecycle path all share the same application core.
100
+ The transport is interchangeable.
101
+
102
+ ```mermaid
103
+ flowchart TD
104
+ subgraph Write[Write path]
105
+ W1[Agent runtime] --> W2[remember / ingest]
106
+ W2 --> W3[Write Guard\nsemantic dedup + typed merge]
107
+ W3 --> W4[(SQLite memories)]
108
+ W3 --> W5[(FTS / BM25)]
109
+ W3 --> W6[(Embeddings, optional)]
110
+ end
111
+
112
+ subgraph Read[Read path]
113
+ R1[Startup / task / query] --> R2[boot / recall / surface]
114
+ W4 --> R2
115
+ W5 --> R2
116
+ W6 --> R2
117
+ R2 --> R3[Ranked memories or surfaced context]
118
+ end
119
+
120
+ subgraph Life[Lifecycle path]
121
+ L1[Scheduler or operator] --> L2[reflect / reindex / feedback]
122
+ L2 --> W4
123
+ L2 --> W5
124
+ L2 --> W6
125
+ L2 --> L3[(maintenance_jobs + feedback_events)]
126
+ end
60
127
  ```
61
128
 
62
- ---
129
+ <p align="center">
130
+ <img src="docs/assets/architecture-diagram.jpg" alt="Architecture Overview" width="800" />
131
+ </p>
63
132
 
64
- ## MCP Server
133
+ See [docs/architecture.md](docs/architecture.md) for a deeper breakdown.
65
134
 
66
- ### 配置示例
135
+ ## 5) What is the shortest 5-minute setup?
136
+
137
+ <p align="center">
138
+ <img src="docs/assets/npm-badge.jpg" alt="npm install @smyslenny/agent-memory" width="500" />
139
+ </p>
140
+
141
+ Choose the integration path that matches your runtime.
142
+
143
+ ### A. CLI
144
+
145
+ ```bash
146
+ npm install @smyslenny/agent-memory
147
+
148
+ export AGENT_MEMORY_DB=./agent-memory.db
149
+ export AGENT_MEMORY_AGENT_ID=assistant-demo
150
+
151
+ npx agent-memory init
152
+ npx agent-memory remember \
153
+ "Alice prefers short weekly summaries." \
154
+ --type knowledge \
155
+ --uri knowledge://users/alice/preferences/summaries
156
+
157
+ npx agent-memory recall "What does Alice prefer?" --limit 5
158
+ npx agent-memory boot
159
+ npx agent-memory reflect all
160
+ ```
161
+
162
+ ### B. MCP stdio
67
163
 
68
164
  ```json
69
165
  {
70
166
  "mcpServers": {
71
167
  "agent-memory": {
72
168
  "command": "node",
73
- "args": ["node_modules/@smyslenny/agent-memory/dist/mcp/server.js"],
169
+ "args": ["./node_modules/@smyslenny/agent-memory/dist/mcp/server.js"],
74
170
  "env": {
75
171
  "AGENT_MEMORY_DB": "./agent-memory.db",
76
- "AGENT_MEMORY_AGENT_ID": "noah",
77
- "AGENT_MEMORY_AUTO_INGEST": "1",
78
- "AGENT_MEMORY_WORKSPACE": "/home/user/.openclaw/workspace"
172
+ "AGENT_MEMORY_AGENT_ID": "assistant-demo",
173
+ "AGENT_MEMORY_AUTO_INGEST": "0"
79
174
  }
80
175
  }
81
176
  }
82
177
  }
83
178
  ```
84
179
 
85
- ### MCP 工具(9个)
180
+ Available MCP tools in v4:
86
181
 
87
182
  - `remember`
88
183
  - `recall`
@@ -92,62 +187,112 @@ agent-memory reflect all
92
187
  - `reflect`
93
188
  - `status`
94
189
  - `ingest`
190
+ - `reindex`
95
191
  - `surface`
96
192
 
97
- > v3 已移除 `link` / `snapshot` 工具。
193
+ ### C. HTTP API
98
194
 
99
- ---
100
-
101
- ## Auto-Ingest(文件变更自动入库)
102
-
103
- MCP server 启动后会默认开启 watcher(`fs.watch`):
104
-
105
- - `~/.openclaw/workspace/memory/*.md`
106
- - `~/.openclaw/workspace/MEMORY.md`
107
-
108
- 当文件变化时自动执行 ingest(复用 Write Guard,幂等/去重)。
195
+ ```bash
196
+ npm install @smyslenny/agent-memory
197
+ export AGENT_MEMORY_DB=./agent-memory.db
198
+ export AGENT_MEMORY_AGENT_ID=assistant-demo
109
199
 
110
- 环境变量:
200
+ npx agent-memory serve --host 127.0.0.1 --port 3000
201
+ ```
111
202
 
112
- - `AGENT_MEMORY_AUTO_INGEST`
113
- - `1`(默认):开启
114
- - `0`:关闭
115
- - `AGENT_MEMORY_WORKSPACE`
116
- - 默认:`$HOME/.openclaw/workspace`
203
+ ```bash
204
+ curl -s http://127.0.0.1:3000/health
205
+
206
+ curl -s -X POST http://127.0.0.1:3000/v1/memories \
207
+ -H 'content-type: application/json' \
208
+ -d '{
209
+ "agent_id": "assistant-demo",
210
+ "type": "knowledge",
211
+ "uri": "knowledge://users/alice/preferences/summaries",
212
+ "content": "Alice prefers short weekly summaries."
213
+ }'
214
+
215
+ curl -s -X POST http://127.0.0.1:3000/v1/recall \
216
+ -H 'content-type: application/json' \
217
+ -d '{"agent_id":"assistant-demo","query":"Alice summary preference","limit":5}'
218
+ ```
117
219
 
118
- ---
220
+ Key HTTP routes:
221
+
222
+ - `GET /health`
223
+ - `GET /v1/status`
224
+ - `GET /v1/jobs/:id`
225
+ - `POST /v1/memories`
226
+ - `POST /v1/recall`
227
+ - `POST /v1/surface`
228
+ - `POST /v1/feedback`
229
+ - `POST /v1/reflect`
230
+ - `POST /v1/reindex`
231
+
232
+ `/v1/reflect` and `/v1/reindex` also support **SSE progress streaming**.
233
+
234
+ ## 6) How do I integrate it into my agent runtime?
235
+
236
+ A good default pattern looks like this:
237
+
238
+ 1. **Startup** → call `boot` to load identity / startup context
239
+ 2. **Durable fact appears** → call `remember`
240
+ 3. **Need an explicit lookup** → call `recall`
241
+ 4. **Need relevant context before replying/planning** → call `surface`
242
+ 5. **A memory was helpful or noisy** → record `feedback`
243
+ 6. **Background maintenance** → run `reflect all` on a schedule
244
+ 7. **Embeddings enabled or changed** → run `reindex`
245
+
246
+ Pseudo-flow:
247
+
248
+ ```text
249
+ user turn -> detect durable memory -> remember
250
+ agent planning -> surface(task, recent_turns)
251
+ explicit memory question -> recall(query)
252
+ startup -> boot
253
+ nightly / periodic -> reflect(all)
254
+ provider change -> reindex
255
+ ```
119
256
 
120
- ## OpenClaw 集成建议(方案A)
257
+ If you want a human-editable file workflow, treat Markdown as an **optional**
258
+ layer on top of the memory system, not the default definition of the product.
259
+ You can use `migrate` or `ingest`, or enable watcher-based ingest when your
260
+ host actually provides a workspace to watch.
121
261
 
122
- 推荐三段 cron:
262
+ ## Optional semantic retrieval
123
263
 
124
- 1. `memory-sync`(14:00 / 22:00)
125
- - 动态发现 session JSONL
126
- - 增量写入 `memory/YYYY-MM-DD.md`
127
- - best-effort 同步到 `agent-memory.remember`
128
- - 输出健康指标(扫描路径、会话文件数、提取数、写库数)
264
+ Embeddings are optional. If you want hybrid retrieval or semantic dedup, set:
129
265
 
130
- 2. `memory-tidy`(03:00)
131
- - 压缩/蒸馏 markdown
132
- - 调用 `agent-memory.reflect phase=all`
266
+ ```bash
267
+ export AGENT_MEMORY_EMBEDDING_PROVIDER=openai-compatible
268
+ export AGENT_MEMORY_EMBEDDING_BASE_URL=https://your-embedding-endpoint.example
269
+ export AGENT_MEMORY_EMBEDDING_MODEL=text-embedding-3-small
270
+ export AGENT_MEMORY_EMBEDDING_DIMENSION=1536
271
+ export AGENT_MEMORY_EMBEDDING_API_KEY=your-api-key
272
+ ```
133
273
 
134
- 3. `memory-surface`(14:05 / 22:05)
135
- - 生成 `RECENT.md`
274
+ Or use `AGENT_MEMORY_EMBEDDING_PROVIDER=local-http` for a local HTTP embedding
275
+ service. If no provider is configured, AgentMemory falls back to BM25-only.
136
276
 
137
- 设计原则:**Markdown 是真相源,agent-memory 是派生索引层。**
277
+ ## Documentation map
138
278
 
139
- ---
279
+ - [Architecture](docs/architecture.md)
280
+ - [Generic runtime integration](docs/integrations/generic.md)
281
+ - [OpenClaw integration](docs/integrations/openclaw.md)
282
+ - [Migration guide: v3 → v4](docs/migration-v3-v4.md)
283
+ - [Examples: quick start](examples/quick-start)
284
+ - [Examples: HTTP API](examples/http-api)
285
+ - [Examples: MCP stdio](examples/mcp-stdio)
286
+ - [Examples: OpenClaw](examples/openclaw)
140
287
 
141
- ## 开发
288
+ ## Development
142
289
 
143
290
  ```bash
144
291
  npm install
145
- npm test
146
292
  npm run build
293
+ npm test
147
294
  ```
148
295
 
149
- ---
150
-
151
296
  ## License
152
297
 
153
298
  MIT