@elizaos/plugin-memory 1.1.0 → 1.1.2
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 +230 -330
- package/dist/actions/remember.d.ts +11 -0
- package/dist/browser/index.browser.js +205 -348
- package/dist/browser/index.browser.js.map +13 -23
- package/dist/cjs/index.node.cjs +936 -2193
- package/dist/cjs/index.node.js.map +13 -23
- package/dist/evaluators/long-term-extraction.d.ts +8 -0
- package/dist/evaluators/summarization.d.ts +25 -6
- package/dist/index.d.ts +32 -152
- package/dist/node/index.node.js +944 -2210
- package/dist/node/index.node.js.map +13 -23
- package/dist/providers/context-summary.d.ts +12 -0
- package/dist/providers/long-term-memory.d.ts +11 -18
- package/dist/schemas/index.d.ts +6 -16
- package/dist/schemas/long-term-memories.d.ts +70 -308
- package/dist/schemas/memory-access-logs.d.ts +154 -0
- package/dist/schemas/session-summaries.d.ts +283 -0
- package/dist/services/memory-service.d.ts +51 -95
- package/dist/types/index.d.ts +53 -298
- package/package.json +2 -84
- package/dist/evaluators/consolidation.d.ts +0 -19
- package/dist/prompts/consolidation.d.ts +0 -35
- package/dist/prompts/summarization.d.ts +0 -25
- package/dist/providers/action-results.d.ts +0 -2
- package/dist/providers/recent-conversation-summary.d.ts +0 -2
- package/dist/repositories/conversation-summary.d.ts +0 -33
- package/dist/repositories/index.d.ts +0 -17
- package/dist/repositories/long-term-memory.d.ts +0 -53
- package/dist/schemas/conversation-summaries.d.ts +0 -494
- package/dist/utils/db-mapping.d.ts +0 -20
- package/dist/utils/decay-scoring.d.ts +0 -41
- package/dist/utils/embedding.d.ts +0 -21
- package/dist/utils/formatting.d.ts +0 -17
- package/dist/utils/index.d.ts +0 -17
- package/dist/utils/search-merging.d.ts +0 -18
- package/dist/utils/token-counter.d.ts +0 -53
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Evaluator } from "@elizaos/core";
|
|
2
|
+
/**
|
|
3
|
+
* Long-term Memory Extraction Evaluator
|
|
4
|
+
*
|
|
5
|
+
* Analyzes conversations to extract persistent facts about users that should be remembered
|
|
6
|
+
* across all future conversations.
|
|
7
|
+
*/
|
|
8
|
+
export declare const longTermExtractionEvaluator: Evaluator;
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import { type Evaluator } from
|
|
1
|
+
import { type Evaluator } from "@elizaos/core";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Short-term Memory Summarization Evaluator
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Automatically generates and updates conversation summaries when conversations
|
|
6
|
+
* exceed the configured threshold (default: 16 messages).
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
8
|
+
* BEHAVIOR:
|
|
9
|
+
* - Monitors message count per room
|
|
10
|
+
* - Creates initial summary when count >= threshold (e.g., 16 messages)
|
|
11
|
+
* - Updates summary at regular intervals (e.g., every 10 new messages)
|
|
12
|
+
* - Condenses existing summary with new messages to stay under token limit
|
|
13
|
+
* - Tracks offset to avoid re-processing messages
|
|
14
|
+
* - Caps new messages per update to prevent context bloat (default: 20)
|
|
15
|
+
*
|
|
16
|
+
* OPTIMIZATION:
|
|
17
|
+
* - Only triggers LLM when crossing threshold or interval boundaries
|
|
18
|
+
* - Processes only NEW messages since last update
|
|
19
|
+
* - Maintains rolling summary (fixed size, not ever-growing)
|
|
20
|
+
* - LLM is instructed to merge and condense, keeping under 2500 tokens
|
|
21
|
+
*
|
|
22
|
+
* INTEGRATION:
|
|
23
|
+
* Works with shortTermMemoryProvider which:
|
|
24
|
+
* - Shows full conversation when < threshold (no summarization needed)
|
|
25
|
+
* - Shows summaries + recent messages when >= threshold (optimized context)
|
|
26
|
+
*
|
|
27
|
+
* This creates an adaptive system that starts with full context and seamlessly
|
|
28
|
+
* transitions to efficient summarization as conversations grow.
|
|
10
29
|
*/
|
|
11
30
|
export declare const summarizationEvaluator: Evaluator;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,160 +1,40 @@
|
|
|
1
1
|
import type { Plugin } from '@elizaos/core';
|
|
2
|
-
import { longTermMemoryProvider } from './providers/long-term-memory';
|
|
3
|
-
import { recentContextProvider } from './providers/recent-conversation-summary';
|
|
4
|
-
import { actionResultsProvider } from './providers/action-results';
|
|
5
2
|
export * from './types/index';
|
|
6
3
|
export * from './schemas/index';
|
|
7
|
-
export * from './prompts/consolidation';
|
|
8
|
-
export * from './prompts/summarization';
|
|
9
|
-
export * from './utils/index';
|
|
10
|
-
export * from './repositories/index';
|
|
11
4
|
export { MemoryService } from './services/memory-service';
|
|
12
|
-
export {
|
|
5
|
+
export { contextSummaryProvider } from './providers/context-summary';
|
|
6
|
+
export { longTermMemoryProvider } from './providers/long-term-memory';
|
|
13
7
|
/**
|
|
14
|
-
* Memory Plugin
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* -
|
|
24
|
-
* -
|
|
25
|
-
* -
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
* -
|
|
31
|
-
* -
|
|
32
|
-
* -
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* -
|
|
37
|
-
* -
|
|
38
|
-
* -
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* -
|
|
43
|
-
* -
|
|
44
|
-
* - Configurable decay rates per memory type
|
|
45
|
-
*
|
|
46
|
-
* ### 5. Contextual Embeddings
|
|
47
|
-
* Research: Section 3.2.1 "Solving the Pronoun Problem"
|
|
48
|
-
* - Enriches content with context before embedding
|
|
49
|
-
* - Example: "It was terrible" → "[User movie preference]: The movie Inception was terrible"
|
|
50
|
-
* - Enables superior retrieval accuracy
|
|
51
|
-
*
|
|
52
|
-
* ### 6. Contradiction Detection & Resolution
|
|
53
|
-
* Research: Section 4.3 "Handling Contradictions"
|
|
54
|
-
* - Detects when new facts contradict existing ones
|
|
55
|
-
* - Uses soft-delete (isActive flag) to supersede old memories
|
|
56
|
-
* - Maintains provenance chain (supersedesId)
|
|
57
|
-
*
|
|
58
|
-
* ## Components
|
|
59
|
-
*
|
|
60
|
-
* - **MemoryService**: Core service managing all memory operations
|
|
61
|
-
* - **consolidationEvaluator**: Buffers messages and triggers fact extraction
|
|
62
|
-
* - **summarizationEvaluator**: Creates hierarchical conversation summaries
|
|
63
|
-
* - **longTermMemoryProvider** (LONG_TERM_MEMORY): User knowledge and facts
|
|
64
|
-
* - **recentContextProvider** (RECENT_CONVERSATION_SUMMARY): Conversational history with summaries
|
|
65
|
-
* - **actionResultsProvider** (ACTION_RESULTS): Recent action executions and tool memory
|
|
66
|
-
*
|
|
67
|
-
* ## Configuration (Environment Variables)
|
|
68
|
-
*
|
|
69
|
-
* All settings use `runtime.getSetting()` pattern:
|
|
70
|
-
*
|
|
71
|
-
* - `MEMORY_CONSOLIDATION_THRESHOLD`: Messages before consolidation (default: 12)
|
|
72
|
-
* - `MEMORY_MIN_CONFIDENCE`: Minimum confidence to store (default: 0.7)
|
|
73
|
-
* - `MEMORY_ENABLE_VECTOR_SEARCH`: Enable semantic search (default: true)
|
|
74
|
-
* - `MEMORY_ENABLE_BM25`: Enable keyword search (default: true)
|
|
75
|
-
* - `MEMORY_RETRIEVAL_LIMIT`: Max memories to retrieve (default: 5)
|
|
76
|
-
* - `MEMORY_TOKEN_BUDGET`: Token budget for memory context (default: 1000)
|
|
77
|
-
*
|
|
78
|
-
* ### Hierarchical Summarization
|
|
79
|
-
*
|
|
80
|
-
* - `MEMORY_SUMMARY_ENABLED`: Enable hierarchical summarization (default: true)
|
|
81
|
-
* - `MEMORY_MESSAGES_PER_SUMMARY`: Messages per Level 1 summary (default: 7)
|
|
82
|
-
* - `MEMORY_SUMMARIES_PER_LEVEL`: Summaries before next level (default: 5)
|
|
83
|
-
* - `MEMORY_SUMMARY_MAX_DEPTH`: Maximum hierarchy depth (default: 3)
|
|
84
|
-
* - `MEMORY_SUMMARY_TOKEN_BUDGET`: Token budget for summaries (default: 500)
|
|
85
|
-
* - `CONTEXT_OVERLAP_USER_MESSAGES`: User messages overlap after summary (default: 2)
|
|
86
|
-
*
|
|
87
|
-
* ## Database Tables
|
|
88
|
-
*
|
|
89
|
-
* - `long_term_memories`: Unified storage for all memory types
|
|
90
|
-
* - `conversation_summaries`: Hierarchical conversation summaries
|
|
91
|
-
*
|
|
92
|
-
* ## Design Decisions
|
|
93
|
-
*
|
|
94
|
-
* ### Why Single Unified Table?
|
|
95
|
-
* Research: Section 4.1 "Data Structure & Schema"
|
|
96
|
-
* - Easier cross-type queries
|
|
97
|
-
* - Unified retrieval logic
|
|
98
|
-
* - Flexible type reassignment (episodic can become semantic over time)
|
|
99
|
-
* - Simpler codebase
|
|
100
|
-
*
|
|
101
|
-
* ### Why Async Consolidation?
|
|
102
|
-
* Research: Section 2.3 "Consolidation Pipeline"
|
|
103
|
-
* - Doesn't block conversation flow
|
|
104
|
-
* - Allows for deeper analysis without latency
|
|
105
|
-
* - Mirrors biological "sleep" consolidation
|
|
106
|
-
*
|
|
107
|
-
* ### Why Contextual Embeddings?
|
|
108
|
-
* Research: Section 3.2.1 "Contextual Retrieval"
|
|
109
|
-
* - Solves pronoun ambiguity ("it", "that")
|
|
110
|
-
* - Improves retrieval accuracy by 49% (Anthropic research)
|
|
111
|
-
* - Self-contained memory chunks
|
|
112
|
-
*
|
|
113
|
-
* ## Usage Examples
|
|
114
|
-
*
|
|
115
|
-
* ### Accessing the Service
|
|
116
|
-
* ```typescript
|
|
117
|
-
* const memoryService = runtime.getService<MemoryService>('memory');
|
|
118
|
-
* ```
|
|
119
|
-
*
|
|
120
|
-
* ### Searching Memories
|
|
121
|
-
* ```typescript
|
|
122
|
-
* const memories = await memoryService.searchLongTermMemories({
|
|
123
|
-
* entityId: userId,
|
|
124
|
-
* query: "What does the user like?",
|
|
125
|
-
* type: MemoryType.SEMANTIC,
|
|
126
|
-
* limit: 5
|
|
127
|
-
* });
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* ### Storing a Memory Manually
|
|
131
|
-
* ```typescript
|
|
132
|
-
* await memoryService.storeLongTermMemory({
|
|
133
|
-
* agentId: runtime.agentId,
|
|
134
|
-
* entityId: userId,
|
|
135
|
-
* type: MemoryType.SEMANTIC,
|
|
136
|
-
* content: "User is allergic to peanuts",
|
|
137
|
-
* embeddingContext: "[User health information]: User is allergic to peanuts",
|
|
138
|
-
* confidence: 1.0,
|
|
139
|
-
* decayRate: 0.0, // Core fact, never decays
|
|
140
|
-
* decayFunction: DecayFunction.NONE,
|
|
141
|
-
* source: { authorId: userId },
|
|
142
|
-
* metadata: { category: "health" }
|
|
143
|
-
* });
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* ## Research References
|
|
147
|
-
*
|
|
148
|
-
* This implementation is based on the comprehensive research document (refactor.md)
|
|
149
|
-
* which analyzed 40+ academic papers and industry implementations to identify
|
|
150
|
-
* state-of-the-art techniques for agentic memory systems.
|
|
151
|
-
*
|
|
152
|
-
* Key research areas:
|
|
153
|
-
* - Cognitive science (memory hierarchies, consolidation)
|
|
154
|
-
* - RAG optimization (vector search, BM25, contextual retrieval)
|
|
155
|
-
* - Forgetting curves (Ebbinghaus, exponential decay)
|
|
156
|
-
* - LLM prompting (Chain-of-Thought, extraction patterns)
|
|
157
|
-
*
|
|
8
|
+
* Memory Plugin
|
|
9
|
+
*
|
|
10
|
+
* Advanced memory management plugin that provides:
|
|
11
|
+
*
|
|
12
|
+
* **Short-term Memory (Conversation Summarization)**:
|
|
13
|
+
* - Automatically summarizes long conversations to reduce context size
|
|
14
|
+
* - Retains recent messages while archiving older ones as summaries
|
|
15
|
+
* - Configurable thresholds for when to summarize
|
|
16
|
+
*
|
|
17
|
+
* **Long-term Memory (Persistent Facts)**:
|
|
18
|
+
* - Extracts and stores persistent facts about users
|
|
19
|
+
* - Categorizes information (identity, expertise, preferences, etc.)
|
|
20
|
+
* - Provides context-aware user profiles across all conversations
|
|
21
|
+
*
|
|
22
|
+
* **Components**:
|
|
23
|
+
* - `MemoryService`: Manages all memory operations
|
|
24
|
+
* - Evaluators: Process conversations to create summaries and extract facts
|
|
25
|
+
* - Providers: Inject memory context into conversations
|
|
26
|
+
* - Actions: Allow manual memory storage via user commands
|
|
27
|
+
*
|
|
28
|
+
* **Configuration** (via environment variables):
|
|
29
|
+
* - `MEMORY_SUMMARIZATION_THRESHOLD`: Messages before summarization (default: 50)
|
|
30
|
+
* - `MEMORY_RETAIN_RECENT`: Recent messages to keep (default: 10)
|
|
31
|
+
* - `MEMORY_LONG_TERM_ENABLED`: Enable long-term extraction (default: true)
|
|
32
|
+
* - `MEMORY_CONFIDENCE_THRESHOLD`: Minimum confidence to store (default: 0.7)
|
|
33
|
+
*
|
|
34
|
+
* **Database Tables**:
|
|
35
|
+
* - `long_term_memories`: Persistent user facts
|
|
36
|
+
* - `session_summaries`: Conversation summaries
|
|
37
|
+
* - `memory_access_logs`: Optional usage tracking
|
|
158
38
|
*/
|
|
159
39
|
export declare const memoryPlugin: Plugin;
|
|
160
40
|
export default memoryPlugin;
|