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,408 @@
1
+ # Agent Memory Integration
2
+
3
+ ## Overview
4
+
5
+ This document describes how MassGen agents (`SingleAgent` and `ConfigurableAgent`) integrate with the memory system to maintain conversation history and long-term knowledge.
6
+
7
+ ## Architecture
8
+
9
+ Agents can use two types of memory:
10
+
11
+ 1. **ConversationMemory**: Stores short-term conversation history for the current session
12
+ 2. **PersistentMemory**: Stores long-term knowledge that persists across sessions
13
+
14
+ ```
15
+ ┌─────────────────────────────────────────────────────────────┐
16
+ │ MassGen Agent │
17
+ │ (SingleAgent/ConfigurableAgent) │
18
+ ├─────────────────────────────────────────────────────────────┤
19
+ │ │
20
+ │ ┌────────────────────────┐ ┌─────────────────────────┐ │
21
+ │ │ ConversationMemory │ │ PersistentMemory │ │
22
+ │ │ (Optional) │ │ (Optional) │ │
23
+ │ ├────────────────────────┤ ├─────────────────────────┤ │
24
+ │ │ • Message history │ │ • Retrieve context │ │
25
+ │ │ • Add new messages │ │ • Record interactions │ │
26
+ │ │ • Clear history │ │ • Cross-session memory │ │
27
+ │ └────────────────────────┘ └─────────────────────────┘ │
28
+ │ ▲ ▲ │
29
+ │ │ │ │
30
+ │ └──────────┬───────────────────┘ │
31
+ │ │ │
32
+ │ ┌───────▼────────┐ │
33
+ │ │ Agent.chat() │ │
34
+ │ │ │ │
35
+ │ │ 1. Retrieve │ │
36
+ │ │ 2. Process │ │
37
+ │ │ 3. Record │ │
38
+ │ └────────────────┘ │
39
+ └─────────────────────────────────────────────────────────────┘
40
+ ```
41
+
42
+ ## Implementation Details
43
+
44
+ ### Initialization
45
+
46
+ Agents accept memory instances during initialization:
47
+
48
+ ```python
49
+ from massgen.chat_agent import SingleAgent
50
+ from massgen.memory import ConversationMemory, PersistentMemory
51
+
52
+ # Create memory instances
53
+ conv_memory = ConversationMemory()
54
+ persist_memory = PersistentMemory(
55
+ user_id="user_123",
56
+ agent_id="agent_1"
57
+ )
58
+
59
+ # Initialize agent with memories
60
+ agent = SingleAgent(
61
+ backend=backend,
62
+ agent_id="my_agent",
63
+ conversation_memory=conv_memory, # Optional
64
+ persistent_memory=persist_memory # Optional
65
+ )
66
+ ```
67
+
68
+ Both memory parameters are optional - agents can use:
69
+ - Only conversation memory
70
+ - Only persistent memory
71
+ - Both memories
72
+ - No memory (stateless operation)
73
+
74
+ ### Memory Lifecycle During Chat
75
+
76
+ When the agent's `chat()` method is called, the following memory operations occur:
77
+
78
+ #### 1. Pre-Processing: Memory Retrieval
79
+
80
+ **ConversationMemory** (if configured):
81
+ - Handles conversation history automatically based on `clear_history` and `reset_chat` flags
82
+ - If `clear_history=True`: Clears conversation memory before processing
83
+ - If `reset_chat=True`: Resets conversation memory before processing
84
+
85
+ **PersistentMemory** (if configured):
86
+ - Retrieves relevant context from long-term memory
87
+ - Context is based on the current messages being processed
88
+ - Retrieved context is injected into the message flow
89
+
90
+ ```python
91
+ # Code location: massgen/chat_agent.py:325-327
92
+ if self.persistent_memory:
93
+ try:
94
+ memory_context = await self.persistent_memory.retrieve(messages)
95
+ ```
96
+
97
+ #### 2. Processing: Message Handling
98
+
99
+ During chat:
100
+ - Agent processes messages with injected memory context
101
+ - ConversationMemory tracks the conversation flow
102
+ - PersistentMemory context helps inform agent responses
103
+
104
+ #### 3. Post-Processing: Memory Recording
105
+
106
+ **ConversationMemory** (if configured):
107
+ - Records all user and assistant messages
108
+ - Maintains chronological conversation history
109
+ - Messages are stored with role and content
110
+
111
+ ```python
112
+ # Code location: massgen/chat_agent.py:250-253
113
+ if self.conversation_memory:
114
+ try:
115
+ await self.conversation_memory.add(messages_to_record)
116
+ ```
117
+
118
+ **PersistentMemory** (if configured):
119
+ - Records the interaction for long-term storage
120
+ - Messages are semantically indexed for future retrieval
121
+ - Supports cross-session knowledge building
122
+
123
+ ```python
124
+ # Code location: massgen/chat_agent.py:257-259
125
+ if self.persistent_memory:
126
+ try:
127
+ await self.persistent_memory.record(messages_to_record)
128
+ ```
129
+
130
+ ### Memory State Management
131
+
132
+ #### Clearing Memory
133
+
134
+ Agents provide a `reset()` method to clear conversation memory:
135
+
136
+ ```python
137
+ # Clear conversation memory
138
+ await agent.reset()
139
+ ```
140
+
141
+ This only affects ConversationMemory - PersistentMemory is preserved across resets.
142
+
143
+ #### Chat Flags
144
+
145
+ The `chat()` method supports flags for memory control:
146
+
147
+ - **`clear_history=True`**: Clears conversation memory before processing new messages
148
+ - **`reset_chat=True`**: Resets the conversation memory state
149
+
150
+ ```python
151
+ # Start a new conversation, clearing previous history
152
+ async for chunk in agent.chat(messages, clear_history=True):
153
+ # Process chunks
154
+ pass
155
+
156
+ # Reset chat state
157
+ async for chunk in agent.chat(messages, reset_chat=True):
158
+ # Process chunks
159
+ pass
160
+ ```
161
+
162
+ ## Error Handling
163
+
164
+ The agent implementation includes robust error handling for memory operations:
165
+
166
+ ### ConversationMemory Errors
167
+
168
+ If ConversationMemory operations fail:
169
+ - The error is caught silently
170
+ - Agent continues operation without conversation memory
171
+ - User interaction is not interrupted
172
+
173
+ ```python
174
+ # Code location: massgen/chat_agent.py:252-254
175
+ try:
176
+ await self.conversation_memory.add(messages_to_record)
177
+ except Exception:
178
+ pass # Fail silently to not interrupt chat
179
+ ```
180
+
181
+ ### PersistentMemory Errors
182
+
183
+ If PersistentMemory operations fail or raise `NotImplementedError`:
184
+ - The error is caught
185
+ - Agent continues without persistent memory features
186
+ - User interaction proceeds normally
187
+
188
+ ```python
189
+ # Code location: massgen/chat_agent.py:259-261
190
+ try:
191
+ await self.persistent_memory.record(messages_to_record)
192
+ except (Exception, NotImplementedError):
193
+ pass # Fail silently
194
+ ```
195
+
196
+ ## Usage Examples
197
+
198
+ ### Example 1: Agent with ConversationMemory Only
199
+
200
+ ```python
201
+ from massgen.chat_agent import SingleAgent
202
+ from massgen.memory import ConversationMemory
203
+
204
+ # Create conversation memory
205
+ conv_memory = ConversationMemory()
206
+
207
+ # Create agent
208
+ agent = SingleAgent(
209
+ backend=backend,
210
+ conversation_memory=conv_memory
211
+ )
212
+
213
+ # First conversation
214
+ messages1 = [{"role": "user", "content": "Hello!"}]
215
+ async for chunk in agent.chat(messages1):
216
+ print(chunk)
217
+
218
+ # Second conversation - remembers first conversation
219
+ messages2 = [{"role": "user", "content": "What did I say earlier?"}]
220
+ async for chunk in agent.chat(messages2):
221
+ print(chunk)
222
+
223
+ # Check conversation history
224
+ history = await conv_memory.get_messages()
225
+ print(f"Conversation has {len(history)} messages")
226
+ ```
227
+
228
+ ### Example 2: Agent with PersistentMemory Only
229
+
230
+ ```python
231
+ from massgen.chat_agent import SingleAgent
232
+ from massgen.memory import PersistentMemory
233
+
234
+ # Create persistent memory
235
+ persist_memory = PersistentMemory(
236
+ user_id="user_123",
237
+ agent_id="assistant"
238
+ )
239
+
240
+ # Create agent
241
+ agent = SingleAgent(
242
+ backend=backend,
243
+ persistent_memory=persist_memory
244
+ )
245
+
246
+ # Chat with long-term memory
247
+ messages = [{"role": "user", "content": "Remember that I like Python"}]
248
+ async for chunk in agent.chat(messages):
249
+ print(chunk)
250
+
251
+ # Later session - memory persists
252
+ messages2 = [{"role": "user", "content": "What programming language do I like?"}]
253
+ async for chunk in agent.chat(messages2):
254
+ print(chunk)
255
+ ```
256
+
257
+ ### Example 3: Agent with Both Memories
258
+
259
+ ```python
260
+ from massgen.chat_agent import SingleAgent
261
+ from massgen.memory import ConversationMemory, PersistentMemory
262
+
263
+ # Create both memory types
264
+ conv_memory = ConversationMemory()
265
+ persist_memory = PersistentMemory(
266
+ user_id="user_123",
267
+ agent_id="assistant"
268
+ )
269
+
270
+ # Create agent with both memories
271
+ agent = SingleAgent(
272
+ backend=backend,
273
+ conversation_memory=conv_memory,
274
+ persistent_memory=persist_memory
275
+ )
276
+
277
+ # Benefits:
278
+ # - Short-term: Full conversation context in current session
279
+ # - Long-term: Knowledge persists across sessions
280
+ messages = [{"role": "user", "content": "My name is Alice"}]
281
+ async for chunk in agent.chat(messages):
282
+ print(chunk)
283
+ ```
284
+
285
+ ### Example 4: ConfigurableAgent with Memory
286
+
287
+ ```python
288
+ from massgen.chat_agent import ConfigurableAgent
289
+ from massgen.agent_config import AgentConfig
290
+ from massgen.memory import ConversationMemory, PersistentMemory
291
+
292
+ # Create agent configuration
293
+ config = AgentConfig(
294
+ agent_id="my_configurable_agent",
295
+ backend_params={"model": "gpt-4o-mini"}
296
+ )
297
+
298
+ # Create memories
299
+ conv_memory = ConversationMemory()
300
+ persist_memory = PersistentMemory(
301
+ user_id="user_123",
302
+ agent_id="my_configurable_agent"
303
+ )
304
+
305
+ # Create configurable agent with memory
306
+ agent = ConfigurableAgent(
307
+ config=config,
308
+ backend=backend,
309
+ conversation_memory=conv_memory,
310
+ persistent_memory=persist_memory
311
+ )
312
+
313
+ # Use exactly like SingleAgent
314
+ messages = [{"role": "user", "content": "Hello!"}]
315
+ async for chunk in agent.chat(messages):
316
+ print(chunk)
317
+ ```
318
+
319
+ ## Memory Flow Diagram
320
+
321
+ ```
322
+ User Message
323
+
324
+
325
+ ┌───────────────────────────────────────────┐
326
+ │ Agent.chat() Called │
327
+ └───────────────────────────────────────────┘
328
+
329
+ ├─── Check clear_history/reset_chat flags
330
+ │ │
331
+ │ ├─── If clear_history: Clear ConversationMemory
332
+ │ └─── If reset_chat: Reset ConversationMemory
333
+
334
+ ├─── Retrieve from PersistentMemory
335
+ │ │
336
+ │ └─── Inject context into messages
337
+
338
+ ├─── Process messages with LLM backend
339
+ │ │
340
+ │ └─── Generate response
341
+
342
+ └─── Record to Memories
343
+
344
+ ├─── Add to ConversationMemory
345
+ │ └─── Store user + assistant messages
346
+
347
+ └─── Record to PersistentMemory
348
+ └─── Store for long-term retrieval
349
+ ```
350
+
351
+ ## Key Files
352
+
353
+ Implementation files:
354
+ - `massgen/chat_agent.py:33-41` - Memory initialization in ChatAgent base class
355
+ - `massgen/chat_agent.py:250-261` - Memory recording logic
356
+ - `massgen/chat_agent.py:298-310` - Clear history and reset chat logic
357
+ - `massgen/chat_agent.py:325-327` - Persistent memory retrieval
358
+ - `massgen/chat_agent.py:397-398` - Reset method
359
+
360
+ Test files:
361
+ - `massgen/tests/test_agent_memory.py` - Comprehensive agent memory tests
362
+
363
+ ## Best Practices
364
+
365
+ 1. **Choose the Right Memory Type**:
366
+ - Use ConversationMemory for multi-turn conversations within a session
367
+ - Use PersistentMemory for knowledge that should persist across sessions
368
+ - Use both for comprehensive memory management
369
+
370
+ 2. **Handle Memory Gracefully**:
371
+ - Both memory types are optional
372
+ - Agents work fine without memory (stateless mode)
373
+ - Memory failures don't crash the agent
374
+
375
+ 3. **Clear Memory When Needed**:
376
+ - Use `clear_history=True` to start fresh conversations
377
+ - Use `reset_chat=True` to reset conversation state
378
+ - Call `agent.reset()` to explicitly clear conversation memory
379
+
380
+ 4. **Memory Scope**:
381
+ - ConversationMemory is session-scoped (cleared on reset)
382
+ - PersistentMemory is user/agent-scoped (persists across sessions)
383
+
384
+ ## Limitations
385
+
386
+ 1. **ConversationMemory**:
387
+ - Not persistent across agent restarts
388
+ - Memory grows indefinitely unless cleared
389
+ - Stored in-memory (not suitable for very long conversations)
390
+
391
+ 2. **PersistentMemory**:
392
+ - Requires additional setup (mem0, embedding model)
393
+ - Retrieval is semantic, not exact
394
+ - May not retrieve all relevant context
395
+
396
+ 3. **Error Handling**:
397
+ - Memory errors are silently caught
398
+ - No explicit feedback to user when memory operations fail
399
+ - Debugging memory issues requires logging inspection
400
+
401
+ ## Future Enhancements
402
+
403
+ - [ ] Memory size limits and automatic truncation for ConversationMemory
404
+ - [ ] Explicit error handling modes (silent vs. explicit)
405
+ - [ ] Memory statistics and monitoring
406
+ - [ ] Selective memory clearing (by role, time range, etc.)
407
+ - [ ] Memory compression for long conversations
408
+ - [ ] Agent-controlled memory management (tools to add/remove/search memory)