massgen 0.1.3__py3-none-any.whl → 0.1.5__py3-none-any.whl
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.
Potentially problematic release.
This version of massgen might be problematic. Click here for more details.
- massgen/__init__.py +1 -1
- massgen/api_params_handler/_chat_completions_api_params_handler.py +4 -0
- massgen/api_params_handler/_claude_api_params_handler.py +4 -0
- massgen/api_params_handler/_gemini_api_params_handler.py +4 -0
- massgen/api_params_handler/_response_api_params_handler.py +4 -0
- massgen/backend/base_with_custom_tool_and_mcp.py +25 -5
- massgen/backend/docs/permissions_and_context_files.md +2 -2
- massgen/backend/response.py +2 -0
- massgen/chat_agent.py +340 -20
- massgen/cli.py +326 -19
- massgen/configs/README.md +92 -41
- massgen/configs/memory/gpt5mini_gemini_baseline_research_to_implementation.yaml +94 -0
- massgen/configs/memory/gpt5mini_gemini_context_window_management.yaml +187 -0
- massgen/configs/memory/gpt5mini_gemini_research_to_implementation.yaml +127 -0
- massgen/configs/memory/gpt5mini_high_reasoning_gemini.yaml +107 -0
- massgen/configs/memory/single_agent_compression_test.yaml +64 -0
- massgen/configs/tools/custom_tools/crawl4ai_example.yaml +55 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_file_generation_multi.yaml +61 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_file_generation_single.yaml +29 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_image_generation_multi.yaml +51 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_image_generation_single.yaml +33 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_speech_generation_multi.yaml +55 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_speech_generation_single.yaml +33 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_video_generation_multi.yaml +47 -0
- massgen/configs/tools/custom_tools/multimodal_tools/text_to_video_generation_single.yaml +29 -0
- massgen/configs/tools/custom_tools/multimodal_tools/understand_audio.yaml +1 -1
- massgen/configs/tools/custom_tools/multimodal_tools/understand_file.yaml +1 -1
- massgen/configs/tools/custom_tools/multimodal_tools/understand_image.yaml +1 -1
- massgen/configs/tools/custom_tools/multimodal_tools/understand_video.yaml +1 -1
- massgen/configs/tools/custom_tools/multimodal_tools/youtube_video_analysis.yaml +1 -1
- massgen/filesystem_manager/_filesystem_manager.py +1 -0
- massgen/filesystem_manager/_path_permission_manager.py +148 -0
- massgen/memory/README.md +277 -0
- massgen/memory/__init__.py +26 -0
- massgen/memory/_base.py +193 -0
- massgen/memory/_compression.py +237 -0
- massgen/memory/_context_monitor.py +211 -0
- massgen/memory/_conversation.py +255 -0
- massgen/memory/_fact_extraction_prompts.py +333 -0
- massgen/memory/_mem0_adapters.py +257 -0
- massgen/memory/_persistent.py +687 -0
- massgen/memory/docker-compose.qdrant.yml +36 -0
- massgen/memory/docs/DESIGN.md +388 -0
- massgen/memory/docs/QUICKSTART.md +409 -0
- massgen/memory/docs/SUMMARY.md +319 -0
- massgen/memory/docs/agent_use_memory.md +408 -0
- massgen/memory/docs/orchestrator_use_memory.md +586 -0
- massgen/memory/examples.py +237 -0
- massgen/message_templates.py +160 -12
- massgen/orchestrator.py +223 -7
- massgen/tests/memory/test_agent_compression.py +174 -0
- massgen/{configs/tools → tests}/memory/test_context_window_management.py +30 -30
- massgen/tests/memory/test_force_compression.py +154 -0
- massgen/tests/memory/test_simple_compression.py +147 -0
- massgen/tests/test_agent_memory.py +534 -0
- massgen/tests/test_binary_file_blocking.py +274 -0
- massgen/tests/test_case_studies.md +12 -12
- massgen/tests/test_conversation_memory.py +382 -0
- massgen/tests/test_multimodal_size_limits.py +407 -0
- massgen/tests/test_orchestrator_memory.py +620 -0
- massgen/tests/test_persistent_memory.py +435 -0
- massgen/token_manager/token_manager.py +6 -0
- massgen/tool/_manager.py +7 -2
- massgen/tool/_multimodal_tools/image_to_image_generation.py +293 -0
- massgen/tool/_multimodal_tools/text_to_file_generation.py +455 -0
- massgen/tool/_multimodal_tools/text_to_image_generation.py +222 -0
- massgen/tool/_multimodal_tools/text_to_speech_continue_generation.py +226 -0
- massgen/tool/_multimodal_tools/text_to_speech_transcription_generation.py +217 -0
- massgen/tool/_multimodal_tools/text_to_video_generation.py +223 -0
- massgen/tool/_multimodal_tools/understand_audio.py +19 -1
- massgen/tool/_multimodal_tools/understand_file.py +6 -1
- massgen/tool/_multimodal_tools/understand_image.py +112 -8
- massgen/tool/_multimodal_tools/understand_video.py +32 -5
- massgen/tool/_web_tools/crawl4ai_tool.py +718 -0
- massgen/tool/docs/multimodal_tools.md +589 -0
- massgen/tools/__init__.py +8 -0
- massgen/tools/_planning_mcp_server.py +520 -0
- massgen/tools/planning_dataclasses.py +434 -0
- {massgen-0.1.3.dist-info → massgen-0.1.5.dist-info}/METADATA +142 -82
- {massgen-0.1.3.dist-info → massgen-0.1.5.dist-info}/RECORD +84 -41
- massgen/configs/tools/custom_tools/crawl4ai_mcp_example.yaml +0 -67
- massgen/configs/tools/custom_tools/crawl4ai_multi_agent_example.yaml +0 -68
- massgen/configs/tools/memory/README.md +0 -199
- massgen/configs/tools/memory/gpt5mini_gemini_context_window_management.yaml +0 -131
- massgen/configs/tools/memory/gpt5mini_gemini_no_persistent_memory.yaml +0 -133
- massgen/configs/tools/multimodal/gpt5mini_gpt5nano_documentation_evolution.yaml +0 -97
- {massgen-0.1.3.dist-info → massgen-0.1.5.dist-info}/WHEEL +0 -0
- {massgen-0.1.3.dist-info → massgen-0.1.5.dist-info}/entry_points.txt +0 -0
- {massgen-0.1.3.dist-info → massgen-0.1.5.dist-info}/licenses/LICENSE +0 -0
- {massgen-0.1.3.dist-info → massgen-0.1.5.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
qdrant:
|
|
5
|
+
image: qdrant/qdrant:latest
|
|
6
|
+
container_name: massgen-qdrant
|
|
7
|
+
ports:
|
|
8
|
+
- "6333:6333" # HTTP API
|
|
9
|
+
- "6334:6334" # gRPC API (optional)
|
|
10
|
+
volumes:
|
|
11
|
+
- ./.massgen/qdrant_storage:/qdrant/storage
|
|
12
|
+
environment:
|
|
13
|
+
# Optional: Configure memory limits
|
|
14
|
+
- QDRANT__SERVICE__MAX_REQUEST_SIZE_MB=10
|
|
15
|
+
restart: unless-stopped
|
|
16
|
+
healthcheck:
|
|
17
|
+
test: ["CMD", "curl", "-f", "http://localhost:6333/health"]
|
|
18
|
+
interval: 10s
|
|
19
|
+
timeout: 5s
|
|
20
|
+
retries: 5
|
|
21
|
+
|
|
22
|
+
# Usage:
|
|
23
|
+
# 1. Start Qdrant server:
|
|
24
|
+
# docker-compose -f docker-compose.qdrant.yml up -d
|
|
25
|
+
#
|
|
26
|
+
# 2. Check status:
|
|
27
|
+
# docker-compose -f docker-compose.qdrant.yml ps
|
|
28
|
+
#
|
|
29
|
+
# 3. View logs:
|
|
30
|
+
# docker-compose -f docker-compose.qdrant.yml logs -f qdrant
|
|
31
|
+
#
|
|
32
|
+
# 4. Stop server:
|
|
33
|
+
# docker-compose -f docker-compose.qdrant.yml down
|
|
34
|
+
#
|
|
35
|
+
# 5. Access Qdrant dashboard:
|
|
36
|
+
# Open http://localhost:6333/dashboard in your browser
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# MassGen Memory System Design
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The MassGen memory system provides agents with both short-term conversation memory and long-term persistent memory capabilities. The design is inspired by how humans maintain working memory for immediate tasks while building long-term knowledge over time.
|
|
6
|
+
|
|
7
|
+
## Design Philosophy
|
|
8
|
+
|
|
9
|
+
1. **Layered Architecture**: Separate short-term (fast, ephemeral) from long-term (semantic, persistent) memory
|
|
10
|
+
2. **Async-First**: All operations are asynchronous for high performance
|
|
11
|
+
3. **Backend Agnostic**: Works with any MassGen-compatible LLM/embedding backend
|
|
12
|
+
4. **Dual Control**: Support both developer-controlled and agent-controlled memory management
|
|
13
|
+
5. **Serializable**: Enable session persistence and state recovery
|
|
14
|
+
|
|
15
|
+
## Architecture Diagram
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
19
|
+
│ MassGen Agent │
|
|
20
|
+
├─────────────────────────────────────────────────────────────┤
|
|
21
|
+
│ │
|
|
22
|
+
│ ┌────────────────────────┐ ┌─────────────────────────┐ │
|
|
23
|
+
│ │ ConversationMemory │ │ PersistentMemory │ │
|
|
24
|
+
│ │ (Short-term) │ │ (Long-term) │ │
|
|
25
|
+
│ ├────────────────────────┤ ├─────────────────────────┤ │
|
|
26
|
+
│ │ - Fast in-memory list │ │ - mem0 integration │ │
|
|
27
|
+
│ │ - Current conversation │ │ - Vector search │ │
|
|
28
|
+
│ │ - Temporary storage │ │ - Semantic retrieval │ │
|
|
29
|
+
│ │ - Session-scoped │ │ - Cross-session │ │
|
|
30
|
+
│ └────────────────────────┘ └─────────────────────────┘ │
|
|
31
|
+
│ │ │ │
|
|
32
|
+
│ ├──────────────┬───────────────┤ │
|
|
33
|
+
│ │ │ │ │
|
|
34
|
+
│ ┌────────▼────────┐ ┌─▼───────────┐ ┌─▼───────────────┐ │
|
|
35
|
+
│ │ Add messages │ │ Retrieve │ │ State mgmt │ │
|
|
36
|
+
│ │ Get messages │ │ context │ │ Save/Load │ │
|
|
37
|
+
│ │ Filter by role │ │ memories │ │ Serialize │ │
|
|
38
|
+
│ │ Truncate size │ │ Search │ │ Persist │ │
|
|
39
|
+
│ └─────────────────┘ └─────────────┘ └─────────────────┘ │
|
|
40
|
+
└─────────────────────────────────────────────────────────────┘
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Module Structure
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
massgen/memory/
|
|
47
|
+
├── __init__.py # Public exports
|
|
48
|
+
├── _base.py # Abstract base classes
|
|
49
|
+
├── _conversation.py # Short-term memory implementation
|
|
50
|
+
├── _persistent.py # Long-term memory (mem0-based)
|
|
51
|
+
├── _mem0_adapters.py # Adapters for MassGen backends
|
|
52
|
+
├── README.md # User documentation
|
|
53
|
+
├── DESIGN.md # This file
|
|
54
|
+
└── examples.py # Usage examples
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Component Details
|
|
58
|
+
|
|
59
|
+
### 1. Base Classes (`_base.py`)
|
|
60
|
+
|
|
61
|
+
#### MemoryBase
|
|
62
|
+
Abstract interface for all memory types:
|
|
63
|
+
- `add()`: Store new items
|
|
64
|
+
- `delete()`: Remove items
|
|
65
|
+
- `retrieve()`: Query items
|
|
66
|
+
- `size()`: Get item count
|
|
67
|
+
- `clear()`: Remove all items
|
|
68
|
+
- `get_messages()`: Get formatted messages
|
|
69
|
+
- `state_dict()`: Serialize state
|
|
70
|
+
- `load_state_dict()`: Restore state
|
|
71
|
+
|
|
72
|
+
#### PersistentMemoryBase
|
|
73
|
+
Abstract interface for long-term memory:
|
|
74
|
+
- **Developer Interface**:
|
|
75
|
+
- `record()`: Automatically save conversations
|
|
76
|
+
- `retrieve()`: Automatically inject relevant context
|
|
77
|
+
- **Agent Interface** (Tools):
|
|
78
|
+
- `save_to_memory()`: Agent explicitly saves info
|
|
79
|
+
- `recall_from_memory()`: Agent queries memory
|
|
80
|
+
|
|
81
|
+
### 2. Conversation Memory (`_conversation.py`)
|
|
82
|
+
|
|
83
|
+
**Purpose**: Fast, in-memory storage for active conversations
|
|
84
|
+
|
|
85
|
+
**Key Features**:
|
|
86
|
+
- List-based storage for O(1) append
|
|
87
|
+
- Message ID generation for duplicate detection
|
|
88
|
+
- Index-based deletion
|
|
89
|
+
- Role-based filtering
|
|
90
|
+
- Size truncation
|
|
91
|
+
- State serialization
|
|
92
|
+
|
|
93
|
+
**Use Cases**:
|
|
94
|
+
- Maintaining chat history during a session
|
|
95
|
+
- Providing context window for LLM
|
|
96
|
+
- Temporary storage before persistence
|
|
97
|
+
- Quick message retrieval
|
|
98
|
+
|
|
99
|
+
**Memory Management**:
|
|
100
|
+
```python
|
|
101
|
+
# Automatic ID assignment
|
|
102
|
+
msg = {"role": "user", "content": "Hello"}
|
|
103
|
+
await memory.add(msg) # ID auto-generated
|
|
104
|
+
|
|
105
|
+
# Duplicate prevention
|
|
106
|
+
await memory.add(same_msg) # Skipped if allow_duplicates=False
|
|
107
|
+
|
|
108
|
+
# Size management
|
|
109
|
+
await memory.truncate_to_size(100) # Keep last 100 messages
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 3. Persistent Memory (`_persistent.py`)
|
|
113
|
+
|
|
114
|
+
**Purpose**: Long-term semantic storage using mem0
|
|
115
|
+
|
|
116
|
+
**Key Features**:
|
|
117
|
+
- Vector-based semantic search
|
|
118
|
+
- Persistent storage across sessions
|
|
119
|
+
- Metadata-based organization (agent/user/session)
|
|
120
|
+
- Automatic summarization via mem0
|
|
121
|
+
- Dual control modes (developer + agent)
|
|
122
|
+
|
|
123
|
+
**Architecture**:
|
|
124
|
+
```
|
|
125
|
+
PersistentMemory
|
|
126
|
+
│
|
|
127
|
+
├── MassGen LLM Backend ──▶ Mem0 LLM (via adapter)
|
|
128
|
+
├── MassGen Embedding ──▶ Mem0 Embedder (via adapter)
|
|
129
|
+
└── mem0.AsyncMemory
|
|
130
|
+
│
|
|
131
|
+
├── Vector Store (Qdrant/Chroma/Pinecone)
|
|
132
|
+
├── Metadata Store
|
|
133
|
+
└── Memory Index
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Memory Organization**:
|
|
137
|
+
- `agent_id`: Separate memories per agent
|
|
138
|
+
- `user_id`: Track user-specific information
|
|
139
|
+
- `session_id`: Organize by conversation session
|
|
140
|
+
|
|
141
|
+
### 4. Mem0 Adapters (`_mem0_adapters.py`)
|
|
142
|
+
|
|
143
|
+
**Purpose**: Bridge MassGen backends to mem0's interface
|
|
144
|
+
|
|
145
|
+
#### MassGenLLMAdapter
|
|
146
|
+
- Converts MassGen LLM backend to mem0's `LLMBase`
|
|
147
|
+
- Handles async→sync conversion (mem0 limitation)
|
|
148
|
+
- Streams response and aggregates to string
|
|
149
|
+
|
|
150
|
+
#### MassGenEmbeddingAdapter
|
|
151
|
+
- Converts MassGen embedding backend to mem0's `EmbeddingBase`
|
|
152
|
+
- Handles batch embedding requests
|
|
153
|
+
- Returns vector representations
|
|
154
|
+
|
|
155
|
+
**Why Adapters?**
|
|
156
|
+
- mem0 has its own provider system
|
|
157
|
+
- MassGen backends don't natively match mem0's interface
|
|
158
|
+
- Adapters provide seamless integration
|
|
159
|
+
|
|
160
|
+
## Control Modes
|
|
161
|
+
|
|
162
|
+
### Mode 1: Developer-Controlled (Static)
|
|
163
|
+
|
|
164
|
+
Framework automatically manages memory:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
class Agent:
|
|
168
|
+
async def chat(self, user_msg):
|
|
169
|
+
# 1. Add to short-term
|
|
170
|
+
await self.conv_memory.add({"role": "user", "content": user_msg})
|
|
171
|
+
|
|
172
|
+
# 2. Retrieve from long-term
|
|
173
|
+
context = await self.persist_memory.retrieve(user_msg)
|
|
174
|
+
|
|
175
|
+
# 3. Build full context
|
|
176
|
+
messages = await self.conv_memory.get_messages()
|
|
177
|
+
if context:
|
|
178
|
+
messages.insert(0, {"role": "system", "content": context})
|
|
179
|
+
|
|
180
|
+
# 4. Generate response
|
|
181
|
+
response = await self.backend.chat(messages)
|
|
182
|
+
|
|
183
|
+
# 5. Save response to short-term
|
|
184
|
+
await self.conv_memory.add({"role": "assistant", "content": response})
|
|
185
|
+
|
|
186
|
+
# 6. Save important info to long-term
|
|
187
|
+
await self.persist_memory.record(messages)
|
|
188
|
+
|
|
189
|
+
return response
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Mode 2: Agent-Controlled (Dynamic)
|
|
193
|
+
|
|
194
|
+
Agent actively manages its memory via tools:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
# Register memory tools
|
|
198
|
+
tools = [
|
|
199
|
+
{
|
|
200
|
+
"name": "save_to_memory",
|
|
201
|
+
"description": "Save important information",
|
|
202
|
+
"function": memory.save_to_memory
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "recall_from_memory",
|
|
206
|
+
"description": "Search your memory",
|
|
207
|
+
"function": memory.recall_from_memory
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
# Agent decides when to use memory
|
|
212
|
+
# Example: Agent thinks "User mentioned birthday, should save this"
|
|
213
|
+
# -> Calls save_to_memory(thinking="...", content=["Birthday: March 15"])
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Mode 3: Hybrid
|
|
217
|
+
|
|
218
|
+
Combine both approaches:
|
|
219
|
+
- Framework handles routine memory operations
|
|
220
|
+
- Agent has tools for explicit memory management
|
|
221
|
+
- Best of both worlds
|
|
222
|
+
|
|
223
|
+
## Integration with mem0
|
|
224
|
+
|
|
225
|
+
### Why mem0?
|
|
226
|
+
|
|
227
|
+
1. **Mature vector search**: Proven semantic retrieval
|
|
228
|
+
2. **Multiple backends**: Support for Qdrant, Chroma, Pinecone
|
|
229
|
+
3. **Auto summarization**: Intelligent memory compression
|
|
230
|
+
4. **Metadata filtering**: Organize by agent/user/session
|
|
231
|
+
5. **Active community**: Regular updates and improvements
|
|
232
|
+
|
|
233
|
+
### Mem0 Configuration
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
# Simple config (mem0 handles defaults)
|
|
237
|
+
memory = PersistentMemory(
|
|
238
|
+
agent_name="my_agent",
|
|
239
|
+
llm_backend=llm,
|
|
240
|
+
embedding_backend=embedding
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
# Advanced config (full control)
|
|
244
|
+
from mem0.configs.base import MemoryConfig
|
|
245
|
+
|
|
246
|
+
custom_config = MemoryConfig(
|
|
247
|
+
llm=...,
|
|
248
|
+
embedder=...,
|
|
249
|
+
vector_store=...,
|
|
250
|
+
# ... other mem0 settings
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
memory = PersistentMemory(
|
|
254
|
+
agent_name="my_agent",
|
|
255
|
+
mem0_config=custom_config
|
|
256
|
+
)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Mem0 Metadata Usage
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
# Record with metadata
|
|
263
|
+
await memory._mem0_add(
|
|
264
|
+
messages=[{"role": "user", "content": "..."}],
|
|
265
|
+
# These become searchable metadata:
|
|
266
|
+
agent_id="researcher",
|
|
267
|
+
user_id="alice",
|
|
268
|
+
run_id="session_123"
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
# Retrieve filters by metadata automatically
|
|
272
|
+
results = await memory.retrieve(query="...")
|
|
273
|
+
# Only returns memories matching agent_id/user_id/run_id
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## State Management
|
|
277
|
+
|
|
278
|
+
### Conversation Memory State
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
state = {
|
|
282
|
+
"messages": [
|
|
283
|
+
{"role": "user", "content": "...", "id": "msg_abc123"},
|
|
284
|
+
{"role": "assistant", "content": "...", "id": "msg_def456"}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Persistent Memory State
|
|
290
|
+
|
|
291
|
+
State is managed by mem0's vector store (Qdrant/etc):
|
|
292
|
+
- Vectors stored in vector DB
|
|
293
|
+
- Metadata in associated store
|
|
294
|
+
- No explicit state_dict() needed (handled by mem0)
|
|
295
|
+
|
|
296
|
+
## Performance Considerations
|
|
297
|
+
|
|
298
|
+
### Conversation Memory
|
|
299
|
+
- **Add**: O(1) - append to list
|
|
300
|
+
- **Get**: O(n) - iterate list
|
|
301
|
+
- **Delete**: O(n) - rebuild list
|
|
302
|
+
- **Search by role**: O(n) - linear scan
|
|
303
|
+
|
|
304
|
+
### Persistent Memory
|
|
305
|
+
- **Add**: O(1) amortized - vector indexing
|
|
306
|
+
- **Retrieve**: O(log n) - vector similarity search
|
|
307
|
+
- **Memory**: Scales with vector DB backend
|
|
308
|
+
|
|
309
|
+
### Optimization Tips
|
|
310
|
+
1. Truncate conversation memory regularly
|
|
311
|
+
2. Use metadata filters to narrow long-term search
|
|
312
|
+
3. Batch record operations when possible
|
|
313
|
+
4. Consider semantic vs procedural memory types
|
|
314
|
+
|
|
315
|
+
## Error Handling
|
|
316
|
+
|
|
317
|
+
```python
|
|
318
|
+
try:
|
|
319
|
+
await memory.add(messages)
|
|
320
|
+
except TypeError as e:
|
|
321
|
+
# Invalid message format
|
|
322
|
+
logger.error(f"Message format error: {e}")
|
|
323
|
+
|
|
324
|
+
try:
|
|
325
|
+
await persist_memory.retrieve(query)
|
|
326
|
+
except ImportError:
|
|
327
|
+
# mem0 not installed
|
|
328
|
+
logger.error("mem0 required: pip install mem0ai")
|
|
329
|
+
|
|
330
|
+
try:
|
|
331
|
+
await persist_memory.record(messages)
|
|
332
|
+
except RuntimeError as e:
|
|
333
|
+
# Backend error
|
|
334
|
+
logger.error(f"Memory recording failed: {e}")
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Testing Strategy
|
|
338
|
+
|
|
339
|
+
1. **Unit Tests**:
|
|
340
|
+
- Test each method in isolation
|
|
341
|
+
- Mock backends for persistent memory
|
|
342
|
+
- Verify state serialization
|
|
343
|
+
|
|
344
|
+
2. **Integration Tests**:
|
|
345
|
+
- Test with real backends
|
|
346
|
+
- Verify mem0 integration
|
|
347
|
+
- Test cross-component workflows
|
|
348
|
+
|
|
349
|
+
3. **Performance Tests**:
|
|
350
|
+
- Benchmark large conversations
|
|
351
|
+
- Test vector search speed
|
|
352
|
+
- Memory usage profiling
|
|
353
|
+
|
|
354
|
+
## Future Enhancements
|
|
355
|
+
|
|
356
|
+
### Planned Features
|
|
357
|
+
- [ ] Collaboration memory (agent-to-agent shared memory)
|
|
358
|
+
- [ ] Memory compression strategies
|
|
359
|
+
- [ ] Automatic important message detection
|
|
360
|
+
- [ ] Memory analytics and insights
|
|
361
|
+
- [ ] Memory export/import utilities
|
|
362
|
+
- [ ] Multi-modal memory (images, audio)
|
|
363
|
+
|
|
364
|
+
### Potential Improvements
|
|
365
|
+
- [ ] LRU cache for frequent retrievals
|
|
366
|
+
- [ ] Async batch operations
|
|
367
|
+
- [ ] Memory pruning strategies
|
|
368
|
+
- [ ] Cross-agent memory sharing protocols
|
|
369
|
+
- [ ] Privacy-preserving memory
|
|
370
|
+
|
|
371
|
+
## Migration from agentscope
|
|
372
|
+
|
|
373
|
+
Key differences from agentscope's memory:
|
|
374
|
+
|
|
375
|
+
| Aspect | agentscope | MassGen |
|
|
376
|
+
|--------|-----------|---------|
|
|
377
|
+
| Message format | `Msg` objects | `Dict[str, Any]` |
|
|
378
|
+
| Base class | `StateModule` | No dependency |
|
|
379
|
+
| Naming | `InMemoryMemory` | `ConversationMemory` |
|
|
380
|
+
| Naming | `Mem0LongTermMemory` | `PersistentMemory` |
|
|
381
|
+
| Adapters | `AgentScope*` | `MassGen*` |
|
|
382
|
+
| Tool names | `record_to_memory` | `save_to_memory` |
|
|
383
|
+
| Tool names | `retrieve_from_memory` | `recall_from_memory` |
|
|
384
|
+
| Documentation | Academic style | Practical examples |
|
|
385
|
+
|
|
386
|
+
## Conclusion
|
|
387
|
+
|
|
388
|
+
The MassGen memory system provides a robust foundation for building agents with both short-term and long-term memory capabilities. By leveraging mem0 for persistent storage and providing clean abstractions, it enables developers to create more contextual and intelligent agent systems.
|