massgen 0.1.3__py3-none-any.whl → 0.1.4__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 (58) hide show
  1. massgen/__init__.py +1 -1
  2. massgen/api_params_handler/_chat_completions_api_params_handler.py +4 -0
  3. massgen/api_params_handler/_claude_api_params_handler.py +4 -0
  4. massgen/api_params_handler/_gemini_api_params_handler.py +4 -0
  5. massgen/api_params_handler/_response_api_params_handler.py +4 -0
  6. massgen/backend/base_with_custom_tool_and_mcp.py +25 -5
  7. massgen/backend/docs/permissions_and_context_files.md +2 -2
  8. massgen/backend/response.py +2 -0
  9. massgen/configs/README.md +49 -40
  10. massgen/configs/tools/custom_tools/crawl4ai_example.yaml +55 -0
  11. massgen/configs/tools/custom_tools/multimodal_tools/text_to_file_generation_multi.yaml +61 -0
  12. massgen/configs/tools/custom_tools/multimodal_tools/text_to_file_generation_single.yaml +29 -0
  13. massgen/configs/tools/custom_tools/multimodal_tools/text_to_image_generation_multi.yaml +51 -0
  14. massgen/configs/tools/custom_tools/multimodal_tools/text_to_image_generation_single.yaml +33 -0
  15. massgen/configs/tools/custom_tools/multimodal_tools/text_to_speech_generation_multi.yaml +55 -0
  16. massgen/configs/tools/custom_tools/multimodal_tools/text_to_speech_generation_single.yaml +33 -0
  17. massgen/configs/tools/custom_tools/multimodal_tools/text_to_video_generation_multi.yaml +47 -0
  18. massgen/configs/tools/custom_tools/multimodal_tools/text_to_video_generation_single.yaml +29 -0
  19. massgen/configs/tools/custom_tools/multimodal_tools/understand_audio.yaml +1 -1
  20. massgen/configs/tools/custom_tools/multimodal_tools/understand_file.yaml +1 -1
  21. massgen/configs/tools/custom_tools/multimodal_tools/understand_image.yaml +1 -1
  22. massgen/configs/tools/custom_tools/multimodal_tools/understand_video.yaml +1 -1
  23. massgen/configs/tools/custom_tools/multimodal_tools/youtube_video_analysis.yaml +1 -1
  24. massgen/filesystem_manager/_filesystem_manager.py +1 -0
  25. massgen/filesystem_manager/_path_permission_manager.py +148 -0
  26. massgen/message_templates.py +160 -12
  27. massgen/orchestrator.py +16 -0
  28. massgen/tests/test_binary_file_blocking.py +274 -0
  29. massgen/tests/test_case_studies.md +12 -12
  30. massgen/tests/test_multimodal_size_limits.py +407 -0
  31. massgen/tool/_manager.py +7 -2
  32. massgen/tool/_multimodal_tools/image_to_image_generation.py +293 -0
  33. massgen/tool/_multimodal_tools/text_to_file_generation.py +455 -0
  34. massgen/tool/_multimodal_tools/text_to_image_generation.py +222 -0
  35. massgen/tool/_multimodal_tools/text_to_speech_continue_generation.py +226 -0
  36. massgen/tool/_multimodal_tools/text_to_speech_transcription_generation.py +217 -0
  37. massgen/tool/_multimodal_tools/text_to_video_generation.py +223 -0
  38. massgen/tool/_multimodal_tools/understand_audio.py +19 -1
  39. massgen/tool/_multimodal_tools/understand_file.py +6 -1
  40. massgen/tool/_multimodal_tools/understand_image.py +112 -8
  41. massgen/tool/_multimodal_tools/understand_video.py +32 -5
  42. massgen/tool/_web_tools/crawl4ai_tool.py +718 -0
  43. massgen/tool/docs/multimodal_tools.md +589 -0
  44. {massgen-0.1.3.dist-info → massgen-0.1.4.dist-info}/METADATA +96 -69
  45. {massgen-0.1.3.dist-info → massgen-0.1.4.dist-info}/RECORD +49 -40
  46. massgen/configs/tools/custom_tools/crawl4ai_mcp_example.yaml +0 -67
  47. massgen/configs/tools/custom_tools/crawl4ai_multi_agent_example.yaml +0 -68
  48. massgen/configs/tools/custom_tools/multimodal_tools/playwright_with_img_understanding.yaml +0 -98
  49. massgen/configs/tools/custom_tools/multimodal_tools/understand_video_example.yaml +0 -54
  50. massgen/configs/tools/memory/README.md +0 -199
  51. massgen/configs/tools/memory/gpt5mini_gemini_context_window_management.yaml +0 -131
  52. massgen/configs/tools/memory/gpt5mini_gemini_no_persistent_memory.yaml +0 -133
  53. massgen/configs/tools/memory/test_context_window_management.py +0 -286
  54. massgen/configs/tools/multimodal/gpt5mini_gpt5nano_documentation_evolution.yaml +0 -97
  55. {massgen-0.1.3.dist-info → massgen-0.1.4.dist-info}/WHEEL +0 -0
  56. {massgen-0.1.3.dist-info → massgen-0.1.4.dist-info}/entry_points.txt +0 -0
  57. {massgen-0.1.3.dist-info → massgen-0.1.4.dist-info}/licenses/LICENSE +0 -0
  58. {massgen-0.1.3.dist-info → massgen-0.1.4.dist-info}/top_level.txt +0 -0
