@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.
Files changed (36) hide show
  1. package/README.md +339 -207
  2. package/dist/browser/index.browser.js +348 -151
  3. package/dist/browser/index.browser.js.map +23 -13
  4. package/dist/cjs/index.node.cjs +2200 -1047
  5. package/dist/cjs/index.node.js.map +23 -13
  6. package/dist/evaluators/consolidation.d.ts +19 -0
  7. package/dist/evaluators/summarization.d.ts +5 -24
  8. package/dist/index.d.ts +152 -30
  9. package/dist/node/index.node.js +2242 -1084
  10. package/dist/node/index.node.js.map +23 -13
  11. package/dist/prompts/consolidation.d.ts +35 -0
  12. package/dist/prompts/summarization.d.ts +25 -0
  13. package/dist/providers/action-results.d.ts +2 -0
  14. package/dist/providers/long-term-memory.d.ts +18 -11
  15. package/dist/providers/recent-conversation-summary.d.ts +2 -0
  16. package/dist/repositories/conversation-summary.d.ts +33 -0
  17. package/dist/repositories/index.d.ts +17 -0
  18. package/dist/repositories/long-term-memory.d.ts +53 -0
  19. package/dist/schemas/conversation-summaries.d.ts +494 -0
  20. package/dist/schemas/index.d.ts +16 -6
  21. package/dist/schemas/long-term-memories.d.ts +308 -70
  22. package/dist/services/memory-service.d.ts +95 -51
  23. package/dist/types/index.d.ts +299 -55
  24. package/dist/utils/db-mapping.d.ts +20 -0
  25. package/dist/utils/decay-scoring.d.ts +41 -0
  26. package/dist/utils/embedding.d.ts +21 -0
  27. package/dist/utils/formatting.d.ts +17 -0
  28. package/dist/utils/index.d.ts +17 -0
  29. package/dist/utils/search-merging.d.ts +18 -0
  30. package/dist/utils/token-counter.d.ts +53 -0
  31. package/package.json +83 -1
  32. package/dist/actions/remember.d.ts +0 -11
  33. package/dist/evaluators/long-term-extraction.d.ts +0 -8
  34. package/dist/providers/short-term-memory.d.ts +0 -19
  35. package/dist/schemas/memory-access-logs.d.ts +0 -154
  36. package/dist/schemas/session-summaries.d.ts +0 -283
@@ -1,86 +1,330 @@
1
1
  import type { UUID } from '@elizaos/core';
2
2
  /**
3
- * Categories of long-term memory
3
+ * Embedding dimension column type mapping
4
4
  */
