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