agent-memory-graph 0.1.0

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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +341 -0
  3. package/config/default.json +28 -0
  4. package/config/graph.config.json +28 -0
  5. package/dist/cli/index.d.ts +3 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +303 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/plugin/entry.d.ts +3 -0
  10. package/dist/plugin/entry.d.ts.map +1 -0
  11. package/dist/plugin/entry.js +1652 -0
  12. package/dist/plugin/entry.js.map +1 -0
  13. package/dist/src/config/defaults.d.ts +8 -0
  14. package/dist/src/config/defaults.d.ts.map +1 -0
  15. package/dist/src/config/defaults.js +31 -0
  16. package/dist/src/config/defaults.js.map +1 -0
  17. package/dist/src/config/schema.d.ts +162 -0
  18. package/dist/src/config/schema.d.ts.map +1 -0
  19. package/dist/src/config/schema.js +39 -0
  20. package/dist/src/config/schema.js.map +1 -0
  21. package/dist/src/extract/dedup.d.ts +14 -0
  22. package/dist/src/extract/dedup.d.ts.map +1 -0
  23. package/dist/src/extract/dedup.js +79 -0
  24. package/dist/src/extract/dedup.js.map +1 -0
  25. package/dist/src/extract/extractor.d.ts +24 -0
  26. package/dist/src/extract/extractor.d.ts.map +1 -0
  27. package/dist/src/extract/extractor.js +162 -0
  28. package/dist/src/extract/extractor.js.map +1 -0
  29. package/dist/src/graph/engine.d.ts +90 -0
  30. package/dist/src/graph/engine.d.ts.map +1 -0
  31. package/dist/src/graph/engine.js +307 -0
  32. package/dist/src/graph/engine.js.map +1 -0
  33. package/dist/src/graph/schema.d.ts +12 -0
  34. package/dist/src/graph/schema.d.ts.map +1 -0
  35. package/dist/src/graph/schema.js +115 -0
  36. package/dist/src/graph/schema.js.map +1 -0
  37. package/dist/src/index.d.ts +129 -0
  38. package/dist/src/index.d.ts.map +1 -0
  39. package/dist/src/index.js +174 -0
  40. package/dist/src/index.js.map +1 -0
  41. package/dist/src/search/hybrid.d.ts +22 -0
  42. package/dist/src/search/hybrid.d.ts.map +1 -0
  43. package/dist/src/search/hybrid.js +38 -0
  44. package/dist/src/search/hybrid.js.map +1 -0
  45. package/dist/src/search/natural-language.d.ts +20 -0
  46. package/dist/src/search/natural-language.d.ts.map +1 -0
  47. package/dist/src/search/natural-language.js +429 -0
  48. package/dist/src/search/natural-language.js.map +1 -0
  49. package/dist/src/sync/export.d.ts +12 -0
  50. package/dist/src/sync/export.d.ts.map +1 -0
  51. package/dist/src/sync/export.js +117 -0
  52. package/dist/src/sync/export.js.map +1 -0
  53. package/dist/src/sync/memory-md.d.ts +19 -0
  54. package/dist/src/sync/memory-md.d.ts.map +1 -0
  55. package/dist/src/sync/memory-md.js +78 -0
  56. package/dist/src/sync/memory-md.js.map +1 -0
  57. package/openclaw.plugin.json +55 -0
  58. package/package.json +90 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KL / OpenClaw Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,341 @@
