@elizaos/plugin-memory 1.1.1 → 2.0.0-alpha

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 (44) hide show
  1. package/dist/evaluators/index.d.ts +3 -0
  2. package/dist/evaluators/index.d.ts.map +1 -0
  3. package/dist/evaluators/long-term-extraction.d.ts +1 -6
  4. package/dist/evaluators/long-term-extraction.d.ts.map +1 -0
  5. package/dist/evaluators/summarization.d.ts +1 -28
  6. package/dist/evaluators/summarization.d.ts.map +1 -0
  7. package/dist/generated/prompts/typescript/prompts.d.ts +16 -0
  8. package/dist/generated/prompts/typescript/prompts.d.ts.map +1 -0
  9. package/dist/index.d.ts +7 -39
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/{node/index.node.js → index.js} +800 -981
  12. package/dist/index.js.map +20 -0
  13. package/dist/providers/context-summary.d.ts +2 -11
  14. package/dist/providers/context-summary.d.ts.map +1 -0
  15. package/dist/providers/index.d.ts +3 -0
  16. package/dist/providers/index.d.ts.map +1 -0
  17. package/dist/providers/long-term-memory.d.ts +2 -16
  18. package/dist/providers/long-term-memory.d.ts.map +1 -0
  19. package/dist/schemas/index.d.ts +4 -9
  20. package/dist/schemas/index.d.ts.map +1 -0
  21. package/dist/schemas/long-term-memories.d.ts +1 -4
  22. package/dist/schemas/long-term-memories.d.ts.map +1 -0
  23. package/dist/schemas/memory-access-logs.d.ts +20 -58
  24. package/dist/schemas/memory-access-logs.d.ts.map +1 -0
  25. package/dist/schemas/session-summaries.d.ts +1 -4
  26. package/dist/schemas/session-summaries.d.ts.map +1 -0
  27. package/dist/services/memory-service.d.ts +7 -75
  28. package/dist/services/memory-service.d.ts.map +1 -0
  29. package/dist/types/index.d.ts +5 -26
  30. package/dist/types/index.d.ts.map +1 -0
  31. package/package.json +45 -48
  32. package/README.md +0 -335
  33. package/dist/actions/remember.d.ts +0 -11
  34. package/dist/browser/index.browser.js +0 -209
  35. package/dist/browser/index.browser.js.map +0 -20
  36. package/dist/browser/index.d.ts +0 -2
  37. package/dist/cjs/index.d.ts +0 -2
  38. package/dist/cjs/index.node.cjs +0 -1293
  39. package/dist/cjs/index.node.js.map +0 -20
  40. package/dist/index.browser.d.ts +0 -2
  41. package/dist/index.node.d.ts +0 -2
  42. package/dist/node/index.d.ts +0 -2
  43. package/dist/node/index.node.js.map +0 -20
  44. package/dist/providers/recent-messages.d.ts +0 -15
package/package.json CHANGED
@@ -1,70 +1,67 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-memory",
3
- "version": "1.1.1",
4
- "description": "Advanced memory management plugin with short-term summarization and long-term persistent memory",
5
- "type": "module",
6
- "main": "dist/cjs/index.node.cjs",
7
- "module": "dist/node/index.node.js",
3
+ "version": "2.0.0-alpha",
4
+ "description": "Memory management plugin for ElizaOS (TypeScript)",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
8
7
  "types": "dist/index.d.ts",
9
- "browser": "dist/browser/index.browser.js",
10
- "sideEffects": false,
8
+ "type": "module",
11
9
  "exports": {
12
10
  "./package.json": "./package.json",
13
11
  ".": {
14
- "types": "./dist/index.d.ts",
15
- "browser": {
16
- "types": "./dist/browser/index.d.ts",
17
- "import": "./dist/browser/index.browser.js",
18
- "default": "./dist/browser/index.browser.js"
19
- },
20
- "node": {
21
- "types": "./dist/node/index.d.ts",
22
- "import": "./dist/node/index.node.js",
23
- "require": "./dist/cjs/index.node.cjs",
24
- "default": "./dist/node/index.node.js"
25
- },
26
- "default": "./dist/node/index.node.js"
27
- },
28
- "./node": {
29
- "types": "./dist/node/index.d.ts",
30
- "import": "./dist/node/index.node.js",
31
- "default": "./dist/node/index.node.js"
32
- },
33
- "./browser": {
34
- "types": "./dist/browser/index.d.ts",
35
- "import": "./dist/browser/index.browser.js",
36
- "default": "./dist/browser/index.browser.js"
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
37
16
  }
38
17
  },
