@danielsimonjr/memoryjs 1.1.0 → 1.2.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/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # MemoryJS
2
2
 
3
- [![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)](https://github.com/danielsimonjr/memoryjs)
3
+ [![Version](https://img.shields.io/badge/version-1.2.0-blue.svg)](https://github.com/danielsimonjr/memoryjs)
4
4
  [![NPM](https://img.shields.io/npm/v/@danielsimonjr/memoryjs.svg)](https://www.npmjs.com/package/@danielsimonjr/memoryjs)
5
5
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
7
 
8
8
  A **TypeScript knowledge graph library** for managing entities, relations, and observations with **advanced search capabilities**, **hierarchical organization**, and **multiple storage backends**.
9
9
 
10
- > **Core library** powering [@danielsimonjr/memory-mcp](https://www.npmjs.com/package/@danielsimonjr/memory-mcp). Provides 73 TypeScript files, ~29K lines of code, dual storage backends (JSONL/SQLite), and sophisticated search algorithms including BM25, TF-IDF, fuzzy, semantic, and hybrid search.
10
+ > **Core library** powering [@danielsimonjr/memory-mcp](https://www.npmjs.com/package/@danielsimonjr/memory-mcp). Provides **93 TypeScript files**, **~41K lines of code**, dual storage backends (JSONL/SQLite), sophisticated search algorithms (BM25, TF-IDF, fuzzy, semantic, hybrid), and a complete **Agent Memory System** for AI agents.
11
11
 
12
12
  ## Table of Contents
13
13
 
@@ -18,6 +18,7 @@ A **TypeScript knowledge graph library** for managing entities, relations, and o
18
18
  - [Storage Options](#storage-options)
19
19
  - [Search Capabilities](#search-capabilities)
20
20
  - [Graph Algorithms](#graph-algorithms)
21
+ - [Agent Memory System](#agent-memory-system)
21
22
  - [API Reference](#api-reference)
22
23
  - [Configuration](#configuration)
23
24
  - [Development](#development)
@@ -50,14 +51,15 @@ A **TypeScript knowledge graph library** for managing entities, relations, and o
50
51
 
51
52
  | Module | Files | Key Components |
52
53
  |--------|-------|----------------|
54
+ | `agent/` | 19 | AgentMemoryManager, SessionManager, DecayEngine, WorkingMemoryManager |
53
55
  | `core/` | 12 | EntityManager, GraphStorage, SQLiteStorage, TransactionManager |
54
56
  | `search/` | 29 | SearchManager, BM25Search, HybridScorer, VectorStore, QueryPlanner |
55
57
  | `features/` | 9 | IOManager, ArchiveManager, CompressionManager, StreamingExporter |
56
58
  | `utils/` | 18 | BatchProcessor, CompressedCache, WorkerPoolManager, MemoryMonitor |
57
- | `types/` | 2 | Entity, Relation, KnowledgeGraph interfaces |
59
+ | `types/` | 3 | Entity, Relation, AgentEntity, SessionEntity interfaces |
58
60
  | `workers/` | 2 | Levenshtein distance calculations |
59
61
 
60
- **Total:** 73 TypeScript files | ~29,000 lines of code | 558 exports
62
+ **Total:** 93 TypeScript files | ~41,000 lines of code | 657 exports | 91 classes | 216 interfaces
61
63
 
62
64
  ## Installation
63
65
 
@@ -353,6 +355,110 @@ await ctx.graphTraversal.dfs('startNode', (node) => {
353
355
  });
354
356
  ```
355
357
 
358
+ ## Agent Memory System
359
+
360
+ A complete memory system for AI agents with working memory, episodic memory, decay mechanisms, and multi-agent support.
361
+
362
+ ### Key Components
363
+
364
+ | Component | Description |
365
+ |-----------|-------------|
366
+ | **AgentMemoryManager** | Unified facade for all agent memory operations |
367
+ | **SessionManager** | Session lifecycle management |
368
+ | **WorkingMemoryManager** | Short-term memory with promotion to long-term |
369
+ | **EpisodicMemoryManager** | Timeline-based episodic memory |
370
+ | **DecayEngine** | Time-based memory importance decay |
371
+ | **SalienceEngine** | Context-aware memory scoring |
372
+ | **MultiAgentMemoryManager** | Shared memory with visibility controls |
373
+ | **ConflictResolver** | Resolution strategies for concurrent updates |
374
+
375
+ ### Quick Start
376
+
377
+ ```typescript
378
+ import { ManagerContext } from '@danielsimonjr/memoryjs';
379
+
380
+ const ctx = new ManagerContext('./memory.jsonl');
381
+ const agent = ctx.agentMemory();
382
+
383
+ // Start a session
384
+ const session = await agent.startSession({ agentId: 'my-agent' });
385
+
386
+ // Add working memory
387
+ await agent.addWorkingMemory({
388
+ sessionId: session.name,
389
+ content: 'User prefers dark mode',
390
+ importance: 7
391
+ });
392
+
393
+ // Create episodic memory
394
+ await agent.createEpisode('Completed onboarding flow', {
395
+ sessionId: session.name,
396
+ importance: 8
397
+ });
398
+
399
+ // Retrieve context for LLM prompt
400
+ const context = await agent.retrieveForContext({
401
+ maxTokens: 2000,
402
+ includeEpisodic: true
403
+ });
404
+
405
+ // End session
406
+ await agent.endSession(session.name);
407
+ ```
408
+
409
+ ### Memory Types
410
+
411
+ ```typescript
412
+ type MemoryType = 'working' | 'episodic' | 'semantic' | 'procedural';
413
+ ```
414
+
415
+ - **Working Memory**: Short-term, session-scoped memories that may be promoted
416
+ - **Episodic Memory**: Timeline-based event memories with temporal ordering
417
+ - **Semantic Memory**: Long-term factual knowledge
418
+ - **Procedural Memory**: Learned behaviors and patterns
419
+
420
+ ### Decay System
421
+
422
+ Memories naturally decay over time unless reinforced:
423
+
424
+ ```typescript
425
+ // Configure decay behavior
426
+ const agent = ctx.agentMemory({
427
+ decay: {
428
+ halfLifeHours: 168, // 1 week half-life
429
+ minImportance: 0.1 // Never fully forget
430
+ },
431
+ enableAutoDecay: true
432
+ });
433
+
434
+ // Reinforce important memories
435
+ await agent.confirmMemory('memory_name', 0.1); // Boost confidence
436
+ await agent.promoteMemory('memory_name', 'episodic'); // Promote to long-term
437
+ ```
438
+
439
+ ### Multi-Agent Support
440
+
441
+ ```typescript
442
+ // Register agents
443
+ agent.registerAgent('agent_1', {
444
+ name: 'Research Agent',
445
+ type: 'llm',
446
+ trustLevel: 0.8,
447
+ capabilities: ['read', 'write']
448
+ });
449
+
450
+ // Create memories with visibility controls
451
+ await agent.addWorkingMemory({
452
+ sessionId: session.name,
453
+ content: 'Shared insight',
454
+ visibility: 'shared', // 'private' | 'shared' | 'public'
455
+ ownerAgentId: 'agent_1'
456
+ });
457
+
458
+ // Cross-agent search
459
+ const results = await agent.searchCrossAgent('agent_2', 'query');
460
+ ```
461
+
356
462
  ## API Reference
357
463
 
358
464
  ### EntityManager
@@ -472,8 +578,18 @@ npm run typecheck # Type checking without emit
472
578
 
473
579
  ```
474
580
  memoryjs/
475
- ├── src/ # Source (73 TypeScript files)
581
+ ├── src/ # Source (93 TypeScript files)
476
582
  │ ├── index.ts # Entry point
583
+ │ ├── agent/ # Agent Memory System (19 files)
584
+ │ │ ├── AgentMemoryManager.ts # Unified facade
585
+ │ │ ├── SessionManager.ts # Session lifecycle
586
+ │ │ ├── WorkingMemoryManager.ts # Working memory
587
+ │ │ ├── EpisodicMemoryManager.ts # Episodic memory
588
+ │ │ ├── DecayEngine.ts # Memory decay
589
+ │ │ ├── SalienceEngine.ts # Context scoring
590
+ │ │ ├── MultiAgentMemoryManager.ts # Multi-agent support
591
+ │ │ ├── ConflictResolver.ts # Conflict resolution
592
+ │ │ └── ...
477
593
  │ ├── core/ # Core managers (12 files)
478
594
  │ │ ├── ManagerContext.ts # Context holder (lazy init)
479
595
  │ │ ├── EntityManager.ts # Entity CRUD + hierarchy
@@ -497,10 +613,10 @@ memoryjs/
497
613
  │ │ ├── ArchiveManager.ts # Entity archival
498
614
  │ │ ├── CompressionManager.ts # Duplicate detection
499
615
  │ │ └── ...
500
- │ ├── types/ # TypeScript definitions (2 files)
616
+ │ ├── types/ # TypeScript definitions (3 files)
501
617
  │ ├── utils/ # Shared utilities (18 files)
502
618
  │ └── workers/ # Worker pool (2 files)
503
- ├── tests/ # Test suite
619
+ ├── tests/ # Test suite (3600+ tests)
504
620
  │ ├── unit/ # Unit tests
505
621
  │ ├── integration/ # Integration tests
506
622
  │ └── performance/ # Benchmarks