@@ -1,286 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Test script for Context Window Management with Memory.
5
-
6
- This script demonstrates how to configure and test the context window
7
- management feature with persistent memory integration.
8
-
9
- Usage:
10
- python massgen/configs/tools/memory/test_context_window_management.py
11
-
12
- # Or specify a custom config:
13
- python massgen/configs/tools/memory/test_context_window_management.py --config path/to/config.yaml
14
- """
15
-
16
- import asyncio
17
- import os
18
- import sys
19
- from pathlib import Path
20
-
21
- # Add parent directory to path for imports
22
- sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent))
23
-
24
- import yaml
25
- from dotenv import load_dotenv
26
-
27
- from massgen.backend.chat_completions import ChatCompletionsBackend
28
- from massgen.chat_agent import SingleAgent
29
- from massgen.memory import ConversationMemory, PersistentMemory
30
-
31
- # Load environment variables from .env file
32
- load_dotenv()
33
-
34
-
35
- def load_config(config_path: str = None) -> dict:
36
- """Load configuration from YAML file."""
37
- if config_path is None:
38
- # Default to the config in same directory
39
- config_path = Path(__file__).parent / "gpt5mini_gemini_context_window_management.yaml"
40
-
41
- with open(config_path, 'r') as f:
42
- return yaml.safe_load(f)
43
-
44
-
45
- async def test_with_persistent_memory(config: dict):
46
- """Test context compression with persistent memory enabled."""
47
- # Check if memory is enabled in config
48
- memory_config = config.get('memory', {})
49
- if not memory_config.get('enabled', True):
50
- print("\n⚠️ Skipping: memory.enabled is false in config")
51
- return
52
-
53
- persistent_enabled = memory_config.get('persistent_memory', {}).get('enabled', True)
54
- if not persistent_enabled:
55
- print("\n⚠️ Skipping: memory.persistent_memory.enabled is false in config")
56
- return
57
-
58
- print("\n" + "=" * 70)
59
- print("TEST 1: Context Window Management WITH Persistent Memory")
60
- print("=" * 70 + "\n")
61
-
62
- # Get memory settings from config
63
- persistent_config = memory_config.get('persistent_memory', {})
64
- agent_name = persistent_config.get('agent_name', 'storyteller_agent')
65
- session_name = persistent_config.get('session_name', 'test_session')
66
- on_disk = persistent_config.get('on_disk', True)
67
-
68
- # Create LLM backend for both agent and memory
69
- llm_backend = ChatCompletionsBackend(
70
- type="openai",
71
- model="gpt-4o-mini", # Use smaller model for faster testing
72
- api_key=os.getenv("OPENAI_API_KEY"),
73
- )
74
-
75
- # Create embedding backend for persistent memory
76
- embedding_backend = ChatCompletionsBackend(
77
- type="openai",
78
- model="text-embedding-3-small",
79
- api_key=os.getenv("OPENAI_API_KEY"),
80
- )
81
-
82
- # Initialize memory systems
83
- conversation_memory = ConversationMemory()
84
- persistent_memory = PersistentMemory(
85
- agent_name=agent_name,
86
- session_name=session_name,
87
- llm_backend=llm_backend,
88
- embedding_backend=embedding_backend,
89
- on_disk=on_disk,
90
- )
91
-
92
- # Create agent with memory
93
- agent = SingleAgent(
94
- backend=llm_backend,
95
- agent_id="storyteller",
96
- system_message="You are a creative storyteller. Create detailed, "
97
- "immersive narratives with rich descriptions.",
98
- conversation_memory=conversation_memory,
99
- persistent_memory=persistent_memory,
100
- )
101
-
102
- print("✅ Agent initialized with memory")
103
- print(f" - ConversationMemory: Active")
104
- print(f" - PersistentMemory: Active (agent={agent_name}, session={session_name}, on_disk={on_disk})")
105
- print(f" - Model context window: 128,000 tokens")
106
- print(f" - Compression triggers at: 96,000 tokens (75%)")
107
- print(f" - Target after compression: 51,200 tokens (40%)\n")
108
-
109
- # Simulate a conversation that will fill context
110
- # Each turn will add significant tokens
111
- story_prompts = [
112
- "Tell me the beginning of a space exploration story. Include details about the ship, crew, and their mission. (Make it 400+ words)",
113
- "What happens when they encounter their first alien planet? Describe it in vivid detail.",
114
- "Describe a tense first contact situation with aliens. What do they look like? How do they communicate?",
115
- "The mission takes an unexpected turn. What crisis occurs and how does the crew respond?",
116
- "Show me a dramatic action sequence involving the ship's technology and the alien environment.",
117
- "Reveal a plot twist about one of the crew members or the mission itself.",
118
- "Continue the story with escalating tension and more discoveries.",
119
- "How do cultural differences between humans and aliens create conflicts?",
120
- "Describe a major decision point for the crew captain. What are the stakes?",
121
- "Bring the story to a climactic moment with high drama.",
122
- ]
123
-
124
- turn = 0
125
- for prompt in story_prompts:
126
- turn += 1
127
- print(f"\n--- Turn {turn} ---")
128
- print(f"User: {prompt}\n")
129
-
130
- response_text = ""
131
- async for chunk in agent.chat([{"role": "user", "content": prompt}]):
132
- if chunk.type == "content" and chunk.content:
133
- response_text += chunk.content
134
-
135
- print(f"Agent: {response_text[:200]}...")
136
- print(f" [{len(response_text)} chars in response]")
137
-
138
- # Check if compression occurred by examining conversation size
139
- if conversation_memory:
140
- size = await conversation_memory.size()
141
- print(f" [Conversation memory: {size} messages]\n")
142
-
143
- print("\n✅ Test completed!")
144
- print(" Check the output above for compression logs:")
145
- print(" - Look for: '📊 Context usage: ...'")
146
- print(" - Look for: '📦 Compressed N messages into long-term memory'")
147
-
148
-
149
- async def test_without_persistent_memory(config: dict):
150
- """Test context compression without persistent memory (warning case)."""
151
- # Check if we should run this test
152
- memory_config = config.get('memory', {})
153
- persistent_enabled = memory_config.get('persistent_memory', {}).get('enabled', True)
154
-
155
- if persistent_enabled:
156
- # Skip if persistent memory is enabled - we already tested that scenario
157
- print("\n⚠️ Skipping Test 2: persistent memory is enabled in config")
158
- print(" To test without persistent memory, set memory.persistent_memory.enabled: false")
159
- return
160
-
161
- print("\n" + "=" * 70)
162
- print("TEST 2: Context Window Management WITHOUT Persistent Memory")
163
- print("=" * 70 + "\n")
164
-
165
- # Create LLM backend
166
- llm_backend = ChatCompletionsBackend(
167
- type="openai",
168
- model="gpt-4o-mini",
169
- api_key=os.getenv("OPENAI_API_KEY"),
170
- )
171
-
172
- # Only conversation memory, NO persistent memory
173
- conversation_memory = ConversationMemory()
174
-
175
- # Create agent without persistent memory
176
- agent = SingleAgent(
177
- backend=llm_backend,
178
- agent_id="storyteller_no_persist",
179
- system_message="You are a creative storyteller.",
180
- conversation_memory=conversation_memory,
181
- persistent_memory=None, # No persistent memory!
182
- )
183
-
184
- print("⚠️ Agent initialized WITHOUT persistent memory")
185
- print(f" - ConversationMemory: Active")
186
- print(f" - PersistentMemory: NONE")
187
- print(f" - This will trigger warning messages when context fills\n")
188
-
189
- # Shorter test - just trigger compression
190
- story_prompts = [
191
- "Tell me a 500-word science fiction story about time travel.",
192
- "Continue the story with 500 more words about paradoxes.",
193
- "Add another 500 words with a plot twist.",
194
- "Continue with 500 words about the resolution.",
195
- "Write a 500-word epilogue.",
196
- ]
197
-
198
- turn = 0
199
- for prompt in story_prompts:
200
- turn += 1
201
- print(f"\n--- Turn {turn} ---")
202
- print(f"User: {prompt}\n")
203
-
204
- response_text = ""
205
- async for chunk in agent.chat([{"role": "user", "content": prompt}]):
206
- if chunk.type == "content" and chunk.content:
207
- response_text += chunk.content
208
-
209
- print(f"Agent: {response_text[:150]}...")
210
-
211
- print("\n✅ Test completed!")
212
- print(" Check the output above for warning messages:")
213
- print(" - Look for: '⚠️ Warning: Dropping N messages'")
214
- print(" - Look for: 'No persistent memory configured'")
215
-
216
-
217
- async def main(config_path: str = None):
218
- """Run all tests."""
219
- print("\n" + "=" * 70)
220
- print("Context Window Management Test Suite")
221
- print("=" * 70)
222
-
223
- # Load configuration
224
- config = load_config(config_path)
225
-
226
- # Show memory configuration
227
- memory_config = config.get('memory', {})
228
- print(f"\n📋 Memory Configuration (from YAML):")
229
- print(f" - Enabled: {memory_config.get('enabled', True)}")
230
- print(f" - Conversation Memory: {memory_config.get('conversation_memory', {}).get('enabled', True)}")
231
- print(f" - Persistent Memory: {memory_config.get('persistent_memory', {}).get('enabled', True)}")
232
-
233
- if memory_config.get('persistent_memory', {}).get('enabled', True):
234
- pm_config = memory_config.get('persistent_memory', {})
235
- print(f" - Agent Name: {pm_config.get('agent_name', 'N/A')}")
236
- print(f" - Session Name: {pm_config.get('session_name', 'N/A')}")
237
- print(f" - On Disk: {pm_config.get('on_disk', True)}")
238
-
239
- compression_config = memory_config.get('compression', {})
240
- print(f" - Compression Trigger: {compression_config.get('trigger_threshold', 0.75)*100}%")
241
- print(f" - Target After Compression: {compression_config.get('target_ratio', 0.40)*100}%\n")
242
-
243
- # Check for API key
244
- if not os.getenv("OPENAI_API_KEY"):
245
- print("\n❌ Error: OPENAI_API_KEY environment variable not set")
246
- print(" Please set your OpenAI API key:")
247
- print(" export OPENAI_API_KEY='your-key-here'")
248
- return
249
-
250
- try:
251
- # Test 1: With persistent memory (if enabled)
252
- await test_with_persistent_memory(config)
253
-
254
- # Wait between tests
255
- print("\n" + "-" * 70)
256
- print("Waiting 5 seconds before next test...")
257
- print("-" * 70)
258
- await asyncio.sleep(5)
259
-
260
- # Test 2: Without persistent memory (if disabled in config)
261
- await test_without_persistent_memory(config)
262
-
263
- except KeyboardInterrupt:
264
- print("\n\n⚠️ Test interrupted by user")
265
- except Exception as e:
266
- print(f"\n\n❌ Test failed with error: {e}")
267
- import traceback
268
- traceback.print_exc()
269
-
270
- print("\n" + "=" * 70)
271
- print("All tests completed!")
272
- print("=" * 70 + "\n")
273
-
274
-
275
- if __name__ == "__main__":
276
- import argparse
277
-
278
- parser = argparse.ArgumentParser(description="Test context window management with memory")
279
- parser.add_argument(
280
- "--config",
281
- type=str,
282
- help="Path to YAML config file (default: gpt5mini_gemini_context_window_management.yaml)"
283
- )
284
- args = parser.parse_args()
285
-
286
- asyncio.run(main(args.config))
@@ -1,97 +0,0 @@
1
- # Example Configuration: Multimodal Self-Evolution Analysis
2
- #
3
- # Use Case: MassGen agents analyze their own documentation videos to extract insights
4
- #
5
- # This configuration demonstrates MassGen's self-evolution capabilities through multimodal
6
- # understanding. Agents use understand_video and understand_image tools to analyze case study
7
- # videos, extract technical insights, and provide recommendations for documentation improvements.
8
- #
9
- # Run with:
10
- # uv run python -m massgen.cli --config massgen/configs/tools/multimodal/gpt5mini_gpt5nano_documentation_evolution.yaml "Analyze the MassGen case study video and extract key technical insights about the multi-agent collaboration capabilities demonstrated."
11
-
12
- agents:
13
- - id: "agent_a"
14
- backend:
15
- type: "openai"
16
- model: "gpt-5-mini"
17
- text:
18
- verbosity: "medium"
19
- reasoning:
20
- effort: "medium"
21
- summary: "auto"
22
- enable_web_search: true
23
- custom_tools:
24
- - name: ["understand_video"]
25
- category: "multimodal"
26
- path: "massgen/tool/_multimodal_tools/understand_video.py"
27
- function: ["understand_video"]
28
- - name: ["understand_image"]
29
- category: "multimodal"
30
- path: "massgen/tool/_multimodal_tools/understand_image.py"
31
- function: ["understand_image"]
32
- system_message: |
33
- You are an AI assistant analyzing MassGen's documentation and case studies to provide
34
- insights for self-evolution and improvement.
35
-
36
- You have access to multimodal understanding tools:
37
- - understand_video: Analyzes video content by extracting key frames
38
- - understand_image: Analyzes image content in detail
39
-
40
- Your goal is to extract technical insights, identify documentation quality patterns,
41
- and provide actionable recommendations for improvement. Focus on understanding
42
- how MassGen presents itself to users and how the documentation could better
43
- demonstrate self-evolution capabilities.
44
-
45
- - id: "agent_b"
46
- backend:
47
- type: "openai"
48
- model: "gpt-5-nano"
49
- text:
50
- verbosity: "medium"
51
- reasoning:
52
- effort: "medium"
53
- summary: "auto"
54
- enable_web_search: true
55
- custom_tools:
56
- - name: ["understand_video"]
57
- category: "multimodal"
58
- path: "massgen/tool/_multimodal_tools/understand_video.py"
59
- function: ["understand_video"]
60
- - name: ["understand_image"]
61
- category: "multimodal"
62
- path: "massgen/tool/_multimodal_tools/understand_image.py"
63
- function: ["understand_image"]
64
- system_message: |
65
- You are an AI assistant analyzing MassGen's documentation and case studies to provide
66
- insights for self-evolution and improvement.
67
-
68
- You have access to multimodal understanding tools:
69
- - understand_video: Analyzes video content by extracting key frames
70
- - understand_image: Analyzes image content in detail
71
-
72
- Your goal is to extract technical insights, identify documentation quality patterns,
73
- and provide actionable recommendations for improvement. Focus on understanding
74
- how MassGen presents itself to users and how the documentation could better
75
- demonstrate self-evolution capabilities.
76
-
77
- # Orchestrator-level configuration
78
- orchestrator:
79
- snapshot_storage: "snapshots"
80
- agent_temporary_workspace: "agent_temp"
81
-
82
- # Context paths at orchestrator level (for read-only source files)
83
- filesystem:
84
- context_paths:
85
- - path: "massgen/configs/resources/v0.1.3-example"
86
- permission: "read"
87
-
88
- ui:
89
- display_type: "rich_terminal"
90
- logging_enabled: true
91
-
92
- # What happens:
93
- # 1. Both agents receive the prompt to analyze a case study video
94
- # 2. Agents use understand_video to extract key frames and analyze content
95
- # 3. Agents use understand_image on specific frames for detailed analysis
96
- # 4. Agents collaborate to synthesize insights about MassGen's capabilities
97
- # 5. Final output includes technical insights and improvement recommendations