39
18
  "files": [
40
19
  "dist"
41
20
  ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
42
24
  "scripts": {
25
+ "dev": "bun --hot build.ts",
26
+ "test": "vitest",
27
+ "test:watch": "vitest --watch",
28
+ "lint": "bunx @biomejs/biome check --write --unsafe .",
29
+ "format": "bunx @biomejs/biome format --write .",
30
+ "format:check": "bunx @biomejs/biome format .",
31
+ "clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo",
32
+ "lint:check": "bunx @biomejs/biome check .",
43
33
  "build": "bun run build.ts",
44
- "dev": "bun run build --watch",
45
- "test": "bun test",
46
- "lint": "eslint . --ext .ts",
47
- "format": "prettier --write \"src/**/*.ts\""
48
- },
49
- "dependencies": {
50
- "@elizaos/core": "latest",
51
- "drizzle-orm": "^0.45.0"
34
+ "build:ts": "bun run build.ts",
35
+ "typecheck": "tsc --noEmit"
52
36
  },
53
- "devDependencies": {
54
- "@types/bun": "latest",
55
- "typescript": "^5.7.2"
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/elizaos/eliza.git"
56
40
  },
57
41
  "keywords": [
58
- "eliza",
42
+ "elizaos",
59
43
  "plugin",
60
44
  "memory",
61
- "long-term-memory",
62
- "short-term-memory",
63
- "summarization"
45
+ "typescript",
46
+ "knowledge-management"
64
47
  ],
65
- "author": "ElizaOS Team",
48
+ "author": "ElizaOS Contributors",
66
49
  "license": "MIT",
67
- "publishConfig": {
68
- "access": "public"
50
+ "bugs": {
51
+ "url": "https://github.com/elizaos/eliza/issues"
52
+ },
53
+ "homepage": "https://github.com/elizaos/eliza#readme",
54
+ "dependencies": {
55
+ "@elizaos/core": "workspace:*"
56
+ },
57
+ "devDependencies": {
58
+ "@types/node": "^25.0.3",
59
+ "typescript": "^5.9.3",
60
+ "vitest": "^4.0.0",
61
+ "@biomejs/biome": "^2.3.11"
62
+ },
63
+ "agentConfig": {
64
+ "pluginType": "elizaos:plugin:1.0.0",
65
+ "pluginParameters": {}
69
66
  }
70
67
  }
package/README.md DELETED
@@ -1,335 +0,0 @@
1
- # @elizaos/plugin-memory
2
-
3
- Advanced memory management plugin for ElizaOS that provides intelligent conversation summarization and persistent long-term memory storage.
4
-
5
- ## Features
6
-
7
- ### 🔄 Short-term Memory (Conversation Summarization)
8
-
9
- - **Automatic Summarization**: Compresses long conversations when they exceed configurable thresholds
10
- - **Context Preservation**: Maintains conversation flow while dramatically reducing token usage
11
- - **Recent Message Retention**: Keeps the most recent messages for immediate context
12
- - **Topic Extraction**: Identifies and tracks main topics discussed in each session
13
-
14
- ### 🧠 Long-term Memory (Persistent Facts)
15
-
16
- - **Intelligent Extraction**: Automatically learns facts about users from conversations
17
- - **Cognitive Science Based**: Organizes information into 3 core memory types (episodic, semantic, procedural)
18
- - **Strict Criteria**: Only extracts truly significant, persistent information
19
- - **Confidence Scoring**: Tracks reliability of stored information
20
- - **Cross-session Persistence**: Remembers user context across all interactions
21
-
22
- ### 📊 Memory Categories (Based on Cognitive Science)
23
-
24
- The plugin uses the three fundamental types of long-term memory from cognitive science:
25
-
26
- 1. **Episodic Memory**: Personal experiences and specific events
27
- - Example: "User completed migration from MongoDB to PostgreSQL in Q2 2024"
28
- - Contains: WHO did WHAT, WHEN/WHERE
29
- - Use for: Significant project milestones, important incidents, formative experiences
30
-
31
- 2. **Semantic Memory**: General facts, concepts, and knowledge
32
- - Example: "User is a senior TypeScript developer with 8 years experience"
33
- - Contains: Factual, timeless information
34
- - Use for: Professional identity, core expertise, established facts about work context
35
-
36
- 3. **Procedural Memory**: Skills, workflows, and how-to knowledge
37
- - Example: "User follows TDD workflow: writes tests first, then implementation"
38
- - Contains: HOW user does things
39
- - Use for: Consistent workflows, methodologies, debugging processes
40
-
41
- ## Installation
42
-
43
- ```bash
44
- bun add @elizaos/plugin-memory
45
- ```
46
-
47
- ## Usage
48
-
49
- ### Basic Setup
50
-
51
- ```typescript
52
- import { memoryPlugin } from '@elizaos/plugin-memory';
53
-
54
- const agent = new Agent({
55
- name: 'MyAgent',
56
- plugins: [
57
- memoryPlugin,
58
- // ... other plugins
59
- ],
60
- });
61
- ```
62
-
63
- ### Configuration
64
-
65
- Configure the plugin via environment variables in your `.env` file:
66
-
67
- ```env
68
- # Short-term Memory Settings
69
- MEMORY_SUMMARIZATION_THRESHOLD=16 # Messages before summarization starts (default: 16)
70
- MEMORY_SUMMARIZATION_INTERVAL=10 # Update summary every N messages (default: 10)
71
- MEMORY_RETAIN_RECENT=10 # Recent messages to keep (default: 10)
72
- MEMORY_MAX_NEW_MESSAGES=20 # Max new messages in summary update (default: 20)
73
-
74
- # Long-term Memory Settings
75
- MEMORY_LONG_TERM_ENABLED=true # Enable long-term extraction (default: true)
76
- MEMORY_EXTRACTION_THRESHOLD=30 # Min messages before extraction starts (default: 30)
77
- MEMORY_EXTRACTION_INTERVAL=10 # Run extraction every N messages (default: 10)
78
- MEMORY_CONFIDENCE_THRESHOLD=0.85 # Minimum confidence to store (default: 0.85)
79
- ```
80
-
81
- ### Manual Memory Storage
82
-
83
- Users can explicitly ask the agent to remember information:
84
-
85
- ```
86
- User: "Remember that I prefer TypeScript over JavaScript"
87
- Agent: I've made a note of that in my Semantic memory: "User prefers TypeScript over JavaScript"
88
-
89
- User: "Keep in mind I'm working on a startup project"
90
- Agent: I've made a note of that in my Episodic memory: "User is working on a startup project"
91
-
92
- User: "Don't forget I always use TDD"
93
- Agent: I've made a note of that in my Procedural memory: "User follows TDD (Test-Driven Development) methodology"
94
- ```
95
-
96
- ### Accessing the Memory Service
97
-
98
- ```typescript
99
- import { MemoryService } from '@elizaos/plugin-memory';
100
-
101
- // Get the service from runtime
102
- const memoryService = runtime.getService('memory') as MemoryService;
103
-
104
- // Store a long-term memory manually
105
- await memoryService.storeLongTermMemory({
106
- agentId: runtime.agentId,
107
- entityId: userId,
108
- category: LongTermMemoryCategory.SEMANTIC,
109
- content: 'User prefers concise responses',
110
- confidence: 0.9,
111
- source: 'manual',
112
- });
113
-
114
- // Retrieve memories
115
- const memories = await memoryService.getLongTermMemories(userId);
116
-
117
- // Get session summaries
118
- const summaries = await memoryService.getSessionSummaries(roomId);
119
- ```
120
-
121
- ## Database Setup
122
-
123
- The plugin uses ElizaOS's dynamic migration system. Database tables are automatically created when the plugin is loaded. The plugin defines three tables:
124
-
125
- - **`long_term_memories`**: Stores persistent facts about users
126
- - **`session_summaries`**: Stores conversation summaries
127
- - **`memory_access_logs`**: Optional usage tracking for analytics
128
-
129
- No manual migration is required - the schema is handled automatically by the runtime.
130
-
131
- ## Architecture
132
-
133
- ### Components
134
-
135
- #### Services
136
-
137
- - **MemoryService**: Core service managing all memory operations
138
- - Tracks message counts for summarization triggers
139
- - Stores and retrieves long-term memories
140
- - Manages session summaries
141
- - Provides formatted memory context
142
-
143
- #### Evaluators
144
-
145
- - **summarizationEvaluator**: Runs after conversations reach threshold
146
- - Generates comprehensive summaries using LLM
147
- - Extracts topics and key points
148
- - Archives old messages while preserving summaries
149
- - **longTermExtractionEvaluator**: Periodically analyzes conversations
150
- - Identifies facts worth remembering long-term
151
- - Categorizes information semantically
152
- - Assigns confidence scores
153
- - Stores high-confidence memories
154
-
155
- #### Providers
156
-
157
- - **longTermMemoryProvider**: Injects persistent user facts into context
158
- - Runs early (position: 50) to establish user context
159
- - Formats memories by category
160
- - Provides "What I Know About You" context
161
- - **shortTermMemoryProvider**: Provides conversation summaries
162
- - Runs before recentMessages (position: 95)
163
- - Includes recent session summaries
164
- - Shows topics and message counts
165
-
166
- #### Actions
167
-
168
- - **rememberAction**: Handles explicit memory requests
169
- - Triggers on keywords like "remember", "keep in mind", etc.
170
- - Uses LLM to extract what to remember
171
- - Categorizes and stores with confirmation
172
-
173
- ## How It Works
174
-
175
- ### Short-term Memory Flow
176
-
177
- 1. **Tracking**: MemoryService tracks message count per room
178
- 2. **Trigger**: When count reaches threshold (default: 50), summarizationEvaluator activates
179
- 3. **Summarization**: LLM generates comprehensive summary of conversation
180
- 4. **Archival**: Older messages deleted, summary stored, recent messages retained
181
- 5. **Context Injection**: shortTermMemoryProvider injects summaries in future conversations
182
-
183
- ### Long-term Memory Flow
184
-
185
- 1. **Warm-up Period**: Extraction waits until 30+ messages (configurable) to ensure meaningful patterns
186
- 2. **Monitoring**: longTermExtractionEvaluator runs periodically (every 10 messages after threshold)
187
- 3. **Analysis**: LLM analyzes conversation for **persistent, important** facts worth remembering
188
- 4. **Strict Filtering**: Applies cognitive science principles to extract only truly significant information
189
- 5. **Storage**: High-confidence facts (≥0.85) stored in long_term_memories table
190
- 6. **Retrieval**: longTermMemoryProvider injects relevant facts in all future conversations
191
-
192
- **Ultra-Strict Extraction Criteria**: The evaluator uses stringent criteria to prevent memory pollution:
193
-
194
- - ✅ **DO Extract:**
195
- - **Episodic**: Significant milestones, important incidents, major decisions with lasting impact
196
- - **Semantic**: Professional identity, core expertise, established facts (explicitly stated or conclusively demonstrated)
197
- - **Procedural**: Consistent workflows (3+ occurrences or explicitly stated), standard practices, methodologies
198
-
199
- - ❌ **NEVER Extract:**
200
- - One-time requests or tasks
201
- - Casual conversations without lasting significance
202
- - Exploratory questions or testing
203
- - Temporary context or situational information
204
- - Preferences from single occurrence
205
- - Social pleasantries
206
- - Common patterns everyone has
207
- - General knowledge not specific to user
208
-
209
- ### Manual Memory Flow
210
-
211
- 1. **Detection**: User says "remember that..." or similar trigger phrase
212
- 2. **Validation**: rememberAction validates the request
213
- 3. **Extraction**: LLM extracts what to remember and categorizes it
214
- 4. **Storage**: Fact stored with 'manual' source and high confidence
215
- 5. **Confirmation**: Agent confirms what was stored
216
-
217
- ## Performance Optimization
218
-
219
- ### Context Reduction
220
-
221
- - Without plugin: 1000 messages = ~200,000 tokens
222
- - With plugin: 1000 messages = ~20 summaries + 10 recent = ~25,000 tokens
223
- - **Savings**: ~85% reduction in context size
224
-
225
- ### Token Efficiency
226
-
227
- - Summaries are 1/10th the size of original conversations
228
- - Long-term memories provide rich context in minimal tokens
229
- - Recent messages still available for immediate context
230
-
231
- ### Database Optimization
232
-
233
- - Indexed queries for fast retrieval
234
- - Separate tables for different memory types
235
- - Optional vector search for semantic similarity (requires pgvector)
236
-
237
- ## Best Practices
238
-
239
- ### For Users
240
-
241
- - Use explicit commands: "Remember that...", "Keep in mind...", "Don't forget..."
242
- - Provide clear, factual information for better storage
243
- - Verify important memories were stored correctly
244
-
245
- ### For Developers
246
-
247
- - Adjust thresholds based on your use case
248
- - Monitor summarization quality with test conversations
249
- - Use confidence thresholds to filter low-quality extractions
250
- - Consider enabling vector search for large-scale deployments
251
-
252
- ### Configuration Tips
253
-
254
- **Short-term Memory:**
255
- - **High-frequency chatbots**: Lower summarization threshold (10-15 messages)
256
- - **Long-form conversations**: Higher threshold (20-30 messages)
257
- - **Adjust retention**: Keep more recent messages for immediate context
258
-
259
- **Long-term Memory:**
260
- - **Conservative extraction**: Keep threshold at 30+ messages for better pattern recognition (default)
261
- - **Aggressive extraction**: Lower threshold to 20 messages if needed (may reduce quality)
262
- - **Balanced approach**: Default 0.85 confidence threshold ensures high-quality extractions
263
- - **More permissive**: Lower confidence to 0.80 for more extractions (risk of lower quality)
264
- - **Most strict**: Raise confidence to 0.90 for only the most certain facts
265
- - **Frequent updates**: Lower extraction interval to 5-8 messages for faster learning
266
- - **Conservative updates**: Keep default 10+ message interval to prevent over-extraction
267
-
268
- ## Advanced Features
269
-
270
- ### Vector Search (Optional)
271
-
272
- Enable semantic search for memories by:
273
-
274
- 1. Installing pgvector extension
275
- 2. Setting `MEMORY_VECTOR_SEARCH_ENABLED=true`
276
- 3. Generating embeddings for memories
277
-
278
- ### Memory Analytics
279
-
280
- Use the `memory_access_logs` table to:
281
-
282
- - Track which memories are most frequently accessed
283
- - Identify useful vs. unused memories
284
- - Optimize extraction strategies
285
-
286
- ### Custom Categories
287
-
288
- The plugin uses three scientifically-grounded memory types from cognitive science. If you need additional categories for domain-specific use cases, you can extend the enum:
289
-
290
- ```typescript
291
- export enum CustomMemoryCategory {
292
- ...LongTermMemoryCategory,
293
- MEDICAL_HISTORY = 'medical_history',
294
- FINANCIAL_DATA = 'financial_data',
295
- }
296
- ```
297
-
298
- **Note**: Consider carefully whether your custom category truly represents a different type of memory, or if it can be classified under episodic (events), semantic (facts), or procedural (how-to) memory.
299
-
300
- ## Testing
301
-
302
- Run the test suite:
303
-
304
- ```bash
305
- cd packages/plugin-memory
306
- bun test
307
- ```
308
-
309
- ## Troubleshooting
310
-
311
- ### Summaries not generating
312
-
313
- - Check that message threshold is reached
314
- - Verify MemoryService is registered
315
- - Check LLM provider is configured
316
-
317
- ### Long-term memories not stored
318
-
319
- - Verify `MEMORY_LONG_TERM_ENABLED=true`
320
- - Check confidence threshold isn't too high
321
- - Ensure facts are being extracted (check logs)
322
-
323
- ### High token usage
324
-
325
- - Lower summarization threshold
326
- - Reduce number of retained recent messages
327
- - Limit number of long-term memories retrieved
328
-
329
- ## License
330
-
331
- MIT
332
-
333
- ## Contributing
334
-
335
- Contributions welcome! Please see the main ElizaOS contributing guide.
@@ -1,11 +0,0 @@
1
- import { type Action } from '@elizaos/core';
2
- /**
3
- * Remember Action
4
- *
5
- * Allows users to explicitly ask the agent to remember information.
6
- * Examples:
7
- * - "Remember that I prefer Python over JavaScript"
8
- * - "Please remember I'm working on a startup project"
9
- * - "Keep in mind that I don't like verbose explanations"
10
- */
11
- export declare const rememberAction: Action;