@lov3kaizen/agentsea-memory 0.5.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +450 -0
  3. package/dist/chunk-GACX3FPR.js +1402 -0
  4. package/dist/chunk-M44NB53O.js +1226 -0
  5. package/dist/chunk-MQDWBPZU.js +972 -0
  6. package/dist/chunk-TPC7MYWK.js +1495 -0
  7. package/dist/chunk-XD2CQGSD.js +1540 -0
  8. package/dist/chunk-YI7RPDEV.js +1215 -0
  9. package/dist/core.types-lkxKv-bW.d.cts +242 -0
  10. package/dist/core.types-lkxKv-bW.d.ts +242 -0
  11. package/dist/debug/index.cjs +1248 -0
  12. package/dist/debug/index.d.cts +3 -0
  13. package/dist/debug/index.d.ts +3 -0
  14. package/dist/debug/index.js +20 -0
  15. package/dist/index-7SsAJ4et.d.ts +525 -0
  16. package/dist/index-BGxYqpFb.d.cts +601 -0
  17. package/dist/index-BX62efZu.d.ts +565 -0
  18. package/dist/index-Bbc3COw0.d.cts +748 -0
  19. package/dist/index-Bczz1Eyk.d.ts +637 -0
  20. package/dist/index-C7pEiT8L.d.cts +637 -0
  21. package/dist/index-CHetLTb0.d.ts +389 -0
  22. package/dist/index-CloeiFyx.d.ts +748 -0
  23. package/dist/index-DNOhq-3y.d.cts +525 -0
  24. package/dist/index-Da-M8FOV.d.cts +389 -0
  25. package/dist/index-Dy8UjRFz.d.cts +565 -0
  26. package/dist/index-aVcITW0B.d.ts +601 -0
  27. package/dist/index.cjs +8554 -0
  28. package/dist/index.d.cts +293 -0
  29. package/dist/index.d.ts +293 -0
  30. package/dist/index.js +742 -0
  31. package/dist/processing/index.cjs +1575 -0
  32. package/dist/processing/index.d.cts +2 -0
  33. package/dist/processing/index.d.ts +2 -0
  34. package/dist/processing/index.js +24 -0
  35. package/dist/retrieval/index.cjs +1262 -0
  36. package/dist/retrieval/index.d.cts +2 -0
  37. package/dist/retrieval/index.d.ts +2 -0
  38. package/dist/retrieval/index.js +26 -0
  39. package/dist/sharing/index.cjs +1003 -0
  40. package/dist/sharing/index.d.cts +3 -0
  41. package/dist/sharing/index.d.ts +3 -0
  42. package/dist/sharing/index.js +16 -0
  43. package/dist/stores/index.cjs +1445 -0
  44. package/dist/stores/index.d.cts +2 -0
  45. package/dist/stores/index.d.ts +2 -0
  46. package/dist/stores/index.js +20 -0
  47. package/dist/structures/index.cjs +1530 -0
  48. package/dist/structures/index.d.cts +3 -0
  49. package/dist/structures/index.d.ts +3 -0
  50. package/dist/structures/index.js +24 -0
  51. package/package.json +141 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 lovekaizen
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,450 @@
1
+ # @lov3kaizen/agentsea-memory
2
+
3
+ Advanced memory management system for AI agents with semantic retrieval, hierarchical structures, and multi-agent support. Build agents with persistent, intelligent memory that can recall relevant context across conversations.
4
+
5
+ ## Features
6
+
7
+ - **Multiple Backends** - Buffer, Redis, PostgreSQL, SQLite, and Pinecone support
8
+ - **Memory Structures** - Episodic, Semantic, and Working memory patterns
9
+ - **Smart Retrieval** - Recency, relevance, and importance-based strategies
10
+ - **Multi-Agent Sharing** - Share memories between agents with access control
11
+ - **Processing Pipeline** - Consolidation, summarization, and forgetting
12
+ - **Debug Tools** - Inspect and visualize memory state
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pnpm add @lov3kaizen/agentsea-memory
18
+ ```
19
+
20
+ Optional backends:
21
+
22
+ ```bash
23
+ # For Redis
24
+ pnpm add ioredis
25
+
26
+ # For PostgreSQL
27
+ pnpm add pg
28
+
29
+ # For SQLite
30
+ pnpm add better-sqlite3
31
+
32
+ # For Pinecone vector store
33
+ pnpm add @pinecone-database/pinecone
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ```typescript
39
+ import {
40
+ MemoryManager,
41
+ BufferMemoryStore,
42
+ RecencyRetrieval,
43
+ } from '@lov3kaizen/agentsea-memory';
44
+
45
+ // Create memory store
46
+ const store = new BufferMemoryStore({
47
+ maxEntries: 1000,
48
+ });
49
+
50
+ // Create retrieval strategy
51
+ const retrieval = new RecencyRetrieval({
52
+ maxResults: 10,
53
+ decayFactor: 0.95,
54
+ });
55
+
56
+ // Create memory manager
57
+ const memory = new MemoryManager({
58
+ store,
59
+ retrieval,
60
+ });
61
+
62
+ // Add memories
63
+ await memory.add({
64
+ content: 'User prefers dark mode',
65
+ type: 'preference',
66
+ importance: 0.8,
67
+ metadata: { category: 'ui' },
68
+ });
69
+
70
+ // Retrieve relevant memories
71
+ const results = await memory.retrieve('What are the user settings?');
72
+ ```
73
+
74
+ ## Memory Stores
75
+
76
+ ### Buffer Memory (In-Memory)
77
+
78
+ Fast, ephemeral storage for development and testing:
79
+
80
+ ```typescript
81
+ import { BufferMemoryStore } from '@lov3kaizen/agentsea-memory/stores';
82
+
83
+ const store = new BufferMemoryStore({
84
+ maxEntries: 1000,
85
+ ttl: 3600000, // 1 hour
86
+ });
87
+ ```
88
+
89
+ ### Redis Memory
90
+
91
+ Distributed memory with persistence:
92
+
93
+ ```typescript
94
+ import { RedisMemoryStore } from '@lov3kaizen/agentsea-memory/stores';
95
+
96
+ const store = new RedisMemoryStore({
97
+ host: 'localhost',
98
+ port: 6379,
99
+ keyPrefix: 'agent:memory:',
100
+ ttl: 86400, // 1 day
101
+ });
102
+ ```
103
+
104
+ ### PostgreSQL Memory
105
+
106
+ Relational storage with complex queries:
107
+
108
+ ```typescript
109
+ import { PostgresMemoryStore } from '@lov3kaizen/agentsea-memory/stores';
110
+
111
+ const store = new PostgresMemoryStore({
112
+ connectionString: process.env.DATABASE_URL,
113
+ tableName: 'agent_memories',
114
+ });
115
+
116
+ await store.initialize(); // Creates table if not exists
117
+ ```
118
+
119
+ ### SQLite Memory
120
+
121
+ Local file-based persistence:
122
+
123
+ ```typescript
124
+ import { SQLiteMemoryStore } from '@lov3kaizen/agentsea-memory/stores';
125
+
126
+ const store = new SQLiteMemoryStore({
127
+ filename: './agent-memory.db',
128
+ tableName: 'memories',
129
+ });
130
+ ```
131
+
132
+ ### Pinecone Memory (Vector)
133
+
134
+ Semantic search with embeddings:
135
+
136
+ ```typescript
137
+ import { PineconeMemoryStore } from '@lov3kaizen/agentsea-memory/stores';
138
+ import { OpenAIEmbeddings } from '@lov3kaizen/agentsea-embeddings';
139
+
140
+ const embeddings = new OpenAIEmbeddings({
141
+ apiKey: process.env.OPENAI_API_KEY,
142
+ });
143
+
144
+ const store = new PineconeMemoryStore({
145
+ apiKey: process.env.PINECONE_API_KEY,
146
+ environment: 'us-east-1',
147
+ indexName: 'agent-memories',
148
+ embeddings,
149
+ });
150
+ ```
151
+
152
+ ## Memory Structures
153
+
154
+ ### Episodic Memory
155
+
156
+ Event-based memories with temporal context:
157
+
158
+ ```typescript
159
+ import { EpisodicMemory } from '@lov3kaizen/agentsea-memory/structures';
160
+
161
+ const episodic = new EpisodicMemory({
162
+ store,
163
+ maxEpisodes: 100,
164
+ });
165
+
166
+ // Record an episode
167
+ await episodic.recordEpisode({
168
+ event: 'user_interaction',
169
+ participants: ['user-123', 'agent'],
170
+ content: 'Discussed project requirements',
171
+ timestamp: new Date(),
172
+ metadata: { sentiment: 'positive' },
173
+ });
174
+
175
+ // Query episodes
176
+ const episodes = await episodic.queryEpisodes({
177
+ timeRange: { start: lastWeek, end: now },
178
+ participants: ['user-123'],
179
+ });
180
+ ```
181
+
182
+ ### Semantic Memory
183
+
184
+ Fact-based knowledge storage:
185
+
186
+ ```typescript
187
+ import { SemanticMemory } from '@lov3kaizen/agentsea-memory/structures';
188
+
189
+ const semantic = new SemanticMemory({
190
+ store,
191
+ embeddings,
192
+ });
193
+
194
+ // Store facts
195
+ await semantic.addFact({
196
+ subject: 'TypeScript',
197
+ predicate: 'is',
198
+ object: 'a typed superset of JavaScript',
199
+ confidence: 0.95,
200
+ });
201
+
202
+ // Query by concept
203
+ const facts = await semantic.queryByConcept('TypeScript');
204
+ ```
205
+
206
+ ### Working Memory
207
+
208
+ Short-term active memory:
209
+
210
+ ```typescript
211
+ import { WorkingMemory } from '@lov3kaizen/agentsea-memory/structures';
212
+
213
+ const working = new WorkingMemory({
214
+ capacity: 7, // Miller's law
215
+ decayRate: 0.1,
216
+ });
217
+
218
+ // Add to working memory
219
+ await working.focus({
220
+ content: 'Current task: debugging API',
221
+ priority: 'high',
222
+ });
223
+
224
+ // Get active items
225
+ const active = working.getActiveItems();
226
+ ```
227
+
228
+ ## Retrieval Strategies
229
+
230
+ ### Recency-Based
231
+
232
+ Prioritize recent memories:
233
+
234
+ ```typescript
235
+ import { RecencyRetrieval } from '@lov3kaizen/agentsea-memory/retrieval';
236
+
237
+ const retrieval = new RecencyRetrieval({
238
+ maxResults: 10,
239
+ decayFactor: 0.95, // Exponential decay
240
+ });
241
+ ```
242
+
243
+ ### Relevance-Based
244
+
245
+ Semantic similarity matching:
246
+
247
+ ```typescript
248
+ import { RelevanceRetrieval } from '@lov3kaizen/agentsea-memory/retrieval';
249
+
250
+ const retrieval = new RelevanceRetrieval({
251
+ embeddings,
252
+ similarityThreshold: 0.7,
253
+ maxResults: 20,
254
+ });
255
+ ```
256
+
257
+ ### Importance-Based
258
+
259
+ Priority by assigned importance:
260
+
261
+ ```typescript
262
+ import { ImportanceRetrieval } from '@lov3kaizen/agentsea-memory/retrieval';
263
+
264
+ const retrieval = new ImportanceRetrieval({
265
+ importanceThreshold: 0.5,
266
+ maxResults: 15,
267
+ });
268
+ ```
269
+
270
+ ### Hybrid Retrieval
271
+
272
+ Combine multiple strategies:
273
+
274
+ ```typescript
275
+ import { HybridRetrieval } from '@lov3kaizen/agentsea-memory/retrieval';
276
+
277
+ const retrieval = new HybridRetrieval({
278
+ strategies: [
279
+ { strategy: recency, weight: 0.3 },
280
+ { strategy: relevance, weight: 0.5 },
281
+ { strategy: importance, weight: 0.2 },
282
+ ],
283
+ });
284
+ ```
285
+
286
+ ## Multi-Agent Memory Sharing
287
+
288
+ ### Access Control
289
+
290
+ ```typescript
291
+ import { AccessControl } from '@lov3kaizen/agentsea-memory/sharing';
292
+
293
+ const access = new AccessControl({
294
+ defaultPermission: 'read',
295
+ strictMode: false,
296
+ });
297
+
298
+ // Grant permissions
299
+ access.grantPermission('admin', 'agent-2', '*', 'write');
300
+ access.grantPermission('admin', 'agent-3', 'facts:*', 'read');
301
+
302
+ // Check access
303
+ const canWrite = access.hasPermission('agent-2', 'memory-123', 'write');
304
+ ```
305
+
306
+ ### Shared Memory Pool
307
+
308
+ ```typescript
309
+ import { SharedMemoryPool } from '@lov3kaizen/agentsea-memory/sharing';
310
+
311
+ const pool = new SharedMemoryPool({
312
+ store,
313
+ accessControl: access,
314
+ });
315
+
316
+ // Share memory between agents
317
+ await pool.share('agent-1', 'memory-123', ['agent-2', 'agent-3']);
318
+
319
+ // Read shared memory
320
+ const memories = await pool.getShared('agent-2');
321
+ ```
322
+
323
+ ## Memory Processing
324
+
325
+ ### Consolidation
326
+
327
+ Merge similar memories:
328
+
329
+ ```typescript
330
+ import { MemoryConsolidator } from '@lov3kaizen/agentsea-memory/processing';
331
+
332
+ const consolidator = new MemoryConsolidator({
333
+ similarityThreshold: 0.85,
334
+ minGroupSize: 3,
335
+ });
336
+
337
+ // Consolidate similar memories
338
+ await consolidator.consolidate(store);
339
+ ```
340
+
341
+ ### Summarization
342
+
343
+ Compress memories using LLM:
344
+
345
+ ```typescript
346
+ import { MemorySummarizer } from '@lov3kaizen/agentsea-memory/processing';
347
+
348
+ const summarizer = new MemorySummarizer({
349
+ provider: anthropicProvider,
350
+ maxTokens: 500,
351
+ });
352
+
353
+ // Summarize old memories
354
+ await summarizer.summarize(store, {
355
+ olderThan: oneWeekAgo,
356
+ minEntries: 10,
357
+ });
358
+ ```
359
+
360
+ ### Forgetting
361
+
362
+ Remove low-importance or old memories:
363
+
364
+ ```typescript
365
+ import { ForgetPolicy } from '@lov3kaizen/agentsea-memory/processing';
366
+
367
+ const policy = new ForgetPolicy({
368
+ maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
369
+ minImportance: 0.3,
370
+ maxEntries: 10000,
371
+ });
372
+
373
+ // Apply forgetting policy
374
+ await policy.apply(store);
375
+ ```
376
+
377
+ ## Debug Tools
378
+
379
+ ### Memory Inspector
380
+
381
+ ```typescript
382
+ import { MemoryInspector } from '@lov3kaizen/agentsea-memory/debug';
383
+
384
+ const inspector = new MemoryInspector(store);
385
+
386
+ // Get statistics
387
+ const stats = await inspector.getStats();
388
+ // { totalEntries: 1500, avgImportance: 0.65, oldestEntry: Date, ... }
389
+
390
+ // Search memories
391
+ const results = await inspector.search({
392
+ query: 'user preferences',
393
+ limit: 10,
394
+ });
395
+
396
+ // Export for analysis
397
+ await inspector.exportToJSON('./memory-dump.json');
398
+ ```
399
+
400
+ ## API Reference
401
+
402
+ ### MemoryEntry
403
+
404
+ ```typescript
405
+ interface MemoryEntry {
406
+ id: string;
407
+ content: string;
408
+ type: 'fact' | 'episode' | 'preference' | 'context' | 'custom';
409
+ importance: number; // 0-1
410
+ timestamp: number;
411
+ accessCount: number;
412
+ lastAccessed: number;
413
+ metadata?: Record<string, unknown>;
414
+ embedding?: number[];
415
+ agentId?: string;
416
+ conversationId?: string;
417
+ tags?: string[];
418
+ }
419
+ ```
420
+
421
+ ### MemoryManager
422
+
423
+ ```typescript
424
+ interface MemoryManager {
425
+ add(entry: Partial<MemoryEntry>): Promise<MemoryEntry>;
426
+ retrieve(query: string, options?: RetrievalOptions): Promise<MemoryEntry[]>;
427
+ update(id: string, updates: Partial<MemoryEntry>): Promise<MemoryEntry>;
428
+ delete(id: string): Promise<boolean>;
429
+ clear(): Promise<void>;
430
+ }
431
+ ```
432
+
433
+ ### MemoryStore
434
+
435
+ ```typescript
436
+ interface MemoryStore {
437
+ add(entry: MemoryEntry): Promise<void>;
438
+ get(id: string): Promise<MemoryEntry | null>;
439
+ update(id: string, entry: Partial<MemoryEntry>): Promise<void>;
440
+ delete(id: string): Promise<boolean>;
441
+ query(options: QueryOptions): Promise<MemoryEntry[]>;
442
+ clear(): Promise<void>;
443
+ }
444
+ ```
445
+
446
+ ## Links
447
+
448
+ - [Documentation](https://github.com/lov3kaizen/agentsea)
449
+ - [Examples](../../examples)
450
+ - [API Reference](../../docs/API.md)