massgen 0.1.4__py3-none-any.whl → 0.1.6__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.

Files changed (84) hide show
  1. massgen/__init__.py +1 -1
  2. massgen/backend/base_with_custom_tool_and_mcp.py +453 -23
  3. massgen/backend/capabilities.py +39 -0
  4. massgen/backend/chat_completions.py +111 -197
  5. massgen/backend/claude.py +210 -181
  6. massgen/backend/gemini.py +1015 -1559
  7. massgen/backend/grok.py +3 -2
  8. massgen/backend/response.py +160 -220
  9. massgen/chat_agent.py +340 -20
  10. massgen/cli.py +399 -25
  11. massgen/config_builder.py +20 -54
  12. massgen/config_validator.py +931 -0
  13. massgen/configs/README.md +95 -10
  14. massgen/configs/memory/gpt5mini_gemini_baseline_research_to_implementation.yaml +94 -0
  15. massgen/configs/memory/gpt5mini_gemini_context_window_management.yaml +187 -0
  16. massgen/configs/memory/gpt5mini_gemini_research_to_implementation.yaml +127 -0
  17. massgen/configs/memory/gpt5mini_high_reasoning_gemini.yaml +107 -0
  18. massgen/configs/memory/single_agent_compression_test.yaml +64 -0
  19. massgen/configs/tools/custom_tools/claude_code_custom_tool_with_mcp_example.yaml +1 -0
  20. massgen/configs/tools/custom_tools/claude_custom_tool_example_no_path.yaml +1 -1
  21. massgen/configs/tools/custom_tools/claude_custom_tool_with_mcp_example.yaml +1 -0
  22. massgen/configs/tools/custom_tools/computer_use_browser_example.yaml +1 -1
  23. massgen/configs/tools/custom_tools/computer_use_docker_example.yaml +1 -1
  24. massgen/configs/tools/custom_tools/gemini_custom_tool_with_mcp_example.yaml +1 -0
  25. massgen/configs/tools/custom_tools/gpt5_nano_custom_tool_with_mcp_example.yaml +1 -0
  26. massgen/configs/tools/custom_tools/gpt_oss_custom_tool_with_mcp_example.yaml +1 -0
  27. massgen/configs/tools/custom_tools/grok3_mini_custom_tool_with_mcp_example.yaml +1 -0
  28. massgen/configs/tools/custom_tools/interop/ag2_and_langgraph_lesson_planner.yaml +65 -0
  29. massgen/configs/tools/custom_tools/interop/ag2_and_openai_assistant_lesson_planner.yaml +65 -0
  30. massgen/configs/tools/custom_tools/interop/ag2_lesson_planner_example.yaml +48 -0
  31. massgen/configs/tools/custom_tools/interop/agentscope_lesson_planner_example.yaml +48 -0
  32. massgen/configs/tools/custom_tools/interop/langgraph_lesson_planner_example.yaml +49 -0
  33. massgen/configs/tools/custom_tools/interop/openai_assistant_lesson_planner_example.yaml +50 -0
  34. massgen/configs/tools/custom_tools/interop/smolagent_lesson_planner_example.yaml +49 -0
  35. massgen/configs/tools/custom_tools/qwen_api_custom_tool_with_mcp_example.yaml +1 -0
  36. massgen/configs/tools/custom_tools/two_models_with_tools_example.yaml +44 -0
  37. massgen/formatter/_gemini_formatter.py +61 -15
  38. massgen/memory/README.md +277 -0
  39. massgen/memory/__init__.py +26 -0
  40. massgen/memory/_base.py +193 -0
  41. massgen/memory/_compression.py +237 -0
  42. massgen/memory/_context_monitor.py +211 -0
  43. massgen/memory/_conversation.py +255 -0
  44. massgen/memory/_fact_extraction_prompts.py +333 -0
  45. massgen/memory/_mem0_adapters.py +257 -0
  46. massgen/memory/_persistent.py +687 -0
  47. massgen/memory/docker-compose.qdrant.yml +36 -0
  48. massgen/memory/docs/DESIGN.md +388 -0
  49. massgen/memory/docs/QUICKSTART.md +409 -0
  50. massgen/memory/docs/SUMMARY.md +319 -0
  51. massgen/memory/docs/agent_use_memory.md +408 -0
  52. massgen/memory/docs/orchestrator_use_memory.md +586 -0
  53. massgen/memory/examples.py +237 -0
  54. massgen/orchestrator.py +207 -7
  55. massgen/tests/memory/test_agent_compression.py +174 -0
  56. massgen/tests/memory/test_context_window_management.py +286 -0
  57. massgen/tests/memory/test_force_compression.py +154 -0
  58. massgen/tests/memory/test_simple_compression.py +147 -0
  59. massgen/tests/test_ag2_lesson_planner.py +223 -0
  60. massgen/tests/test_agent_memory.py +534 -0
  61. massgen/tests/test_config_validator.py +1156 -0
  62. massgen/tests/test_conversation_memory.py +382 -0
  63. massgen/tests/test_langgraph_lesson_planner.py +223 -0
  64. massgen/tests/test_orchestrator_memory.py +620 -0
  65. massgen/tests/test_persistent_memory.py +435 -0
  66. massgen/token_manager/token_manager.py +6 -0
  67. massgen/tool/__init__.py +2 -9
  68. massgen/tool/_decorators.py +52 -0
  69. massgen/tool/_extraframework_agents/ag2_lesson_planner_tool.py +251 -0
  70. massgen/tool/_extraframework_agents/agentscope_lesson_planner_tool.py +303 -0
  71. massgen/tool/_extraframework_agents/langgraph_lesson_planner_tool.py +275 -0
  72. massgen/tool/_extraframework_agents/openai_assistant_lesson_planner_tool.py +247 -0
  73. massgen/tool/_extraframework_agents/smolagent_lesson_planner_tool.py +180 -0
  74. massgen/tool/_manager.py +102 -16
  75. massgen/tool/_registered_tool.py +3 -0
  76. massgen/tool/_result.py +3 -0
  77. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/METADATA +138 -77
  78. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/RECORD +82 -37
  79. massgen/backend/gemini_mcp_manager.py +0 -545
  80. massgen/backend/gemini_trackers.py +0 -344
  81. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/WHEEL +0 -0
  82. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/entry_points.txt +0 -0
  83. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/licenses/LICENSE +0 -0
  84. {massgen-0.1.4.dist-info → massgen-0.1.6.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.