5
- export declare enum LongTermMemoryCategory {
6
- IDENTITY = "identity",// User identity, name, roles
7
- EXPERTISE = "expertise",// Domain knowledge and familiarity
8
- PROJECTS = "projects",// Past interactions and recurring topics
9
- PREFERENCES = "preferences",// User preferences for interaction style
10
- DATA_SOURCES = "data_sources",// Frequently used files, databases, APIs
11
- GOALS = "goals",// User's broader intentions and objectives
12
- CONSTRAINTS = "constraints",// User-defined rules and limitations
13
- DEFINITIONS = "definitions",// Custom terms, acronyms, glossaries
14
- BEHAVIORAL_PATTERNS = "behavioral_patterns"
5
+ export type EmbeddingDimensionColumn = 'dim384' | 'dim512' | 'dim768' | 'dim1024' | 'dim1536' | 'dim3072';
6
+ /**
7
+ * Dimension map for dynamic embedding support
8
+ */
9
+ export declare const MEMORY_DIMENSION_MAP: Record<number, EmbeddingDimensionColumn>;
10
+ /**
11
+ * Memory Type Taxonomy (Based on Cognitive Science)
12
+ *
13
+ * Research: Section 1.1 "The Cognitive Hierarchy of Agent Memory"
14
+ * - EPISODIC: Specific events anchored in time and place (conversation logs)
15
+ * - SEMANTIC: Facts and knowledge detached from specific episodes (user preferences, identity)
16
+ * - PROCEDURAL: "How-to" knowledge and successful tool execution patterns
17
+ */
18
+ export declare enum MemoryType {
19
+ EPISODIC = "EPISODIC",
20
+ SEMANTIC = "SEMANTIC",
21
+ PROCEDURAL = "PROCEDURAL"
15
22
  }
16
23
  /**
17
- * Long-term memory entry
24
+ * Decay Function Types
25
+ *
26
+ * Research: Section 4.2 "Mathematical Model for Memory Decay"
27
+ * - EXPONENTIAL: Standard forgetting curve (Ebbinghaus)
28
+ * - LINEAR: Simple time-based decay
29
+ * - NONE: Core facts that never decay (identity, core preferences)
18
30
  */
19
- export interface LongTermMemory {
31
+ export declare enum DecayFunction {
32
+ EXPONENTIAL = "EXPONENTIAL",
33
+ LINEAR = "LINEAR",
34
+ NONE = "NONE"
35
+ }
36
+ /**
37
+ * Conversation Summary - Hierarchical Conversation Summarization
38
+ *
39
+ * Research: Section 5.1.2 "Hierarchical Conversation Summarization"
40
+ *
41
+ * This implements recursive, multi-level summarization for long conversations:
42
+ * - Level 1: Summary of 50-100 messages
43
+ * - Level 2+: Summary of lower-level summaries (recursive)
44
+ *
45
+ * Benefits:
46
+ * - 10x token compression for very long conversations
47
+ * - Maintains narrative flow without exploding context window
48
+ * - Enables efficient retrieval of past conversation context
49
+ */
50
+ export interface ConversationSummary {
51
+ /** Unique identifier */
20
52
  id: UUID;
53
+ /** Agent this summary belongs to */
21
54
  agentId: UUID;
55
+ /** Entity (user) this summary is about */
22
56
  entityId: UUID;
23
- category: LongTermMemoryCategory;
57
+ /** Room this summary belongs to */
58
+ roomId: UUID;
59
+ /**
60
+ * Hierarchical level
61
+ * - 1: Direct summarization of messages
62
+ * - 2+: Summarization of lower-level summaries
63
+ */
64
+ level: number;
65
+ /**
66
+ * Parent summary ID (for tree structure)
67
+ * - null for Level 1 (summarizes messages)
68
+ * - UUID for Level 2+ (summarizes summaries)
69
+ */
70
+ parentSummaryId?: UUID;
71
+ /** The summary content (human-readable paragraph) */
24
72
  content: string;
25
- metadata?: Record<string, unknown>;
73
+ /** Vector embedding for semantic search */
26
74
  embedding?: number[];
27
- confidence?: number;
28
- source?: string;
75
+ /** Estimated token count of this summary */
76
+ tokenCount: number;
77
+ /** Time range this summary covers */
78
+ startTime: Date;
79
+ endTime: Date;
80
+ /**
81
+ * Number of source items summarized
82
+ * - Level 1: message count
83
+ * - Level 2+: summary count
84
+ */
85
+ sourceCount: number;
86
+ /** IDs of source items (messages or summaries) */
87
+ sourceIds: UUID[];
88
+ /** When this summary was created */
29
89
  createdAt: Date;
30
- updatedAt: Date;
31
- lastAccessedAt?: Date;
32
- accessCount?: number;
33
- similarity?: number;
90
+ /** Last time this summary was accessed */
91
+ lastAccessedAt: Date | null;
92
+ /** How many times retrieved */
93
+ accessCount: number;
94
+ /** Flexible metadata (topics, sentiment, etc.) */
95
+ metadata: Record<string, unknown>;
34
96
  }
35
97
  /**
36
- * Short-term memory session summary
98
+ * Long-Term Memory Entry (The "Engram")
99
+ *
100
+ * Research: Section 4.1 "The SOTA Memory Schema"
101
+ * This interface represents a single unit of long-term memory with all necessary metadata
102
+ * for cognitive processing, including decay, confidence, and provenance tracking.
37
103
  */
38
- export interface SessionSummary {
104
+ export interface LongTermMemory {
105
+ /** Unique identifier for this memory */
39
106
  id: UUID;
107
+ /** Agent this memory belongs to */
40
108
  agentId: UUID;
41
- roomId: UUID;
42
- entityId?: UUID;
43
- summary: string;
44
- messageCount: number;
45
- lastMessageOffset: number;
46
- startTime: Date;
47
- endTime: Date;
48
- topics?: string[];
49
- metadata?: Record<string, unknown>;
50
- embedding?: number[];
109
+ /** Entity (user/agent) this memory is about */
110
+ entityId: UUID;
111
+ /** Room/context where this memory was created */
112
+ roomId?: UUID;
113
+ /** Memory taxonomy type */
114
+ type: MemoryType;
115
+ /** The actual memory content (the fact or event) */
116
+ content: string;
117
+ /**
118
+ * Contextualized content for embedding
119
+ * Research: Section 3.2.1 "Contextual Embeddings"
120
+ * Example: "[User preference regarding programming]: I prefer Python over JavaScript"
121
+ */
122
+ embeddingContext: string;
123
+ /** Vector embedding of embeddingContext */
124
+ embedding: number[];
125
+ /**
126
+ * Confidence score (0.0 to 1.0)
127
+ * Research: Section 4.1 - Track certainty of extracted facts
128
+ * - 1.0: User explicitly stated or verified
129
+ * - < 1.0: LLM inferred or uncertain
130
+ */
131
+ confidence: number;
132
+ /**
133
+ * Decay rate (lambda λ) for exponential decay
134
+ * Research: Section 4.2.2 "Implementation Strategy"
135
+ * - ~0: Core facts (name, identity) - very slow decay
136
+ * - 0.01: Mid-term facts (current projects) - fade over weeks
137
+ * - 0.5+: Transient facts (lunch plans) - fade over days
138
+ */
139
+ decayRate: number;
140
+ /** Type of decay function to use */
141
+ decayFunction: DecayFunction;
142
+ /** When this memory was created */
51
143
  createdAt: Date;
52
- updatedAt: Date;
144
+ /** When this memory was last accessed/retrieved */
145
+ lastAccessedAt: Date | null;
146
+ /**
147
+ * How many times this memory has been retrieved
148
+ * Research: Section 4.2.2 - High count = stronger memory (slower decay)
149
+ */
150
+ accessCount: number;
151
+ /**
152
+ * Soft delete flag for contradiction handling
153
+ * Research: Section 4.3 "Handling Contradictions"
154
+ * When a contradiction is found, old memory is marked inactive
155
+ */
156
+ isActive: boolean;
157
+ /**
158
+ * Provenance: Source tracking
159
+ * Research: Section 4.1 "Provenance / Lineage"
160
+ */
161
+ source: {
162
+ /** ID of the session where this was extracted */
163
+ sessionId?: string;
164
+ /** ID of the specific message that generated this fact */
165
+ messageId?: string;
166
+ /** Raw text snippet that triggered extraction */
167
+ textSnippet?: string;
168
+ /** Who provided the info (user ID or agent ID) */
169
+ authorId?: string;
170
+ /** Extraction model used (e.g., "gpt-4-turbo") */
171
+ extractionModel?: string;
172
+ };
173
+ /**
174
+ * Flexible metadata for future extensions
175
+ * Can store: tags, categories, relationships, etc.
176
+ */
177
+ metadata: Record<string, unknown>;
178
+ /**
179
+ * Optional: ID of memory this one supersedes (for contradiction resolution)
180
+ * Research: Section 4.3.1 "Resolution Strategies"
181
+ */
182
+ supersedesId?: UUID;
53
183
  }
54
184
  /**
55
- * Configuration for memory plugin
185
+ * Memory Configuration
186
+ *
187
+ * Research: Section 6 "Implementation Strategy"
188
+ * Simplified configuration focusing on key parameters
56
189
  */
57
- export interface MemoryConfig {
58
- shortTermSummarizationThreshold: number;
59
- shortTermRetainRecent: number;
60
- shortTermSummarizationInterval: number;
61
- longTermExtractionEnabled: boolean;
62
- longTermVectorSearchEnabled: boolean;
63
- longTermConfidenceThreshold: number;
64
- longTermExtractionThreshold: number;
65
- longTermExtractionInterval: number;
66
- summaryModelType?: string;
67
- summaryMaxTokens?: number;
68
- summaryMaxNewMessages?: number;
190
+ export interface LongTermMemoryConfig {
191
+ /**
192
+ * Number of messages before triggering consolidation
193
+ * Research: Section 2.3 "Consolidation Pipeline"
194
+ * Recommended: 10-20 messages
195
+ */
196
+ consolidationThreshold: number;
197
+ /**
198
+ * Minimum confidence to store a memory
199
+ * Research: Section 2.2 "Extraction Prompt Structure"
200
+ * Recommended: 0.7
201
+ */
202
+ minConfidence: number;
203
+ /**
204
+ * Enable vector search (requires embedding model)
205
+ * Research: Section 3 "RAG Strategy"
206
+ */
207
+ enableVectorSearch: boolean;
208
+ /**
209
+ * Enable BM25 keyword search
210
+ * Research: Section 3.2.1 - Combines with vector for Contextual Retrieval
211
+ */
212
+ enableBM25: boolean;
213
+ /**
214
+ * Number of memories to retrieve during RAG
215
+ * Research: Section 5.1.3 "Tier 3: Just-In-Time Injection"
216
+ */
217
+ retrievalLimit: number;
218
+ /**
219
+ * Token budget for memory context injection
220
+ * Research: Section 5.1.3 - Only highest-scoring memories within budget
221
+ */
222
+ tokenBudget: number;
223
+ /**
224
+ * Default decay rates for different memory types
225
+ * Research: Section 4.2.2 "Implementation Strategy"
226
+ */
227
+ defaultDecayRates: {
228
+ [MemoryType.EPISODIC]: number;
229
+ [MemoryType.SEMANTIC]: number;
230
+ [MemoryType.PROCEDURAL]: number;
231
+ };
232
+ /**
233
+ * Enable contradiction detection and resolution
234
+ * Research: Section 4.3 "Handling Contradictions"
235
+ */
236
+ enableContradictionDetection: boolean;
237
+ /**
238
+ * Hierarchical Summarization Configuration (GAP 3 fix)
239
+ * Research: Section 5.1.2 "Hierarchical Episodic Summarization"
240
+ */
241
+ summarization?: {
242
+ /** Enable hierarchical summarization */
243
+ enabled: boolean;
244
+ /** Number of messages before triggering Level 1 summary */
245
+ messagesPerSummary: number;
246
+ /** Number of Level N summaries before creating Level N+1 summary */
247
+ summariesPerLevel: number;
248
+ /** Maximum hierarchical depth (prevents infinite recursion) */
249
+ maxDepth: number;
250
+ /** Token budget for summary retrieval */
251
+ summaryTokenBudget: number;
252
+ };
69
253
  }
70
254
  /**
71
- * Memory extraction result from evaluator
255
+ * Extracted Long-Term Memory Result (from consolidation)
256
+ *
257
+ * Research: Section 2.2.2 "Proposed Extraction Prompt Structure"
72
258
  */
73
- export interface MemoryExtraction {
74
- category: LongTermMemoryCategory;
259
+ export interface ExtractedLongTermMemory {
260
+ /** The memory type classification */
261
+ type: MemoryType;
262
+ /** The extracted content */
75
263
  content: string;
264
+ /** Confidence score (0-1) */
76
265
  confidence: number;
266
+ /** Whether this contradicts an existing memory */
267
+ isContradiction: boolean;
268
+ /** ID of the source message */
269
+ sourceMessageId?: string;
270
+ /**
271
+ * Optional: Entity extraction for graph
272
+ * Research: Section 3.1.2 "Graph Advantages"
273
+ */
274
+ entities?: {
275
+ subject: string;
276
+ predicate: string;
277
+ object: string;
278
+ };
279
+ /** Additional metadata */
77
280
  metadata?: Record<string, unknown>;
78
281
  }
79
282
  /**
80
- * Summary generation result
283
+ * Consolidation Result
284
+ *
285
+ * Research: Section 2.2.2 "OUTPUT FORMAT"
81
286
  */
82
- export interface SummaryResult {
83
- summary: string;
84
- topics: string[];
85
- keyPoints: string[];
287
+ export interface ConsolidationResult {
288
+ /** Reasoning trace for debugging */
289
+ reasoningTrace: string;
290
+ /** Brief summary of transient events (for episodic log) */
291
+ transientSummary: string;
292
+ /** Extracted persistent long-term memories */
293
+ extractedMemories: ExtractedLongTermMemory[];
294
+ }
295
+ /**
296
+ * Long-Term Memory Retrieval Result (with decay-adjusted scoring)
297
+ *
298
+ * Research: Section 4.2 "Mathematical Model for Memory Decay"
299
+ */
300
+ export interface LongTermMemoryRetrievalResult extends LongTermMemory {
301
+ /** Relevance score (vector similarity or BM25 score) */
302
+ relevanceScore: number;
303
+ /** Time-decayed activation score */
304
+ activationScore: number;
305
+ /** Final composite score (relevance * decay * confidence) */
306
+ finalScore: number;
307
+ }
308
+ /**
309
+ * Long-Term Memory Search Query Parameters
310
+ */
311
+ export interface LongTermMemorySearchParams {
312
+ /** Entity to search memories for */
313
+ entityId: UUID;
314
+ /** Optional room context filter */
315
+ roomId?: UUID;
316
+ /** Query text */
317
+ query: string;
318
+ /** Optional memory type filter */
319
+ type?: MemoryType;
320
+ /** Maximum results to return */
321
+ limit?: number;
322
+ /** Minimum confidence threshold (default: 0.7) */
323
+ minConfidence?: number;
324
+ /** Minimum similarity threshold for vector search (default: 0.3) */
325
+ similarityThreshold?: number;
326
+ /** Whether to include inactive (superseded) memories */
327
+ includeInactive?: boolean;
328
+ /** Token budget for this retrieval (overrides config default) */
329
+ tokenBudget?: number;
86
330
  }
@@ -0,0 +1,20 @@
1
+ import { type LongTermMemory, type ConversationSummary } from '../types/index';
2
+ /**
3
+ * Database Row Mapping Utilities
4
+ *
5
+ * Maps raw database rows to strongly-typed domain objects
6
+ */
7
+ /**
8
+ * Map database row to LongTermMemory object
9
+ *
10
+ * @param row - Raw database row
11
+ * @returns Typed LongTermMemory object
12
+ */
13
+ export declare function mapDbRowToLongTermMemory(row: any): LongTermMemory;
14
+ /**
15
+ * Map database row to ConversationSummary object
16
+ *
17
+ * @param row - Raw database row
18
+ * @returns Typed ConversationSummary object
19
+ */
20
+ export declare function mapDbRowToConversationSummary(row: any): ConversationSummary;
@@ -0,0 +1,41 @@
1
+ import { DecayFunction, type LongTermMemoryRetrievalResult } from '../types/index';
2
+ /**
3
+ * Decay Scoring Utilities
4
+ *
5
+ * Research: Section 4.2 "Mathematical Model for Memory Decay"
6
+ *
7
+ * Implements exponential and linear decay functions to model natural
8
+ * forgetting curves inspired by cognitive science research (Ebbinghaus forgetting curve)
9
+ */
10
+ /**
11
+ * Calculate decay factor based on decay function type
12
+ *
13
+ * Research: Section 4.2 "Mathematical Model for Memory Decay"
14
+ * Formula: Score = Relevance * Confidence * exp(-λ * (t_now - t_last))
15
+ *
16
+ * @param decayFunction - Type of decay function (EXPONENTIAL, LINEAR, NONE)
17
+ * @param decayRate - Decay rate (lambda λ)
18
+ * @param timeDeltaDays - Time since last access in days
19
+ * @returns Decay factor (0.0 to 1.0)
20
+ */
21
+ export declare function calculateDecayFactor(decayFunction: DecayFunction, decayRate: number, timeDeltaDays: number): number;
22
+ /**
23
+ * Calculate access boost factor from access count
24
+ *
25
+ * Research: Section 4.2.2 "Reinforcement"
26
+ * More accesses = stronger memory
27
+ *
28
+ * @param accessCount - Number of times memory has been accessed
29
+ * @returns Boost factor (>= 1.0)
30
+ */
31
+ export declare function calculateAccessBoost(accessCount: number): number;
32
+ /**
33
+ * Apply decay scoring to a set of memories
34
+ *
35
+ * Research: Section 4.2 "Mathematical Model for Memory Decay"
36
+ * Calculates activation score and final score for each memory
37
+ *
38
+ * @param memories - Array of memory retrieval results
39
+ * @returns Array with decay scores applied
40
+ */
41
+ export declare function applyDecayScoring(memories: LongTermMemoryRetrievalResult[]): LongTermMemoryRetrievalResult[];
@@ -0,0 +1,21 @@
1
+ import { type IAgentRuntime } from '@elizaos/core';
2
+ /**
3
+ * Embedding Generation Utility
4
+ *
5
+ * Research: Section 3.2.1 "Contextual Embeddings"
6
+ */
7
+ /**
8
+ * Generate embedding for text using the runtime's embedding model
9
+ *
10
+ * @param runtime - Agent runtime instance
11
+ * @param text - Text to generate embedding for
12
+ * @returns Embedding vector
13
+ */
14
+ export declare function generateEmbedding(runtime: IAgentRuntime, text: string): Promise<number[]>;
15
+ /**
16
+ * Clean and normalize an embedding vector
17
+ *
18
+ * @param embedding - Raw embedding vector
19
+ * @returns Cleaned vector with finite numbers and fixed precision
20
+ */
21
+ export declare function cleanEmbedding(embedding: number[]): number[];
@@ -0,0 +1,17 @@
1
+ import { type LongTermMemoryRetrievalResult } from '../types/index';
2
+ /**
3
+ * Memory Formatting Utilities
4
+ *
5
+ * Research: Section 5.1.3 "Tier 3: Just-In-Time Injection"
6
+ * Formats memories for LLM context in a human-readable format
7
+ */
8
+ /**
9
+ * Format memories for context injection
10
+ *
11
+ * Research: Section 5.1.3 "Tier 3: Just-In-Time Injection"
12
+ * Groups by type and formats in a human-readable markdown format
13
+ *
14
+ * @param memories - Array of memories to format
15
+ * @returns Formatted string for LLM context
16
+ */
17
+ export declare function formatMemoriesForContext(memories: LongTermMemoryRetrievalResult[]): string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Utility Functions for Memory Plugin
3
+ *
4
+ * This module exports reusable utility functions for:
5
+ * - Embedding generation and cleaning
6
+ * - Decay scoring calculations
7
+ * - Search result merging
8
+ * - Memory formatting
9
+ * - Database row mapping
10
+ * - Token counting and budget enforcement
11
+ */
12
+ export * from './embedding';
13
+ export * from './decay-scoring';
14
+ export * from './search-merging';
15
+ export * from './formatting';
16
+ export * from './db-mapping';
17
+ export * from './token-counter';
@@ -0,0 +1,18 @@
1
+ import type { LongTermMemoryRetrievalResult } from '../types/index';
2
+ /**
3
+ * Search Result Merging Utilities
4
+ *
5
+ * Research: Section 3.2.1 "Contextual Retrieval"
6
+ * Combines multiple ranking methods (Vector + BM25) for superior retrieval
7
+ */
8
+ /**
9
+ * Merge vector and BM25 search results
10
+ *
11
+ * Research: Section 3.2.1 "Contextual Retrieval"
12
+ * When a memory appears in both result sets, average their scores
13
+ *
14
+ * @param vectorResults - Results from vector search
15
+ * @param bm25Results - Results from BM25 search
16
+ * @returns Merged results with combined scores
17
+ */
18
+ export declare function mergeSearchResults(vectorResults: LongTermMemoryRetrievalResult[], bm25Results: LongTermMemoryRetrievalResult[]): LongTermMemoryRetrievalResult[];
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Token Counter Utility
3
+ *
4
+ * Research: Section 5.1.3 "Token Budget Enforcement"
5
+ *
6
+ * This utility provides token counting for memory content to enforce
7
+ * token budgets during retrieval. Uses a simplified estimation based on
8
+ * GPT tokenization rules (1 token ≈ 4 characters for English text).
9
+ *
10
+ * For more precise counting, this can be replaced with a full tokenizer
11
+ * library (e.g., tiktoken), but the estimation is sufficient for budget
12
+ * enforcement in most cases.
13
+ */
14
+ /**
15
+ * Estimate token count for a given text
16
+ *
17
+ * This is a simplified heuristic that works well for most content:
18
+ * - 1 token ≈ 4 characters for English text
19
+ * - Punctuation and whitespace are included
20
+ * - Non-English text may have different ratios
21
+ *
22
+ * @param text - The text to count tokens for
23
+ * @returns Estimated token count
24
+ */
25
+ export declare function estimateTokenCount(text: string): number;
26
+ /**
27
+ * Calculate token count for multiple text segments
28
+ *
29
+ * @param texts - Array of text strings
30
+ * @returns Total estimated token count
31
+ */
32
+ export declare function estimateTokenCountForArray(texts: string[]): number;
33
+ /**
34
+ * Trim an array of items to fit within a token budget
35
+ *
36
+ * This function takes an array of items with text content and trims it
37
+ * to fit within the specified token budget. Items are assumed to be
38
+ * already sorted by priority/score (highest first).
39
+ *
40
+ * @param items - Array of items (with getText function)
41
+ * @param budget - Maximum token budget
42
+ * @param getText - Function to extract text from an item
43
+ * @param includeOverhead - Additional tokens per item (formatting overhead)
44
+ * @returns Trimmed array of items that fit within budget
45
+ */
46
+ export declare function trimToTokenBudget<T>(items: T[], budget: number, getText: (item: T) => string, includeOverhead?: number): T[];
47
+ /**
48
+ * Format token count for human-readable display
49
+ *
50
+ * @param count - Token count
51
+ * @returns Formatted string (e.g., "1.2K tokens")
52
+ */
53
+ export declare function formatTokenCount(count: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-memory",
3
- "version": "1.0.5",
3
+ "version": "2.0.1",
4
4
  "description": "Advanced memory management plugin with short-term summarization and long-term persistent memory",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.node.cjs",
@@ -66,5 +66,87 @@
66
66
  "license": "MIT",
67
67
  "publishConfig": {
68
68
  "access": "public"
69
+ },
70
+ "agentConfig": {
71
+ "pluginType": "elizaos:plugin:1.0.0",
72
+ "pluginParameters": {
73
+ "MEMORY_CONSOLIDATION_THRESHOLD": {
74
+ "type": "number",
75
+ "description": "Number of messages to buffer before triggering memory consolidation.",
76
+ "required": false,
77
+ "default": 10,
78
+ "sensitive": false
79
+ },
80
+ "MEMORY_MIN_CONFIDENCE": {
81
+ "type": "number",
82
+ "description": "Minimum confidence score (0-1) required to store extracted facts.",
83
+ "required": false,
84
+ "default": 0.7,
85
+ "sensitive": false
86
+ },
87
+ "MEMORY_ENABLE_VECTOR_SEARCH": {
88
+ "type": "boolean",
89
+ "description": "Enable semantic similarity search using embeddings.",
90
+ "required": false,
91
+ "default": true,
92
+ "sensitive": false
93
+ },
94
+ "MEMORY_ENABLE_BM25": {
95
+ "type": "boolean",
96
+ "description": "Enable keyword-based search with stemming for exact term matching.",
97
+ "required": false,
98
+ "default": true,
99
+ "sensitive": false
100
+ },
101
+ "MEMORY_RETRIEVAL_LIMIT": {
102
+ "type": "number",
103
+ "description": "Maximum number of memories to retrieve per query.",
104
+ "required": false,
105
+ "default": 5,
106
+ "sensitive": false
107
+ },
108
+ "MEMORY_TOKEN_BUDGET": {
109
+ "type": "number",
110
+ "description": "Maximum tokens to use for memory context in prompts.",
111
+ "required": false,
112
+ "default": 1000,
113
+ "sensitive": false
114
+ },
115
+ "MEMORY_SUMMARY_ENABLED": {
116
+ "type": "boolean",
117
+ "description": "Enable hierarchical conversation summarization to reduce token usage.",
118
+ "required": false,
119
+ "default": true,
120
+ "sensitive": false
121
+ },
122
+ "MEMORY_MESSAGES_PER_SUMMARY": {
123
+ "type": "number",
124
+ "description": "How many messages to include in each Level 1 summary.",
125
+ "required": false,
126
+ "default": 15,
127
+ "sensitive": false
128
+ },
129
+ "MEMORY_SUMMARIES_PER_LEVEL": {
130
+ "type": "number",
131
+ "description": "How many summaries to accumulate before creating the next level.",
132
+ "required": false,
133
+ "default": 5,
134
+ "sensitive": false
135
+ },
136
+ "MEMORY_SUMMARY_MAX_DEPTH": {
137
+ "type": "number",
138
+ "description": "Maximum depth of the summary hierarchy (1=direct summaries, 2=summaries of summaries, etc).",
139
+ "required": false,
140
+ "default": 3,
141
+ "sensitive": false
142
+ },
143
+ "MEMORY_SUMMARY_TOKEN_BUDGET": {
144
+ "type": "number",
145
+ "description": "Maximum tokens to use for conversation summaries in context.",
146
+ "required": false,
147
+ "default": 500,
148
+ "sensitive": false
149
+ }
150
+ }
69
151
  }
70
152
  }