chat-agent-toolkit 1.2.32 → 1.2.34
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/dist/research-agent.cjs.js +1 -1
- package/dist/research-agent.cjs.js.map +1 -1
- package/dist/research-agent.es.js +1 -1
- package/dist/research-agent.es.js.map +1 -1
- package/package.json +1 -1
- package/src/config/config-manager.ts +295 -295
- package/src/config/config-types.ts +65 -65
- package/src/config/environment-variables.ts +16 -16
- package/src/config/index.ts +26 -26
- package/src/config/language-models-database.ts +1434 -1434
- package/src/config/mcp-server-registry.ts +24 -24
- package/src/config/model-registry.ts +271 -271
- package/src/config/model-tester.ts +211 -211
- package/src/config/model-utils.ts +193 -193
- package/src/config/provider-ui-config.ts +196 -196
- package/src/connectors/open-connector.json +130 -130
- package/src/index.ts +26 -26
- package/src/memory/ARCHITECTURE.md +302 -302
- package/src/memory/README.md +224 -224
- package/src/memory/agent-memory-manager.ts +416 -416
- package/src/memory/example.ts +343 -343
- package/src/memory/index.ts +47 -47
- package/src/memory/mastra-integration.ts +604 -604
- package/src/memory/storage/drizzle-storage.ts +236 -236
- package/src/memory/storage/in-memory-storage.ts +551 -551
- package/src/memory/storage/storage-interface.ts +68 -68
- package/src/memory/types.ts +125 -125
- package/src/models/types.ts +4 -4
- package/src/provider-logos/01-ai.png +0 -0
- package/src/provider-logos/anthropic.png +0 -0
- package/src/provider-logos/aws-bedrock.png +0 -0
- package/src/provider-logos/aws-sagemaker.png +0 -0
- package/src/provider-logos/azure-openai-service.png +0 -0
- package/src/provider-logos/chatglm.png +0 -0
- package/src/provider-logos/cohere.png +0 -0
- package/src/provider-logos/gemini.png +0 -0
- package/src/provider-logos/groqcloud.png +0 -0
- package/src/provider-logos/huggingface.png +0 -0
- package/src/provider-logos/jina.png +0 -0
- package/src/provider-logos/localai.png +0 -0
- package/src/provider-logos/mistral-ai.png +0 -0
- package/src/provider-logos/moonshot-ai.png +0 -0
- package/src/provider-logos/ollama.png +0 -0
- package/src/provider-logos/openai.png +0 -0
- package/src/provider-logos/openllm.png +0 -0
- package/src/provider-logos/openrouter.png +0 -0
- package/src/provider-logos/replicate.png +0 -0
- package/src/provider-logos/together-ai.png +0 -0
- package/src/provider-logos/tongyi.png +0 -0
- package/src/provider-logos/xorbits-inference.png +0 -0
- package/src/provider-logos/zhipu-ai.png +0 -0
- package/src/tools/index.ts +13 -13
- package/src/tools/open-connector-mastra.ts +270 -270
- package/src/tools/open-connector-mcp.ts +170 -170
- package/src/tools/qwksearch-api-tools.ts +326 -326
- package/src/tools/search/doc-utils.ts +139 -139
- package/src/tools/search/document.ts +47 -47
- package/src/tools/search/index.ts +14 -14
- package/src/tools/search/link-summarizer.ts +112 -112
- package/src/tools/search/meta-search-types.ts +62 -62
- package/src/tools/search/metaSearchAgent.ts +465 -465
- package/src/tools/search/search-handlers.ts +97 -97
- package/src/tools/search/suggestionGeneratorAgent.ts +56 -56
- package/src/types.d.ts +137 -137
- package/src/utils/index.ts +2 -2
- package/src/utils/markdown-to-html.ts +53 -53
- package/src/utils/outputParser.ts +73 -73
package/src/memory/README.md
CHANGED
|
@@ -1,224 +1,224 @@
|
|
|
1
|
-
# Memory Module
|
|
2
|
-
|
|
3
|
-
Intelligent memory management for AI agents with persistent storage, automatic summarization, and vector-based relevance search.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
The memory system is now split into multiple files with clear separation of concerns:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
memory/
|
|
11
|
-
├── index.ts # Main entry point, exports all public APIs
|
|
12
|
-
├── types.ts # TypeScript types and constants
|
|
13
|
-
├── storage-interface.ts # Abstract storage interface
|
|
14
|
-
├── drizzle-storage.ts # Drizzle ORM implementation
|
|
15
|
-
├── simple-memory.ts # Core memory management logic
|
|
16
|
-
├── memory-agent.ts # High-level agent with LLM integration
|
|
17
|
-
├── memory.ts # Backward compatibility (deprecated)
|
|
18
|
-
└── README.md # This file
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Key Benefits
|
|
22
|
-
|
|
23
|
-
### 1. **Abstracted Database Layer**
|
|
24
|
-
The storage layer is now abstracted behind the `IMemoryStorage` interface, making it easy to:
|
|
25
|
-
- Swap database implementations (PostgreSQL, MySQL, SQLite, etc.)
|
|
26
|
-
- Mock storage for testing
|
|
27
|
-
- Add new storage backends without touching core logic
|
|
28
|
-
|
|
29
|
-
### 2. **Modular Design**
|
|
30
|
-
Each component has a single responsibility:
|
|
31
|
-
- **types.ts** - Type definitions and constants
|
|
32
|
-
- **storage-interface.ts** - Storage contract
|
|
33
|
-
- **drizzle-storage.ts** - Drizzle-specific implementation
|
|
34
|
-
- **simple-memory.ts** - Core memory management
|
|
35
|
-
- **memory-agent.ts** - Agent-level features (rate limiting, LLM integration)
|
|
36
|
-
|
|
37
|
-
### 3. **No Direct Drizzle Dependency**
|
|
38
|
-
The core `SimpleMemory` class now depends only on the `IMemoryStorage` interface, not on Drizzle directly. This means:
|
|
39
|
-
- Easier testing with mock storage
|
|
40
|
-
- Can use different ORMs or raw SQL
|
|
41
|
-
- Cleaner dependency management
|
|
42
|
-
|
|
43
|
-
## Usage
|
|
44
|
-
|
|
45
|
-
### Basic Usage (with Drizzle)
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { DrizzleMemoryStorage, SimpleMemory } from "research-agent";
|
|
49
|
-
|
|
50
|
-
// Create storage adapter
|
|
51
|
-
const storage = new DrizzleMemoryStorage(db);
|
|
52
|
-
|
|
53
|
-
// Create memory instance
|
|
54
|
-
const memory = new SimpleMemory("user-123", storage, {
|
|
55
|
-
maxMemories: 100,
|
|
56
|
-
enableVectorSearch: true,
|
|
57
|
-
enableAutoSummarization: true,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Store a fact
|
|
61
|
-
await memory.storeFact("User prefers dark mode", 8, "preference");
|
|
62
|
-
|
|
63
|
-
// Recall relevant memories
|
|
64
|
-
const memories = await memory.recallRelevantMemories("preferences", 10);
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Using the Memory Agent
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import { DrizzleMemoryStorage, MemoryAgent } from "research-agent";
|
|
71
|
-
|
|
72
|
-
const storage = new DrizzleMemoryStorage(db);
|
|
73
|
-
const agent = new MemoryAgent("user-123", storage, {
|
|
74
|
-
defaultProvider: "groq",
|
|
75
|
-
defaultModel: "mixtral-8x7b-32768",
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Chat with memory context
|
|
79
|
-
const response = await agent.chat("What do you remember about my preferences?");
|
|
80
|
-
console.log(response.content);
|
|
81
|
-
console.log(response.memoryContext);
|
|
82
|
-
|
|
83
|
-
// Manually store a fact
|
|
84
|
-
await agent.remember("User likes coffee", 7, "personal");
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Custom Storage Implementation
|
|
88
|
-
|
|
89
|
-
You can implement your own storage backend:
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
import { IMemoryStorage } from "research-agent";
|
|
93
|
-
|
|
94
|
-
class MyCustomStorage implements IMemoryStorage {
|
|
95
|
-
async insertMemory(userId, memoryType, content, importance, metadata) {
|
|
96
|
-
// Your implementation
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async findMemories(userId, query, limit, options) {
|
|
100
|
-
// Your implementation
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ... implement other methods
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const storage = new MyCustomStorage();
|
|
107
|
-
const memory = new SimpleMemory("user-123", storage);
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## Migration Guide
|
|
111
|
-
|
|
112
|
-
If you were using the old monolithic `memory.ts`:
|
|
113
|
-
|
|
114
|
-
### Before
|
|
115
|
-
```typescript
|
|
116
|
-
import { SimpleMemory, MemoryAgent } from "research-agent";
|
|
117
|
-
|
|
118
|
-
const memory = new SimpleMemory("user-123", db, options);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### After
|
|
122
|
-
```typescript
|
|
123
|
-
import { DrizzleMemoryStorage, SimpleMemory } from "research-agent";
|
|
124
|
-
|
|
125
|
-
const storage = new DrizzleMemoryStorage(db);
|
|
126
|
-
const memory = new SimpleMemory("user-123", storage, options);
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
The old `memory.ts` file still works for backward compatibility but is deprecated.
|
|
130
|
-
|
|
131
|
-
## Storage Interface
|
|
132
|
-
|
|
133
|
-
The `IMemoryStorage` interface defines these methods:
|
|
134
|
-
|
|
135
|
-
- `insertMemory()` - Insert a new memory record
|
|
136
|
-
- `findMemories()` - Search memories with filters
|
|
137
|
-
- `findSimilarMemories()` - Find similar content
|
|
138
|
-
- `updateMemory()` - Update a memory record
|
|
139
|
-
- `deleteMemory()` - Delete a memory
|
|
140
|
-
- `getMemoryById()` - Get memory by ID
|
|
141
|
-
- `batchUpdateMemories()` - Batch update multiple memories
|
|
142
|
-
|
|
143
|
-
## Features
|
|
144
|
-
|
|
145
|
-
### Core Memory Management
|
|
146
|
-
- **Message deduplication** - Prevents duplicate messages
|
|
147
|
-
- **Auto-summarization** - Extracts facts from conversations
|
|
148
|
-
- **Intelligent caching** - TTL-based cache for performance
|
|
149
|
-
- **Batch processing** - Efficient database operations
|
|
150
|
-
- **Conflict resolution** - Handles similar facts intelligently
|
|
151
|
-
|
|
152
|
-
### Memory Agent
|
|
153
|
-
- **Rate limiting** - Prevents API abuse
|
|
154
|
-
- **Multi-provider support** - Works with different LLMs
|
|
155
|
-
- **Session management** - Tracks conversation sessions
|
|
156
|
-
- **Analytics** - Monitors performance metrics
|
|
157
|
-
- **Health checks** - System status monitoring
|
|
158
|
-
|
|
159
|
-
## Configuration
|
|
160
|
-
|
|
161
|
-
### Memory Options
|
|
162
|
-
```typescript
|
|
163
|
-
{
|
|
164
|
-
maxMemories: 100, // Maximum memories to store
|
|
165
|
-
summaryThreshold: 10, // Messages before auto-summarization
|
|
166
|
-
cacheExpiry: 300000, // Cache TTL in ms (5 minutes)
|
|
167
|
-
batchSize: 5, // Batch size for processing
|
|
168
|
-
relevanceThreshold: 0.3, // Minimum relevance score
|
|
169
|
-
enableVectorSearch: true, // Enable vector-based search
|
|
170
|
-
enableAutoSummarization: true, // Enable auto-summarization
|
|
171
|
-
}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Agent Options
|
|
175
|
-
```typescript
|
|
176
|
-
{
|
|
177
|
-
memoryOptions: { /* Memory options */ },
|
|
178
|
-
defaultProvider: "groq", // Default LLM provider
|
|
179
|
-
defaultApiKey: "...", // API key
|
|
180
|
-
defaultModel: "...", // Model name
|
|
181
|
-
rateLimit: {
|
|
182
|
-
requests: 10, // Max requests per window
|
|
183
|
-
windowMs: 60000, // Rate limit window (1 minute)
|
|
184
|
-
},
|
|
185
|
-
}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
## Testing
|
|
189
|
-
|
|
190
|
-
With the abstracted storage layer, testing is much easier:
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
class MockStorage implements IMemoryStorage {
|
|
194
|
-
private memories: Map<string, MemoryRecord> = new Map();
|
|
195
|
-
|
|
196
|
-
async insertMemory(userId, memoryType, content, importance, metadata) {
|
|
197
|
-
const id = Math.random().toString();
|
|
198
|
-
this.memories.set(id, { id, userId, memoryType, content, importance, metadata });
|
|
199
|
-
return id;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ... implement other methods
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Use in tests
|
|
206
|
-
const mockStorage = new MockStorage();
|
|
207
|
-
const memory = new SimpleMemory("test-user", mockStorage);
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## Performance
|
|
211
|
-
|
|
212
|
-
- **Caching** - Reduces database queries
|
|
213
|
-
- **Batch operations** - Minimizes round trips
|
|
214
|
-
- **Query optimization** - Efficient database queries
|
|
215
|
-
- **Rate limiting** - Prevents overload
|
|
216
|
-
|
|
217
|
-
## Future Enhancements
|
|
218
|
-
|
|
219
|
-
Potential improvements:
|
|
220
|
-
- Vector search integration (embeddings API)
|
|
221
|
-
- Memory importance decay over time
|
|
222
|
-
- Cross-user memory sharing
|
|
223
|
-
- Memory export/import
|
|
224
|
-
- Advanced analytics dashboard
|
|
1
|
+
# Memory Module
|
|
2
|
+
|
|
3
|
+
Intelligent memory management for AI agents with persistent storage, automatic summarization, and vector-based relevance search.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The memory system is now split into multiple files with clear separation of concerns:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
memory/
|
|
11
|
+
├── index.ts # Main entry point, exports all public APIs
|
|
12
|
+
├── types.ts # TypeScript types and constants
|
|
13
|
+
├── storage-interface.ts # Abstract storage interface
|
|
14
|
+
├── drizzle-storage.ts # Drizzle ORM implementation
|
|
15
|
+
├── simple-memory.ts # Core memory management logic
|
|
16
|
+
├── memory-agent.ts # High-level agent with LLM integration
|
|
17
|
+
├── memory.ts # Backward compatibility (deprecated)
|
|
18
|
+
└── README.md # This file
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Key Benefits
|
|
22
|
+
|
|
23
|
+
### 1. **Abstracted Database Layer**
|
|
24
|
+
The storage layer is now abstracted behind the `IMemoryStorage` interface, making it easy to:
|
|
25
|
+
- Swap database implementations (PostgreSQL, MySQL, SQLite, etc.)
|
|
26
|
+
- Mock storage for testing
|
|
27
|
+
- Add new storage backends without touching core logic
|
|
28
|
+
|
|
29
|
+
### 2. **Modular Design**
|
|
30
|
+
Each component has a single responsibility:
|
|
31
|
+
- **types.ts** - Type definitions and constants
|
|
32
|
+
- **storage-interface.ts** - Storage contract
|
|
33
|
+
- **drizzle-storage.ts** - Drizzle-specific implementation
|
|
34
|
+
- **simple-memory.ts** - Core memory management
|
|
35
|
+
- **memory-agent.ts** - Agent-level features (rate limiting, LLM integration)
|
|
36
|
+
|
|
37
|
+
### 3. **No Direct Drizzle Dependency**
|
|
38
|
+
The core `SimpleMemory` class now depends only on the `IMemoryStorage` interface, not on Drizzle directly. This means:
|
|
39
|
+
- Easier testing with mock storage
|
|
40
|
+
- Can use different ORMs or raw SQL
|
|
41
|
+
- Cleaner dependency management
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Basic Usage (with Drizzle)
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { DrizzleMemoryStorage, SimpleMemory } from "research-agent";
|
|
49
|
+
|
|
50
|
+
// Create storage adapter
|
|
51
|
+
const storage = new DrizzleMemoryStorage(db);
|
|
52
|
+
|
|
53
|
+
// Create memory instance
|
|
54
|
+
const memory = new SimpleMemory("user-123", storage, {
|
|
55
|
+
maxMemories: 100,
|
|
56
|
+
enableVectorSearch: true,
|
|
57
|
+
enableAutoSummarization: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Store a fact
|
|
61
|
+
await memory.storeFact("User prefers dark mode", 8, "preference");
|
|
62
|
+
|
|
63
|
+
// Recall relevant memories
|
|
64
|
+
const memories = await memory.recallRelevantMemories("preferences", 10);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Using the Memory Agent
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { DrizzleMemoryStorage, MemoryAgent } from "research-agent";
|
|
71
|
+
|
|
72
|
+
const storage = new DrizzleMemoryStorage(db);
|
|
73
|
+
const agent = new MemoryAgent("user-123", storage, {
|
|
74
|
+
defaultProvider: "groq",
|
|
75
|
+
defaultModel: "mixtral-8x7b-32768",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Chat with memory context
|
|
79
|
+
const response = await agent.chat("What do you remember about my preferences?");
|
|
80
|
+
console.log(response.content);
|
|
81
|
+
console.log(response.memoryContext);
|
|
82
|
+
|
|
83
|
+
// Manually store a fact
|
|
84
|
+
await agent.remember("User likes coffee", 7, "personal");
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Custom Storage Implementation
|
|
88
|
+
|
|
89
|
+
You can implement your own storage backend:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { IMemoryStorage } from "research-agent";
|
|
93
|
+
|
|
94
|
+
class MyCustomStorage implements IMemoryStorage {
|
|
95
|
+
async insertMemory(userId, memoryType, content, importance, metadata) {
|
|
96
|
+
// Your implementation
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async findMemories(userId, query, limit, options) {
|
|
100
|
+
// Your implementation
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ... implement other methods
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const storage = new MyCustomStorage();
|
|
107
|
+
const memory = new SimpleMemory("user-123", storage);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Migration Guide
|
|
111
|
+
|
|
112
|
+
If you were using the old monolithic `memory.ts`:
|
|
113
|
+
|
|
114
|
+
### Before
|
|
115
|
+
```typescript
|
|
116
|
+
import { SimpleMemory, MemoryAgent } from "research-agent";
|
|
117
|
+
|
|
118
|
+
const memory = new SimpleMemory("user-123", db, options);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### After
|
|
122
|
+
```typescript
|
|
123
|
+
import { DrizzleMemoryStorage, SimpleMemory } from "research-agent";
|
|
124
|
+
|
|
125
|
+
const storage = new DrizzleMemoryStorage(db);
|
|
126
|
+
const memory = new SimpleMemory("user-123", storage, options);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The old `memory.ts` file still works for backward compatibility but is deprecated.
|
|
130
|
+
|
|
131
|
+
## Storage Interface
|
|
132
|
+
|
|
133
|
+
The `IMemoryStorage` interface defines these methods:
|
|
134
|
+
|
|
135
|
+
- `insertMemory()` - Insert a new memory record
|
|
136
|
+
- `findMemories()` - Search memories with filters
|
|
137
|
+
- `findSimilarMemories()` - Find similar content
|
|
138
|
+
- `updateMemory()` - Update a memory record
|
|
139
|
+
- `deleteMemory()` - Delete a memory
|
|
140
|
+
- `getMemoryById()` - Get memory by ID
|
|
141
|
+
- `batchUpdateMemories()` - Batch update multiple memories
|
|
142
|
+
|
|
143
|
+
## Features
|
|
144
|
+
|
|
145
|
+
### Core Memory Management
|
|
146
|
+
- **Message deduplication** - Prevents duplicate messages
|
|
147
|
+
- **Auto-summarization** - Extracts facts from conversations
|
|
148
|
+
- **Intelligent caching** - TTL-based cache for performance
|
|
149
|
+
- **Batch processing** - Efficient database operations
|
|
150
|
+
- **Conflict resolution** - Handles similar facts intelligently
|
|
151
|
+
|
|
152
|
+
### Memory Agent
|
|
153
|
+
- **Rate limiting** - Prevents API abuse
|
|
154
|
+
- **Multi-provider support** - Works with different LLMs
|
|
155
|
+
- **Session management** - Tracks conversation sessions
|
|
156
|
+
- **Analytics** - Monitors performance metrics
|
|
157
|
+
- **Health checks** - System status monitoring
|
|
158
|
+
|
|
159
|
+
## Configuration
|
|
160
|
+
|
|
161
|
+
### Memory Options
|
|
162
|
+
```typescript
|
|
163
|
+
{
|
|
164
|
+
maxMemories: 100, // Maximum memories to store
|
|
165
|
+
summaryThreshold: 10, // Messages before auto-summarization
|
|
166
|
+
cacheExpiry: 300000, // Cache TTL in ms (5 minutes)
|
|
167
|
+
batchSize: 5, // Batch size for processing
|
|
168
|
+
relevanceThreshold: 0.3, // Minimum relevance score
|
|
169
|
+
enableVectorSearch: true, // Enable vector-based search
|
|
170
|
+
enableAutoSummarization: true, // Enable auto-summarization
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Agent Options
|
|
175
|
+
```typescript
|
|
176
|
+
{
|
|
177
|
+
memoryOptions: { /* Memory options */ },
|
|
178
|
+
defaultProvider: "groq", // Default LLM provider
|
|
179
|
+
defaultApiKey: "...", // API key
|
|
180
|
+
defaultModel: "...", // Model name
|
|
181
|
+
rateLimit: {
|
|
182
|
+
requests: 10, // Max requests per window
|
|
183
|
+
windowMs: 60000, // Rate limit window (1 minute)
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Testing
|
|
189
|
+
|
|
190
|
+
With the abstracted storage layer, testing is much easier:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
class MockStorage implements IMemoryStorage {
|
|
194
|
+
private memories: Map<string, MemoryRecord> = new Map();
|
|
195
|
+
|
|
196
|
+
async insertMemory(userId, memoryType, content, importance, metadata) {
|
|
197
|
+
const id = Math.random().toString();
|
|
198
|
+
this.memories.set(id, { id, userId, memoryType, content, importance, metadata });
|
|
199
|
+
return id;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ... implement other methods
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Use in tests
|
|
206
|
+
const mockStorage = new MockStorage();
|
|
207
|
+
const memory = new SimpleMemory("test-user", mockStorage);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Performance
|
|
211
|
+
|
|
212
|
+
- **Caching** - Reduces database queries
|
|
213
|
+
- **Batch operations** - Minimizes round trips
|
|
214
|
+
- **Query optimization** - Efficient database queries
|
|
215
|
+
- **Rate limiting** - Prevents overload
|
|
216
|
+
|
|
217
|
+
## Future Enhancements
|
|
218
|
+
|
|
219
|
+
Potential improvements:
|
|
220
|
+
- Vector search integration (embeddings API)
|
|
221
|
+
- Memory importance decay over time
|
|
222
|
+
- Cross-user memory sharing
|
|
223
|
+
- Memory export/import
|
|
224
|
+
- Advanced analytics dashboard
|