1
+ <p align="center">
2
+ <img src="https://img.shields.io/badge/🧠_Agent_Memory_Graph-Knowledge_that_persists-blueviolet?style=for-the-badge" alt="Agent Memory Graph" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <strong>Give your AI agent a persistent, queryable memory β€” powered by a local knowledge graph.</strong>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License" /></a>
11
+ <a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node.js-18%2B-green.svg" alt="Node.js 18+" /></a>
12
+ <img src="https://img.shields.io/badge/SQLite-FTS5-orange.svg" alt="SQLite FTS5" />
13
+ <img src="https://img.shields.io/badge/Zero_Config-βœ“-brightgreen.svg" alt="Zero Config" />
14
+ <img src="https://img.shields.io/badge/LLM-Any_Provider-purple.svg" alt="Any LLM" />
15
+ </p>
16
+
17
+ ---
18
+
19
+ ## The Problem
20
+
21
+ AI agents forget everything between sessions. Context windows overflow. MEMORY.md files become unstructured dumps. RAG retrieval misses relationships.
22
+
23
+ ## The Solution
24
+
25
+ **agent-memory-graph** builds a structured knowledge graph from your conversations β€” automatically. Every person, project, tool, and relationship is extracted, stored locally in SQLite, and queryable with natural language.
26
+
27
+ ```
28
+ You: "I just met Viktor, the CTO of Nexus Labs. They're building SkyNet-X using Rust."
29
+
30
+ β†’ Graph auto-extracts:
31
+ Viktor (Person) ──[CTO_OF]──→ Nexus Labs (Company)
32
+ Nexus Labs ──[BUILDS]──→ SkyNet-X (Project)
33
+ SkyNet-X ──[USES]──→ Rust (Language)
34
+
35
+ You: "Who works at Nexus Labs?"
36
+ β†’ "People at Nexus Labs: Viktor"
37
+
38
+ You: "How is Viktor connected to Rust?"
39
+ β†’ "Viktor β†’[CTO_OF]β†’ Nexus Labs β†’[BUILDS]β†’ SkyNet-X β†’[USES]β†’ Rust"
40
+ ```
41
+
42
+ ---
43
+
44
+ ## ✨ Features
45
+
46
+ | Feature | Description |
47
+ |---------|-------------|
48
+ | 🧠 **Auto-extraction** | LLM extracts entities & relationships from any text |
49
+ | πŸ—£οΈ **Natural language queries** | Ask questions like "Who works at X?" or "What does Y use?" |
50
+ | πŸ”— **Path finding** | Discover hidden connections between entities (BFS, up to 5 hops) |
51
+ | πŸ“¦ **Single SQLite file** | Zero external deps, fully portable, survives restarts |
52
+ | 🌐 **Domain-agnostic** | Software, crypto, research, CRM, notes β€” anything |
53
+ | ⚑ **Zero-config** | Works out of the box with any OpenAI-compatible LLM |
54
+ | πŸ”Œ **OpenClaw plugin** | Auto-ingests every conversation, registers query tools |
55
+ | πŸ” **Full-text search** | SQLite FTS5 for fast keyword search |
56
+ | πŸ“Š **Export** | Mermaid, DOT, JSON, CSV for visualization |
57
+
58
+ ---
59
+
60
+ ## πŸš€ Quick Start
61
+
62
+ ```bash
63
+ npm install agent-memory-graph
64
+ ```
65
+
66
+ ### As a library
67
+
68
+ ```typescript
69
+ import { MemoryGraph } from 'agent-memory-graph';
70
+
71
+ const graph = new MemoryGraph();
72
+
73
+ // Ingest β€” entities and relationships are auto-extracted
74
+ await graph.ingest(
75
+ "Alice is the CTO of TechCorp. She leads the Platform team " +
76
+ "and uses Kubernetes, Go, and PostgreSQL."
77
+ );
78
+
79
+ // Query with natural language
80
+ await graph.ask("What does Alice use?");
81
+ // β†’ "Alice: USES β†’ Kubernetes, Go, PostgreSQL"
82
+
83
+ await graph.ask("Who works at TechCorp?");
84
+ // β†’ "People at TechCorp: Alice"
85
+
86
+ // Find hidden connections
87
+ graph.findPath("Bob", "PostgreSQL");
88
+ // β†’ Bob β†’[MEMBER_OF]β†’ Platform team β†’[LED_BY]β†’ Alice β†’[USES]β†’ PostgreSQL
89
+
90
+ graph.close();
91
+ ```
92
+
93
+ ### As a CLI
94
+
95
+ ```bash
96
+ # Ingest from text
97
+ memory-graph ingest "Started learning Rust for the new backend service"
98
+
99
+ # Ask questions
100
+ memory-graph ask "What am I learning?"
101
+ # β†’ "Found: Rust (Language)"
102
+
103
+ # Search entities
104
+ memory-graph search "Rust"
105
+
106
+ # Find paths
107
+ memory-graph path "Alice" "PostgreSQL"
108
+
109
+ # Visualize
110
+ memory-graph visualize --format mermaid
111
+
112
+ # Stats
113
+ memory-graph stats
114
+ # β†’ Entities: 42 | Relationships: 67 | Types: Person, Tool, Project...
115
+ ```
116
+
117
+ ---
118
+
119
+ ## πŸ”Œ OpenClaw Plugin (Recommended)
120
+
121
+ The killer feature: install as an OpenClaw plugin and your agent **automatically remembers everything**.
122
+
123
+ ### Install
124
+
125
+ ```bash
126
+ openclaw plugins install agent-memory-graph
127
+ openclaw gateway restart
128
+ ```
129
+
130
+ ### What happens next
131
+
132
+ 1. **Every message** (>20 chars) is auto-ingested into the knowledge graph
133
+ 2. **5 tools** are registered for the agent to call:
134
+ - `memory_graph_ingest` β€” manually add knowledge
135
+ - `memory_graph_query` β€” natural language questions
136
+ - `memory_graph_search` β€” keyword search
137
+ - `memory_graph_path` β€” find connections between entities
138
+ - `memory_graph_stats` β€” graph statistics
139
+ 3. **Data persists** in `~/.openclaw/data/memory-graph.db` β€” survives `/new`, `/reset`, and restarts
140
+
141
+ ### Demo: Auto-detect in action
142
+
143
+ ```
144
+ [19:02] You: Hey, I just met Viktor who's the CTO of Nexus Labs.
145
+ They're building SkyNet-X using Rust and ROS2.
146
+
147
+ β”Œβ”€ memory-graph hook ─────────────────────────────┐
148
+ β”‚ βœ“ Auto-ingested: 4 entities, 5 relationships β”‚
149
+ β”‚ Viktor (Person), Nexus Labs (Company), β”‚
150
+ β”‚ SkyNet-X (Project), Rust (Language) β”‚
151
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
152
+
153
+ [19:05] You: Who works at Nexus Labs?
154
+
155
+ Agent calls: memory_graph_query("Who works at Nexus Labs?")
156
+ β†’ "People at Nexus Labs: Viktor"
157
+
158
+ [19:06] You: How is Viktor connected to Rust?
159
+
160
+ Agent calls: memory_graph_path("Viktor", "Rust")
161
+ β†’ "Viktor β†’[CTO_OF]β†’ Nexus Labs β†’[BUILDS]β†’ SkyNet-X β†’[USES]β†’ Rust"
162
+ ```
163
+
164
+ ### Plugin config
165
+
166
+ ```json
167
+ {
168
+ "plugins": {
169
+ "entries": {
170
+ "memory-graph": {
171
+ "enabled": true,
172
+ "config": {
173
+ "autoIngest": true,
174
+ "extractionModel": "gpt-4o-mini",
175
+ "dbPath": "~/.openclaw/data/memory-graph.db",
176
+ "maxHops": 5,
177
+ "minConfidence": 0.7
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ ```
184
+
185
+ Set `autoIngest: false` to disable auto-ingestion and only use manual tool calls.
186
+
187
+ ---
188
+
189
+ ## πŸ§ͺ Query Examples
190
+
191
+ The NL query engine understands 12+ question patterns:
192
+
193
+ | Question | What it does |
194
+ |----------|-------------|
195
+ | "What is Alice working on?" | Find outgoing relationships |
196
+ | "Who works at TechCorp?" | Find people connected to entity |
197
+ | "Where did Bob work before?" | Find PREVIOUSLY_WORKED_AT relations |
198
+ | "What does the team use?" | Find USES relationships |
199
+ | "What is Alice's role?" | Look up role property/relation |
200
+ | "List all people" | Filter by type (normalizes "people" β†’ "Person") |
201
+ | "List all companies" | Type normalization works for all types |
202
+ | "How is A connected to B?" | BFS path finding |
203
+ | "Who suggested X?" | Verb-to-relation matching |
204
+ | "What tools are mentioned?" | Type-based listing |
205
+
206
+ ---
207
+
208
+ ## πŸ“Š Graph Visualization
209
+
210
+ ```mermaid
211
+ graph LR
212
+ classDef person fill:#3b82f6,stroke:#1d4ed8,color:#fff
213
+ classDef company fill:#f97316,stroke:#c2410c,color:#fff
214
+ classDef project fill:#8b5cf6,stroke:#6d28d9,color:#fff
215
+ classDef tool fill:#10b981,stroke:#047857,color:#fff
216
+
217
+ Alice[Alice - CTO]:::person
218
+ Bob[Bob - Engineer]:::person
219
+ TechCorp[TechCorp]:::company
220
+ Platform[Platform Team]:::project
221
+ K8s[Kubernetes]:::tool
222
+ Go[Go]:::tool
223
+ PG[PostgreSQL]:::tool
224
+
225
+ Alice -->|CTO_OF| TechCorp
226
+ Alice -->|LEADS| Platform
227
+ Alice -->|USES| K8s
228
+ Alice -->|USES| Go
229
+ Alice -->|USES| PG
230
+ Bob -->|MEMBER_OF| Platform
231
+ Bob -->|WORKS_AT| TechCorp
232
+ ```
233
+
234
+ ---
235
+
236
+ ## βš™οΈ Configuration
237
+
238
+ ### LLM Provider
239
+
240
+ Works with **any OpenAI-compatible API** β€” OpenAI, Anthropic (via proxy), Ollama, LiteLLM, vLLM, 9router, etc.
241
+
242
+ | Variable | Description | Default |
243
+ |----------|-------------|---------|
244
+ | `OPENAI_API_KEY` | API key | `sk-local` |
245
+ | `OPENAI_BASE_URL` | API base URL | `http://127.0.0.1:20128/v1` |
246
+ | `MEMORY_GRAPH_API_KEY` | Override API key | β€” |
247
+ | `MEMORY_GRAPH_BASE_URL` | Override base URL | β€” |
248
+ | `MEMORY_GRAPH_MODEL` | Override model | `gpt-4o-mini` |
249
+
250
+ **Examples:**
251
+
252
+ ```bash
253
+ # OpenAI
254
+ export OPENAI_API_KEY="sk-..."
255
+
256
+ # Anthropic via LiteLLM/9router
257
+ export OPENAI_BASE_URL="http://127.0.0.1:4000/v1"
258
+ export MEMORY_GRAPH_MODEL="claude-3-5-haiku-20241022"
259
+
260
+ # Ollama (free, local)
261
+ export OPENAI_BASE_URL="http://localhost:11434/v1"
262
+ export MEMORY_GRAPH_MODEL="llama3.1"
263
+ ```
264
+
265
+ ### Domain Hints (optional)
266
+
267
+ Improve extraction accuracy for your specific domain:
268
+
269
+ ```json
270
+ {
271
+ "domains": [{
272
+ "name": "software",
273
+ "entityHints": ["Person", "Repository", "Language", "Framework", "Service"],
274
+ "relationHints": ["MAINTAINS", "USES", "DEPENDS_ON", "DEPLOYS_TO"]
275
+ }]
276
+ }
277
+ ```
278
+
279
+ ---
280
+
281
+ ## πŸ—οΈ Architecture
282
+
283
+ ```
284
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
285
+ β”‚ MemoryGraph API β”‚
286
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
287
+ β”‚ Ingest β”‚ Query β”‚ Search β”‚ Export β”‚
288
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
289
+ β”‚ LLM β”‚ NL Query β”‚ FTS5 β”‚ Mermaid β”‚
290
+ β”‚ Extractorβ”‚ Engine β”‚ Hybrid β”‚ DOT/JSON β”‚
291
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
292
+ β”‚ GraphEngine (SQLite + WAL) β”‚
293
+ β”‚ Entities β”‚ Relationships β”‚ FTS5 Index β”‚
294
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
295
+ ```
296
+
297
+ - **SQLite** β€” Single file, WAL mode, FTS5 full-text search
298
+ - **LLM extraction** β€” Any OpenAI-compatible provider
299
+ - **NL Query Engine** β€” 12+ regex patterns + smart entity-name fallback
300
+ - **Graph traversal** β€” BFS pathfinding up to 5 hops
301
+ - **Deduplication** β€” Levenshtein-based entity merging
302
+ - **Persistence** β€” Survives process restarts, session resets, and agent reboots
303
+
304
+ ---
305
+
306
+ ## πŸ“ˆ Test Results
307
+
308
+ ```
309
+ βœ“ Unit tests: 38/38 pass
310
+ βœ“ NL Query accuracy: 10/10 (local), 9.5/10 (plugin E2E)
311
+ βœ“ Path finding: 4/4 pass
312
+ βœ“ Edge cases: graceful handling, zero crashes
313
+ βœ“ Zero hallucination: no fabricated relationships
314
+ βœ“ Persistence: data survives /new, /reset, gateway restart
315
+ ```
316
+
317
+ ---
318
+
319
+ ## 🀝 Contributing
320
+
321
+ PRs welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).
322
+
323
+ ```bash
324
+ git clone https://github.com/KLSGG/agent-memory-graph
325
+ cd agent-memory-graph
326
+ npm install
327
+ npm test # 38 tests
328
+ npm run dev # Watch mode
329
+ ```
330
+
331
+ ---
332
+
333
+ ## πŸ“„ License
334
+
335
+ [MIT](LICENSE) β€” Use it however you want.
336
+
337
+ ---
338
+
339
+ <p align="center">
340
+ <em>Built for <a href="https://github.com/openclaw/openclaw">OpenClaw</a> agents that need to remember.</em>
341
+ </p>
@@ -0,0 +1,28 @@
1
+ {
2
+ "storage": {
3
+ "path": "./memory-graph.db",
4
+ "maxSizeMb": 500
5
+ },
6
+ "extraction": {
7
+ "provider": "auto",
8
+ "model": "auto",
9
+ "autoExtract": true,
10
+ "minConfidence": 0.7,
11
+ "batchSize": 5
12
+ },
13
+ "domains": [],
14
+ "deduplication": {
15
+ "enabled": true,
16
+ "similarityThreshold": 0.85
17
+ },
18
+ "sync": {
19
+ "memoryMd": null,
20
+ "neuralMemory": null,
21
+ "importOnStart": false
22
+ },
23
+ "query": {
24
+ "maxHops": 3,
25
+ "maxResults": 10,
26
+ "includeConfidence": true
27
+ }
28
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "storage": {
3
+ "path": "./memory-graph.db",
4
+ "maxSizeMb": 500
5
+ },
6
+ "extraction": {
7
+ "provider": "openai",
8
+ "model": "kr/claude-haiku-4.5",
9
+ "autoExtract": true,
10
+ "minConfidence": 0.7,
11
+ "batchSize": 5
12
+ },
13
+ "domains": [],
14
+ "deduplication": {
15
+ "enabled": true,
16
+ "similarityThreshold": 0.85
17
+ },
18
+ "sync": {
19
+ "memoryMd": null,
20
+ "neuralMemory": null,
21
+ "importOnStart": false
22
+ },
23
+ "query": {
24
+ "maxHops": 3,
25
+ "maxResults": 10,
26
+ "includeConfidence": true
27
+ }
28
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../cli/index.ts"],"names":[],"mappings":""}