@elizaos/plugin-memory 1.0.5 โ 2.0.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 +339 -207
- package/dist/browser/index.browser.js +348 -151
- package/dist/browser/index.browser.js.map +23 -13
- package/dist/cjs/index.node.cjs +2200 -1047
- package/dist/cjs/index.node.js.map +23 -13
- package/dist/evaluators/consolidation.d.ts +19 -0
- package/dist/evaluators/summarization.d.ts +5 -24
- package/dist/index.d.ts +152 -30
- package/dist/node/index.node.js +2242 -1084
- package/dist/node/index.node.js.map +23 -13
- package/dist/prompts/consolidation.d.ts +35 -0
- package/dist/prompts/summarization.d.ts +25 -0
- package/dist/providers/action-results.d.ts +2 -0
- package/dist/providers/long-term-memory.d.ts +18 -11
- package/dist/providers/recent-conversation-summary.d.ts +2 -0
- package/dist/repositories/conversation-summary.d.ts +33 -0
- package/dist/repositories/index.d.ts +17 -0
- package/dist/repositories/long-term-memory.d.ts +53 -0
- package/dist/schemas/conversation-summaries.d.ts +494 -0
- package/dist/schemas/index.d.ts +16 -6
- package/dist/schemas/long-term-memories.d.ts +308 -70
- package/dist/services/memory-service.d.ts +95 -51
- package/dist/types/index.d.ts +299 -55
- package/dist/utils/db-mapping.d.ts +20 -0
- package/dist/utils/decay-scoring.d.ts +41 -0
- package/dist/utils/embedding.d.ts +21 -0
- package/dist/utils/formatting.d.ts +17 -0
- package/dist/utils/index.d.ts +17 -0
- package/dist/utils/search-merging.d.ts +18 -0
- package/dist/utils/token-counter.d.ts +53 -0
- package/package.json +83 -1
- package/dist/actions/remember.d.ts +0 -11
- package/dist/evaluators/long-term-extraction.d.ts +0 -8
- package/dist/providers/short-term-memory.d.ts +0 -19
- package/dist/schemas/memory-access-logs.d.ts +0 -154
- package/dist/schemas/session-summaries.d.ts +0 -283
package/README.md
CHANGED
|
@@ -1,311 +1,443 @@
|
|
|
1
1
|
# @elizaos/plugin-memory
|
|
2
2
|
|
|
3
|
-
Advanced memory
|
|
3
|
+
Advanced cognitive memory system for ElizaOS agents with persistent memory, intelligent fact extraction, and hybrid retrieval.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> ๐ **Research-Driven**: Built on analysis of 40+ academic papers. See [`refactor.md`](./refactor.md) and [`EVALUATION.md`](./EVALUATION.md) for details.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> โ ๏ธ **Version Notice**: Breaking schema change between v1.x and v2.x. See [MIGRATION.md](./MIGRATION.md) for details.
|
|
8
|
+
> - **v1.x**: Stable for existing production (v1.0.5)
|
|
9
|
+
> - **v2.x**: New cognitive architecture (v2.0.0+)
|
|
8
10
|
|
|
9
|
-
|
|
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
|
|
11
|
+
---
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
## Overview
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
- **Categorized Storage**: Organizes information into 9 semantic categories
|
|
18
|
-
- **Confidence Scoring**: Tracks reliability of stored information
|
|
19
|
-
- **Cross-session Persistence**: Remembers user preferences and context across all interactions
|
|
15
|
+
Transforms stateless LLM agents into persistent entities with human-like memory capabilities:
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
- **Three-Tier Memory**: Episodic (events), Semantic (facts), Procedural (skills)
|
|
18
|
+
- **Smart Consolidation**: Automatically extracts persistent facts from conversations
|
|
19
|
+
- **Hybrid Retrieval**: Vector + BM25 + Graph search with exponential decay
|
|
20
|
+
- **Contextual Embeddings**: Self-contained memories that improve retrieval accuracy
|
|
21
|
+
- **Contradiction Detection**: Automatically handles conflicting information
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
2. **Expertise**: Domain knowledge, skills, familiarity with topics
|
|
25
|
-
3. **Projects**: Ongoing work, past interactions, recurring topics
|
|
26
|
-
4. **Preferences**: Communication style, format preferences, verbosity
|
|
27
|
-
5. **Data Sources**: Frequently used files, databases, APIs
|
|
28
|
-
6. **Goals**: Broader intentions and objectives
|
|
29
|
-
7. **Constraints**: User-defined rules or limitations
|
|
30
|
-
8. **Definitions**: Custom terms, acronyms, glossaries
|
|
31
|
-
9. **Behavioral Patterns**: Interaction styles and tendencies
|
|
23
|
+
---
|
|
32
24
|
|
|
33
25
|
## Installation
|
|
34
26
|
|
|
35
27
|
```bash
|
|
28
|
+
# For new projects (v2.x - latest)
|
|
36
29
|
bun add @elizaos/plugin-memory
|
|
37
|
-
```
|
|
38
30
|
|
|
39
|
-
|
|
31
|
+
# For existing production (v1.x - stable)
|
|
32
|
+
bun add @elizaos/plugin-memory@^1.0.5
|
|
33
|
+
```
|
|
40
34
|
|
|
41
|
-
|
|
35
|
+
Add to your character file:
|
|
42
36
|
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
name: 'MyAgent',
|
|
48
|
-
plugins: [
|
|
49
|
-
memoryPlugin,
|
|
50
|
-
// ... other plugins
|
|
51
|
-
],
|
|
52
|
-
});
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"plugins": ["@elizaos/plugin-memory"]
|
|
40
|
+
}
|
|
53
41
|
```
|
|
54
42
|
|
|
55
|
-
|
|
43
|
+
The plugin auto-creates database tables on first load and handles everything automatically.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
### Quick Reference
|
|
50
|
+
|
|
51
|
+
| Setting | Default | Description |
|
|
52
|
+
| -------------------------------- | ------- | --------------------------------------- |
|
|
53
|
+
| `MEMORY_CONSOLIDATION_THRESHOLD` | `12` | Messages before fact extraction |
|
|
54
|
+
| `MEMORY_MIN_CONFIDENCE` | `0.7` | Minimum confidence to store facts (0-1) |
|
|
55
|
+
| `MEMORY_ENABLE_VECTOR_SEARCH` | `true` | Enable semantic search |
|
|
56
|
+
| `MEMORY_ENABLE_BM25` | `true` | Enable keyword search |
|
|
57
|
+
| `MEMORY_RETRIEVAL_LIMIT` | `5` | Max memories per query |
|
|
58
|
+
| `MEMORY_TOKEN_BUDGET` | `1000` | Token budget for memory context |
|
|
59
|
+
| `MEMORY_SUMMARY_ENABLED` | `true` | Enable conversation summarization |
|
|
60
|
+
| `MEMORY_MESSAGES_PER_SUMMARY` | `7` | Messages per summary |
|
|
61
|
+
| `MEMORY_SUMMARIES_PER_LEVEL` | `5` | Summaries before next level |
|
|
62
|
+
| `MEMORY_SUMMARY_MAX_DEPTH` | `3` | Maximum summary hierarchy depth |
|
|
63
|
+
| `MEMORY_SUMMARY_TOKEN_BUDGET` | `500` | Token budget for summaries |
|
|
64
|
+
| `CONTEXT_OVERLAP_USER_MESSAGES` | `2` | User messages overlap after summary |
|
|
65
|
+
|
|
66
|
+
### Configuration Methods
|
|
67
|
+
|
|
68
|
+
Settings are loaded via `runtime.getSetting()` with priority:
|
|
69
|
+
|
|
70
|
+
1. **Character `settings`** (highest priority)
|
|
71
|
+
2. **Environment variables** (`.env` file)
|
|
72
|
+
3. **Plugin defaults** (fallback)
|
|
56
73
|
|
|
57
|
-
|
|
74
|
+
#### Character File Example
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"name": "MyAgent",
|
|
79
|
+
"plugins": ["@elizaos/plugin-memory"],
|
|
80
|
+
"settings": {
|
|
81
|
+
"MEMORY_CONSOLIDATION_THRESHOLD": "15",
|
|
82
|
+
"MEMORY_MIN_CONFIDENCE": "0.8",
|
|
83
|
+
"MEMORY_RETRIEVAL_LIMIT": "10"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### `.env` File Example
|
|
58
89
|
|
|
59
90
|
```env
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
# Core Settings
|
|
92
|
+
MEMORY_CONSOLIDATION_THRESHOLD=12
|
|
93
|
+
MEMORY_MIN_CONFIDENCE=0.7
|
|
94
|
+
|
|
95
|
+
# Retrieval Settings
|
|
96
|
+
MEMORY_ENABLE_VECTOR_SEARCH=true
|
|
97
|
+
MEMORY_ENABLE_BM25=true
|
|
98
|
+
MEMORY_RETRIEVAL_LIMIT=5
|
|
99
|
+
MEMORY_TOKEN_BUDGET=1000
|
|
100
|
+
|
|
101
|
+
# Summarization Settings
|
|
102
|
+
MEMORY_SUMMARY_ENABLED=true
|
|
103
|
+
MEMORY_MESSAGES_PER_SUMMARY=7
|
|
104
|
+
MEMORY_SUMMARIES_PER_LEVEL=5
|
|
105
|
+
MEMORY_SUMMARY_MAX_DEPTH=3
|
|
106
|
+
MEMORY_SUMMARY_TOKEN_BUDGET=500
|
|
107
|
+
CONTEXT_OVERLAP_USER_MESSAGES=2
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Configuration Details
|
|
113
|
+
|
|
114
|
+
### Core Memory Settings
|
|
115
|
+
|
|
116
|
+
#### `MEMORY_CONSOLIDATION_THRESHOLD` (default: `12`)
|
|
117
|
+
|
|
118
|
+
Number of messages to buffer before triggering memory consolidation.
|
|
119
|
+
|
|
120
|
+
- **Lower** (5-8): Extract facts frequently, more LLM calls, better for fast-paced chats
|
|
121
|
+
- **Higher** (15-30): Let conversations develop, fewer LLM calls, better for long-form discussions
|
|
122
|
+
|
|
123
|
+
#### `MEMORY_MIN_CONFIDENCE` (default: `0.7`)
|
|
124
|
+
|
|
125
|
+
Minimum confidence score (0-1) to store extracted facts.
|
|
126
|
+
|
|
127
|
+
- **Higher** (0.8-0.9): Only store high-certainty facts, good for critical applications
|
|
128
|
+
- **Lower** (0.5-0.6): Capture more nuanced information, risk storing noise
|
|
129
|
+
|
|
130
|
+
### Retrieval Settings
|
|
131
|
+
|
|
132
|
+
#### `MEMORY_ENABLE_VECTOR_SEARCH` (default: `true`)
|
|
133
|
+
|
|
134
|
+
Enable semantic similarity search using embeddings. Recommended to keep enabled.
|
|
135
|
+
|
|
136
|
+
#### `MEMORY_ENABLE_BM25` (default: `true`)
|
|
137
|
+
|
|
138
|
+
Enable keyword-based search with stemming. Works best combined with vector search.
|
|
139
|
+
|
|
140
|
+
#### `MEMORY_RETRIEVAL_LIMIT` (default: `5`)
|
|
141
|
+
|
|
142
|
+
Maximum number of memories to retrieve per query.
|
|
143
|
+
|
|
144
|
+
- **Lower** (3): Faster responses, less context
|
|
145
|
+
- **Higher** (10-20): More context, uses more tokens
|
|
146
|
+
|
|
147
|
+
#### `MEMORY_TOKEN_BUDGET` (default: `1000`)
|
|
148
|
+
|
|
149
|
+
Maximum tokens for memory context in prompts. Automatically trims to fit budget.
|
|
150
|
+
|
|
151
|
+
### Summarization Settings
|
|
152
|
+
|
|
153
|
+
#### `MEMORY_SUMMARY_ENABLED` (default: `true`)
|
|
154
|
+
|
|
155
|
+
Enable hierarchical conversation summarization. Reduces token usage for long conversations.
|
|
156
|
+
|
|
157
|
+
#### `MEMORY_MESSAGES_PER_SUMMARY` (default: `7`)
|
|
158
|
+
|
|
159
|
+
How many messages to include in each Level 1 summary.
|
|
160
|
+
|
|
161
|
+
- **Lower** (5): More granular summaries
|
|
162
|
+
- **Higher** (15-20): Broader summaries
|
|
163
|
+
|
|
164
|
+
#### `MEMORY_SUMMARIES_PER_LEVEL` (default: `5`)
|
|
165
|
+
|
|
166
|
+
How many summaries to accumulate before creating the next level.
|
|
167
|
+
|
|
168
|
+
- Example: 5 Level-1 summaries โ 1 Level-2 summary
|
|
169
|
+
|
|
170
|
+
#### `MEMORY_SUMMARY_MAX_DEPTH` (default: `3`)
|
|
171
|
+
|
|
172
|
+
Maximum depth of the summary hierarchy.
|
|
173
|
+
|
|
174
|
+
- Level 1: Direct message summaries
|
|
175
|
+
- Level 2: Summaries of summaries
|
|
176
|
+
- Level 3+: Higher-level abstractions
|
|
177
|
+
|
|
178
|
+
#### `MEMORY_SUMMARY_TOKEN_BUDGET` (default: `500`)
|
|
179
|
+
|
|
180
|
+
Maximum tokens for conversation summaries in context.
|
|
181
|
+
|
|
182
|
+
#### `CONTEXT_OVERLAP_USER_MESSAGES` (default: `2`)
|
|
183
|
+
|
|
184
|
+
Number of user messages to show as overlap after summarization for conversation continuity.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Configuration Presets
|
|
189
|
+
|
|
190
|
+
### High-Frequency Chatbot
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
{
|
|
194
|
+
"MEMORY_CONSOLIDATION_THRESHOLD": "8",
|
|
195
|
+
"MEMORY_MIN_CONFIDENCE": "0.8",
|
|
196
|
+
"MEMORY_RETRIEVAL_LIMIT": "3",
|
|
197
|
+
"MEMORY_MESSAGES_PER_SUMMARY": "5"
|
|
198
|
+
}
|
|
71
199
|
```
|
|
72
200
|
|
|
73
|
-
|
|
201
|
+
**Why**: Fast extraction, high-quality facts only, minimal context for speed.
|
|
74
202
|
|
|
75
|
-
|
|
203
|
+
### Long-Form Conversations (Therapy, Coaching, Research)
|
|
76
204
|
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"MEMORY_CONSOLIDATION_THRESHOLD": "20",
|
|
208
|
+
"MEMORY_MIN_CONFIDENCE": "0.6",
|
|
209
|
+
"MEMORY_RETRIEVAL_LIMIT": "10",
|
|
210
|
+
"MEMORY_TOKEN_BUDGET": "2000"
|
|
211
|
+
}
|
|
77
212
|
```
|
|
78
|
-
User: "Remember that I prefer TypeScript over JavaScript"
|
|
79
|
-
Agent: I've made a note of that in my Preferences memory: "User prefers TypeScript over JavaScript"
|
|
80
213
|
|
|
81
|
-
|
|
82
|
-
|
|
214
|
+
**Why**: Natural conversation flow, capture nuanced details, rich context.
|
|
215
|
+
|
|
216
|
+
### Critical Applications (Medical, Legal, Financial)
|
|
83
217
|
|
|
84
|
-
|
|
85
|
-
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"MEMORY_MIN_CONFIDENCE": "0.9",
|
|
221
|
+
"MEMORY_ENABLE_BM25": "true",
|
|
222
|
+
"MEMORY_ENABLE_VECTOR_SEARCH": "true"
|
|
223
|
+
}
|
|
86
224
|
```
|
|
87
225
|
|
|
88
|
-
|
|
226
|
+
**Why**: Only store very certain facts, use both keyword and semantic matching.
|
|
89
227
|
|
|
90
|
-
|
|
91
|
-
import { MemoryService } from '@elizaos/plugin-memory';
|
|
228
|
+
---
|
|
92
229
|
|
|
93
|
-
|
|
94
|
-
const memoryService = runtime.getService('memory') as MemoryService;
|
|
230
|
+
## Basic Usage
|
|
95
231
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
entityId: userId,
|
|
100
|
-
category: LongTermMemoryCategory.PREFERENCES,
|
|
101
|
-
content: 'User prefers concise responses',
|
|
102
|
-
confidence: 0.9,
|
|
103
|
-
source: 'manual',
|
|
104
|
-
});
|
|
232
|
+
The plugin works automatically once installed. No code changes required.
|
|
233
|
+
|
|
234
|
+
### How It Works
|
|
105
235
|
|
|
106
|
-
|
|
107
|
-
|
|
236
|
+
1. **Conversation**: Agent buffers messages
|
|
237
|
+
2. **Consolidation**: After threshold (default 12), LLM extracts persistent facts
|
|
238
|
+
3. **Storage**: Facts stored with confidence โฅ 0.7 (configurable)
|
|
239
|
+
4. **Retrieval**: Hybrid search (vector + BM25) with decay scoring
|
|
240
|
+
5. **Context**: Relevant memories added to prompts automatically
|
|
108
241
|
|
|
109
|
-
|
|
110
|
-
|
|
242
|
+
### Example Flow
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
User: "I'm a software engineer working on React. I prefer TypeScript."
|
|
246
|
+
โ [12 messages later, consolidation triggers]
|
|
247
|
+
โ Extracted: "User is a software engineer" (confidence: 0.95)
|
|
248
|
+
โ Extracted: "User works with React" (confidence: 0.92)
|
|
249
|
+
โ Extracted: "User prefers TypeScript" (confidence: 0.95)
|
|
250
|
+
|
|
251
|
+
User: "What's the best state management for my project?"
|
|
252
|
+
โ Retrieves: React + TypeScript preferences
|
|
253
|
+
โ Agent: "For React with TypeScript, I'd recommend Zustand or..."
|
|
111
254
|
```
|
|
112
255
|
|
|
113
|
-
|
|
256
|
+
---
|
|
114
257
|
|
|
115
|
-
|
|
258
|
+
## Programmatic Access
|
|
116
259
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
- **`memory_access_logs`**: Optional usage tracking for analytics
|
|
260
|
+
```typescript
|
|
261
|
+
import { MemoryService, MemoryType, DecayFunction } from '@elizaos/plugin-memory';
|
|
120
262
|
|
|
121
|
-
|
|
263
|
+
// Get service
|
|
264
|
+
const memoryService = runtime.getService<MemoryService>('memory');
|
|
122
265
|
|
|
123
|
-
|
|
266
|
+
// Store memory manually
|
|
267
|
+
await memoryService.storeLongTermMemory({
|
|
268
|
+
agentId: runtime.agentId,
|
|
269
|
+
entityId: userId,
|
|
270
|
+
roomId: roomId,
|
|
271
|
+
type: MemoryType.SEMANTIC,
|
|
272
|
+
content: 'User is allergic to peanuts',
|
|
273
|
+
embeddingContext: '[Health fact]: User is allergic to peanuts',
|
|
274
|
+
confidence: 1.0,
|
|
275
|
+
decayRate: 0.0, // Never decays
|
|
276
|
+
decayFunction: DecayFunction.NONE,
|
|
277
|
+
source: { authorId: userId },
|
|
278
|
+
metadata: { category: 'health', critical: true },
|
|
279
|
+
});
|
|
124
280
|
|
|
125
|
-
|
|
281
|
+
// Search memories
|
|
282
|
+
const memories = await memoryService.searchLongTermMemories({
|
|
283
|
+
entityId: userId,
|
|
284
|
+
query: 'What foods should I avoid?',
|
|
285
|
+
type: MemoryType.SEMANTIC,
|
|
286
|
+
limit: 5,
|
|
287
|
+
minConfidence: 0.7,
|
|
288
|
+
});
|
|
126
289
|
|
|
127
|
-
|
|
290
|
+
// Get all memories by type
|
|
291
|
+
const facts = await memoryService.getLongTermMemories(userId, MemoryType.SEMANTIC, 20);
|
|
292
|
+
```
|
|
128
293
|
|
|
129
|
-
|
|
130
|
-
- Tracks message counts for summarization triggers
|
|
131
|
-
- Stores and retrieves long-term memories
|
|
132
|
-
- Manages session summaries
|
|
133
|
-
- Provides formatted memory context
|
|
294
|
+
---
|
|
134
295
|
|
|
135
|
-
|
|
296
|
+
## Troubleshooting
|
|
136
297
|
|
|
137
|
-
|
|
138
|
-
- Generates comprehensive summaries using LLM
|
|
139
|
-
- Extracts topics and key points
|
|
140
|
-
- Archives old messages while preserving summaries
|
|
141
|
-
- **longTermExtractionEvaluator**: Periodically analyzes conversations
|
|
142
|
-
- Identifies facts worth remembering long-term
|
|
143
|
-
- Categorizes information semantically
|
|
144
|
-
- Assigns confidence scores
|
|
145
|
-
- Stores high-confidence memories
|
|
298
|
+
### No memories being extracted
|
|
146
299
|
|
|
147
|
-
|
|
300
|
+
**Check**:
|
|
148
301
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
- Provides "What I Know About You" context
|
|
153
|
-
- **shortTermMemoryProvider**: Provides conversation summaries
|
|
154
|
-
- Runs before recentMessages (position: 95)
|
|
155
|
-
- Includes recent session summaries
|
|
156
|
-
- Shows topics and message counts
|
|
302
|
+
1. Has threshold been reached? (default: 12 messages)
|
|
303
|
+
2. Is LLM provider configured?
|
|
304
|
+
3. Check logs: `grep "consolidation" agent.log`
|
|
157
305
|
|
|
158
|
-
|
|
306
|
+
**Debug**:
|
|
159
307
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
308
|
+
```typescript
|
|
309
|
+
const memoryService = runtime.getService<MemoryService>('memory');
|
|
310
|
+
console.log('Config:', memoryService.getConfig());
|
|
311
|
+
```
|
|
164
312
|
|
|
165
|
-
|
|
313
|
+
### Agent doesn't remember facts
|
|
166
314
|
|
|
167
|
-
|
|
315
|
+
**Check**:
|
|
168
316
|
|
|
169
|
-
1.
|
|
170
|
-
2.
|
|
171
|
-
3.
|
|
172
|
-
4. **Archival**: Older messages deleted, summary stored, recent messages retained
|
|
173
|
-
5. **Context Injection**: shortTermMemoryProvider injects summaries in future conversations
|
|
317
|
+
1. Database: `SELECT * FROM long_term_memories WHERE isActive = true;`
|
|
318
|
+
2. Confidence: `WHERE confidence >= 0.7`
|
|
319
|
+
3. Decay scores (old memories may have decayed)
|
|
174
320
|
|
|
175
|
-
|
|
321
|
+
**Debug**:
|
|
176
322
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
5. **Storage**: High-confidence facts stored in long_term_memories table
|
|
182
|
-
6. **Retrieval**: longTermMemoryProvider injects relevant facts in all future conversations
|
|
323
|
+
```typescript
|
|
324
|
+
const memories = await memoryService.getLongTermMemories(userId, undefined, 50, true);
|
|
325
|
+
console.log('Total:', memories.length, 'Active:', memories.filter((m) => m.isActive).length);
|
|
326
|
+
```
|
|
183
327
|
|
|
184
|
-
|
|
185
|
-
- โ
Extracts: Repeated patterns (3+ occurrences), explicit personal info, stated preferences
|
|
186
|
-
- โ Skips: One-time requests, casual interactions, testing behavior, temporary context
|
|
328
|
+
### High token usage
|
|
187
329
|
|
|
188
|
-
|
|
330
|
+
**Solutions**:
|
|
189
331
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
5. **Confirmation**: Agent confirms what was stored
|
|
332
|
+
- Lower `MEMORY_CONSOLIDATION_THRESHOLD` (consolidate more often)
|
|
333
|
+
- Reduce `MEMORY_RETRIEVAL_LIMIT` (fewer memories per query)
|
|
334
|
+
- Increase `MEMORY_MIN_CONFIDENCE` (only high-quality facts)
|
|
335
|
+
- Reduce `MEMORY_TOKEN_BUDGET` and `MEMORY_SUMMARY_TOKEN_BUDGET`
|
|
195
336
|
|
|
196
|
-
|
|
337
|
+
### Transient requests stored as facts
|
|
197
338
|
|
|
198
|
-
|
|
339
|
+
**Solutions**:
|
|
199
340
|
|
|
200
|
-
-
|
|
201
|
-
-
|
|
202
|
-
-
|
|
341
|
+
- Increase `MEMORY_MIN_CONFIDENCE` to 0.8+
|
|
342
|
+
- Use better LLM model (GPT-4, Claude)
|
|
343
|
+
- Customize extraction prompts in `prompts/consolidation.ts`
|
|
203
344
|
|
|
204
|
-
|
|
345
|
+
---
|
|
205
346
|
|
|
206
|
-
|
|
207
|
-
- Long-term memories provide rich context in minimal tokens
|
|
208
|
-
- Recent messages still available for immediate context
|
|
347
|
+
## Database Schema
|
|
209
348
|
|
|
210
|
-
|
|
349
|
+
Tables auto-created on first load via ElizaOS dynamic migrations:
|
|
211
350
|
|
|
212
|
-
|
|
213
|
-
- Separate tables for different memory types
|
|
214
|
-
- Optional vector search for semantic similarity (requires pgvector)
|
|
351
|
+
### `long_term_memories`
|
|
215
352
|
|
|
216
|
-
|
|
353
|
+
Stores episodic, semantic, and procedural memories with:
|
|
217
354
|
|
|
218
|
-
|
|
355
|
+
- Embeddings (pgvector)
|
|
356
|
+
- Confidence scores
|
|
357
|
+
- Decay rates
|
|
358
|
+
- Access tracking
|
|
359
|
+
- Soft deletes
|
|
219
360
|
|
|
220
|
-
|
|
221
|
-
- Provide clear, factual information for better storage
|
|
222
|
-
- Verify important memories were stored correctly
|
|
361
|
+
### `conversation_summaries`
|
|
223
362
|
|
|
224
|
-
|
|
363
|
+
Hierarchical conversation summaries with:
|
|
225
364
|
|
|
226
|
-
-
|
|
227
|
-
-
|
|
228
|
-
-
|
|
229
|
-
-
|
|
365
|
+
- Multi-level compression
|
|
366
|
+
- Time ranges
|
|
367
|
+
- Token estimates
|
|
368
|
+
- Access tracking
|
|
230
369
|
|
|
231
|
-
|
|
370
|
+
---
|
|
232
371
|
|
|
233
|
-
|
|
234
|
-
- **High-frequency chatbots**: Lower summarization threshold (10-15 messages)
|
|
235
|
-
- **Long-form conversations**: Higher threshold (20-30 messages)
|
|
236
|
-
- **Adjust retention**: Keep more recent messages for immediate context
|
|
372
|
+
## Architecture Highlights
|
|
237
373
|
|
|
238
|
-
|
|
239
|
-
- **Quick extraction**: Lower extraction threshold to 10-15 messages (may reduce quality)
|
|
240
|
-
- **Quality-focused**: Keep threshold at 20+ messages for better pattern recognition
|
|
241
|
-
- **Critical applications**: Raise confidence threshold to 0.8-0.9
|
|
242
|
-
- **Exploratory use**: Keep default 0.7 confidence threshold
|
|
243
|
-
- **Frequent updates**: Lower extraction interval to run every 3-5 messages
|
|
244
|
-
- **Conservative updates**: Raise interval to 10+ messages
|
|
374
|
+
### Memory Types
|
|
245
375
|
|
|
246
|
-
|
|
376
|
+
- **Episodic**: Time-anchored events ("User asked about X on Tuesday")
|
|
377
|
+
- **Semantic**: Timeless facts ("User is allergic to peanuts")
|
|
378
|
+
- **Procedural**: Skills and patterns ("User prefers git rebase")
|
|
247
379
|
|
|
248
|
-
###
|
|
380
|
+
### Hybrid Retrieval
|
|
249
381
|
|
|
250
|
-
|
|
382
|
+
Combines:
|
|
251
383
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
384
|
+
- **Vector Search**: Semantic similarity (pgvector HNSW index)
|
|
385
|
+
- **BM25**: Keyword matching with stemming
|
|
386
|
+
- **Decay Scoring**: `Confidence ร e^(-ฮปรt) ร (1 + log(accessCount))`
|
|
255
387
|
|
|
256
|
-
###
|
|
388
|
+
### Contextual Embeddings
|
|
257
389
|
|
|
258
|
-
|
|
390
|
+
Enriches content before embedding:
|
|
259
391
|
|
|
260
|
-
-
|
|
261
|
-
-
|
|
262
|
-
- Optimize extraction strategies
|
|
392
|
+
- Raw: "It was terrible"
|
|
393
|
+
- Enriched: "[Movie preference]: The movie Inception was terrible"
|
|
263
394
|
|
|
264
|
-
###
|
|
395
|
+
### Contradiction Detection
|
|
265
396
|
|
|
266
|
-
|
|
397
|
+
- Detects conflicting facts via LLM
|
|
398
|
+
- Soft deletes old memories (marks inactive)
|
|
399
|
+
- Maintains provenance chain via `supersedesId`
|
|
267
400
|
|
|
268
|
-
|
|
269
|
-
export enum CustomMemoryCategory {
|
|
270
|
-
...LongTermMemoryCategory,
|
|
271
|
-
MEDICAL_HISTORY = 'medical_history',
|
|
272
|
-
FINANCIAL_DATA = 'financial_data',
|
|
273
|
-
}
|
|
274
|
-
```
|
|
401
|
+
---
|
|
275
402
|
|
|
276
403
|
## Testing
|
|
277
404
|
|
|
278
|
-
Run the test suite:
|
|
279
|
-
|
|
280
405
|
```bash
|
|
281
406
|
cd packages/plugin-memory
|
|
282
407
|
bun test
|
|
283
408
|
```
|
|
284
409
|
|
|
285
|
-
|
|
410
|
+
Tests cover:
|
|
286
411
|
|
|
287
|
-
|
|
412
|
+
- XML parsing
|
|
413
|
+
- Memory consolidation
|
|
414
|
+
- Decay algorithms
|
|
415
|
+
- Contradiction detection
|
|
416
|
+
- Hybrid retrieval
|
|
288
417
|
|
|
289
|
-
|
|
290
|
-
- Verify MemoryService is registered
|
|
291
|
-
- Check LLM provider is configured
|
|
418
|
+
---
|
|
292
419
|
|
|
293
|
-
|
|
420
|
+
## Research & References
|
|
294
421
|
|
|
295
|
-
|
|
296
|
-
- Check confidence threshold isn't too high
|
|
297
|
-
- Ensure facts are being extracted (check logs)
|
|
422
|
+
Based on comprehensive research documented in [`refactor.md`](./refactor.md):
|
|
298
423
|
|
|
299
|
-
|
|
424
|
+
- **Cognitive Science**: Ebbinghaus forgetting curve, memory consolidation theory
|
|
425
|
+
- **AI/RAG Systems**: MemGPT, GraphRAG, Contextual Retrieval (Anthropic), HyDE
|
|
426
|
+
- **Agent Architecture**: A-MEM, AgentCore (AWS), MLE-Benchmark
|
|
300
427
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
428
|
+
Full analysis: [`EVALUATION.md`](./EVALUATION.md)
|
|
429
|
+
|
|
430
|
+
---
|
|
304
431
|
|
|
305
432
|
## License
|
|
306
433
|
|
|
307
434
|
MIT
|
|
308
435
|
|
|
309
|
-
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
## Support
|
|
310
439
|
|
|
311
|
-
|
|
440
|
+
- **Research**: [`refactor.md`](./refactor.md)
|
|
441
|
+
- **Evaluation**: [`EVALUATION.md`](./EVALUATION.md)
|
|
442
|
+
- **Issues**: [GitHub Issues](https://github.com/elizaOS/eliza/issues)
|
|
443
|
+
- **Discord**: [ElizaOS Community](https://discord.gg/elizaos)
|