massgen 0.0.3__py3-none-any.whl → 0.1.0__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 (268) hide show
  1. massgen/__init__.py +142 -8
  2. massgen/adapters/__init__.py +29 -0
  3. massgen/adapters/ag2_adapter.py +483 -0
  4. massgen/adapters/base.py +183 -0
  5. massgen/adapters/tests/__init__.py +0 -0
  6. massgen/adapters/tests/test_ag2_adapter.py +439 -0
  7. massgen/adapters/tests/test_agent_adapter.py +128 -0
  8. massgen/adapters/utils/__init__.py +2 -0
  9. massgen/adapters/utils/ag2_utils.py +236 -0
  10. massgen/adapters/utils/tests/__init__.py +0 -0
  11. massgen/adapters/utils/tests/test_ag2_utils.py +138 -0
  12. massgen/agent_config.py +329 -55
  13. massgen/api_params_handler/__init__.py +10 -0
  14. massgen/api_params_handler/_api_params_handler_base.py +99 -0
  15. massgen/api_params_handler/_chat_completions_api_params_handler.py +176 -0
  16. massgen/api_params_handler/_claude_api_params_handler.py +113 -0
  17. massgen/api_params_handler/_response_api_params_handler.py +130 -0
  18. massgen/backend/__init__.py +39 -4
  19. massgen/backend/azure_openai.py +385 -0
  20. massgen/backend/base.py +341 -69
  21. massgen/backend/base_with_mcp.py +1102 -0
  22. massgen/backend/capabilities.py +386 -0
  23. massgen/backend/chat_completions.py +577 -130
  24. massgen/backend/claude.py +1033 -537
  25. massgen/backend/claude_code.py +1203 -0
  26. massgen/backend/cli_base.py +209 -0
  27. massgen/backend/docs/BACKEND_ARCHITECTURE.md +126 -0
  28. massgen/backend/{CLAUDE_API_RESEARCH.md → docs/CLAUDE_API_RESEARCH.md} +18 -18
  29. massgen/backend/{GEMINI_API_DOCUMENTATION.md → docs/GEMINI_API_DOCUMENTATION.md} +9 -9
  30. massgen/backend/docs/Gemini MCP Integration Analysis.md +1050 -0
  31. massgen/backend/docs/MCP_IMPLEMENTATION_CLAUDE_BACKEND.md +177 -0
  32. massgen/backend/docs/MCP_INTEGRATION_RESPONSE_BACKEND.md +352 -0
  33. massgen/backend/docs/OPENAI_GPT5_MODELS.md +211 -0
  34. massgen/backend/{OPENAI_RESPONSES_API_FORMAT.md → docs/OPENAI_RESPONSE_API_TOOL_CALLS.md} +3 -3
  35. massgen/backend/docs/OPENAI_response_streaming.md +20654 -0
  36. massgen/backend/docs/inference_backend.md +257 -0
  37. massgen/backend/docs/permissions_and_context_files.md +1085 -0
  38. massgen/backend/external.py +126 -0
  39. massgen/backend/gemini.py +1850 -241
  40. massgen/backend/grok.py +40 -156
  41. massgen/backend/inference.py +156 -0
  42. massgen/backend/lmstudio.py +171 -0
  43. massgen/backend/response.py +1095 -322
  44. massgen/chat_agent.py +131 -113
  45. massgen/cli.py +1560 -275
  46. massgen/config_builder.py +2396 -0
  47. massgen/configs/BACKEND_CONFIGURATION.md +458 -0
  48. massgen/configs/README.md +559 -216
  49. massgen/configs/ag2/ag2_case_study.yaml +27 -0
  50. massgen/configs/ag2/ag2_coder.yaml +34 -0
  51. massgen/configs/ag2/ag2_coder_case_study.yaml +36 -0
  52. massgen/configs/ag2/ag2_gemini.yaml +27 -0
  53. massgen/configs/ag2/ag2_groupchat.yaml +108 -0
  54. massgen/configs/ag2/ag2_groupchat_gpt.yaml +118 -0
  55. massgen/configs/ag2/ag2_single_agent.yaml +21 -0
  56. massgen/configs/basic/multi/fast_timeout_example.yaml +37 -0
  57. massgen/configs/basic/multi/gemini_4o_claude.yaml +31 -0
  58. massgen/configs/basic/multi/gemini_gpt5nano_claude.yaml +36 -0
  59. massgen/configs/{gemini_4o_claude.yaml → basic/multi/geminicode_4o_claude.yaml} +3 -3
  60. massgen/configs/basic/multi/geminicode_gpt5nano_claude.yaml +36 -0
  61. massgen/configs/basic/multi/glm_gemini_claude.yaml +25 -0
  62. massgen/configs/basic/multi/gpt4o_audio_generation.yaml +30 -0
  63. massgen/configs/basic/multi/gpt4o_image_generation.yaml +31 -0
  64. massgen/configs/basic/multi/gpt5nano_glm_qwen.yaml +26 -0
  65. massgen/configs/basic/multi/gpt5nano_image_understanding.yaml +26 -0
  66. massgen/configs/{three_agents_default.yaml → basic/multi/three_agents_default.yaml} +8 -4
  67. massgen/configs/basic/multi/three_agents_opensource.yaml +27 -0
  68. massgen/configs/basic/multi/three_agents_vllm.yaml +20 -0
  69. massgen/configs/basic/multi/two_agents_gemini.yaml +19 -0
  70. massgen/configs/{two_agents.yaml → basic/multi/two_agents_gpt5.yaml} +14 -6
  71. massgen/configs/basic/multi/two_agents_opensource_lmstudio.yaml +31 -0
  72. massgen/configs/basic/multi/two_qwen_vllm_sglang.yaml +28 -0
  73. massgen/configs/{single_agent.yaml → basic/single/single_agent.yaml} +1 -1
  74. massgen/configs/{single_flash2.5.yaml → basic/single/single_flash2.5.yaml} +1 -2
  75. massgen/configs/basic/single/single_gemini2.5pro.yaml +16 -0
  76. massgen/configs/basic/single/single_gpt4o_audio_generation.yaml +22 -0
  77. massgen/configs/basic/single/single_gpt4o_image_generation.yaml +22 -0
  78. massgen/configs/basic/single/single_gpt4o_video_generation.yaml +24 -0
  79. massgen/configs/basic/single/single_gpt5nano.yaml +20 -0
  80. massgen/configs/basic/single/single_gpt5nano_file_search.yaml +18 -0
  81. massgen/configs/basic/single/single_gpt5nano_image_understanding.yaml +17 -0
  82. massgen/configs/basic/single/single_gptoss120b.yaml +15 -0
  83. massgen/configs/basic/single/single_openrouter_audio_understanding.yaml +15 -0
  84. massgen/configs/basic/single/single_qwen_video_understanding.yaml +15 -0
  85. massgen/configs/debug/code_execution/command_filtering_blacklist.yaml +29 -0
  86. massgen/configs/debug/code_execution/command_filtering_whitelist.yaml +28 -0
  87. massgen/configs/debug/code_execution/docker_verification.yaml +29 -0
  88. massgen/configs/debug/skip_coordination_test.yaml +27 -0
  89. massgen/configs/debug/test_sdk_migration.yaml +17 -0
  90. massgen/configs/docs/DISCORD_MCP_SETUP.md +208 -0
  91. massgen/configs/docs/TWITTER_MCP_ENESCINAR_SETUP.md +82 -0
  92. massgen/configs/providers/azure/azure_openai_multi.yaml +21 -0
  93. massgen/configs/providers/azure/azure_openai_single.yaml +19 -0
  94. massgen/configs/providers/claude/claude.yaml +14 -0
  95. massgen/configs/providers/gemini/gemini_gpt5nano.yaml +28 -0
  96. massgen/configs/providers/local/lmstudio.yaml +11 -0
  97. massgen/configs/providers/openai/gpt5.yaml +46 -0
  98. massgen/configs/providers/openai/gpt5_nano.yaml +46 -0
  99. massgen/configs/providers/others/grok_single_agent.yaml +19 -0
  100. massgen/configs/providers/others/zai_coding_team.yaml +108 -0
  101. massgen/configs/providers/others/zai_glm45.yaml +12 -0
  102. massgen/configs/{creative_team.yaml → teams/creative/creative_team.yaml} +16 -6
  103. massgen/configs/{travel_planning.yaml → teams/creative/travel_planning.yaml} +16 -6
  104. massgen/configs/{news_analysis.yaml → teams/research/news_analysis.yaml} +16 -6
  105. massgen/configs/{research_team.yaml → teams/research/research_team.yaml} +15 -7
  106. massgen/configs/{technical_analysis.yaml → teams/research/technical_analysis.yaml} +16 -6
  107. massgen/configs/tools/code-execution/basic_command_execution.yaml +25 -0
  108. massgen/configs/tools/code-execution/code_execution_use_case_simple.yaml +41 -0
  109. massgen/configs/tools/code-execution/docker_claude_code.yaml +32 -0
  110. massgen/configs/tools/code-execution/docker_multi_agent.yaml +32 -0
  111. massgen/configs/tools/code-execution/docker_simple.yaml +29 -0
  112. massgen/configs/tools/code-execution/docker_with_resource_limits.yaml +32 -0
  113. massgen/configs/tools/code-execution/multi_agent_playwright_automation.yaml +57 -0
  114. massgen/configs/tools/filesystem/cc_gpt5_gemini_filesystem.yaml +34 -0
  115. massgen/configs/tools/filesystem/claude_code_context_sharing.yaml +68 -0
  116. massgen/configs/tools/filesystem/claude_code_flash2.5.yaml +43 -0
  117. massgen/configs/tools/filesystem/claude_code_flash2.5_gptoss.yaml +49 -0
  118. massgen/configs/tools/filesystem/claude_code_gpt5nano.yaml +31 -0
  119. massgen/configs/tools/filesystem/claude_code_single.yaml +40 -0
  120. massgen/configs/tools/filesystem/fs_permissions_test.yaml +87 -0
  121. massgen/configs/tools/filesystem/gemini_gemini_workspace_cleanup.yaml +54 -0
  122. massgen/configs/tools/filesystem/gemini_gpt5_filesystem_casestudy.yaml +30 -0
  123. massgen/configs/tools/filesystem/gemini_gpt5nano_file_context_path.yaml +43 -0
  124. massgen/configs/tools/filesystem/gemini_gpt5nano_protected_paths.yaml +45 -0
  125. massgen/configs/tools/filesystem/gpt5mini_cc_fs_context_path.yaml +31 -0
  126. massgen/configs/tools/filesystem/grok4_gpt5_gemini_filesystem.yaml +32 -0
  127. massgen/configs/tools/filesystem/multiturn/grok4_gpt5_claude_code_filesystem_multiturn.yaml +58 -0
  128. massgen/configs/tools/filesystem/multiturn/grok4_gpt5_gemini_filesystem_multiturn.yaml +58 -0
  129. massgen/configs/tools/filesystem/multiturn/two_claude_code_filesystem_multiturn.yaml +47 -0
  130. massgen/configs/tools/filesystem/multiturn/two_gemini_flash_filesystem_multiturn.yaml +48 -0
  131. massgen/configs/tools/mcp/claude_code_discord_mcp_example.yaml +27 -0
  132. massgen/configs/tools/mcp/claude_code_simple_mcp.yaml +35 -0
  133. massgen/configs/tools/mcp/claude_code_twitter_mcp_example.yaml +32 -0
  134. massgen/configs/tools/mcp/claude_mcp_example.yaml +24 -0
  135. massgen/configs/tools/mcp/claude_mcp_test.yaml +27 -0
  136. massgen/configs/tools/mcp/five_agents_travel_mcp_test.yaml +157 -0
  137. massgen/configs/tools/mcp/five_agents_weather_mcp_test.yaml +103 -0
  138. massgen/configs/tools/mcp/gemini_mcp_example.yaml +24 -0
  139. massgen/configs/tools/mcp/gemini_mcp_filesystem_test.yaml +23 -0
  140. massgen/configs/tools/mcp/gemini_mcp_filesystem_test_sharing.yaml +23 -0
  141. massgen/configs/tools/mcp/gemini_mcp_filesystem_test_single_agent.yaml +17 -0
  142. massgen/configs/tools/mcp/gemini_mcp_filesystem_test_with_claude_code.yaml +24 -0
  143. massgen/configs/tools/mcp/gemini_mcp_test.yaml +27 -0
  144. massgen/configs/tools/mcp/gemini_notion_mcp.yaml +52 -0
  145. massgen/configs/tools/mcp/gpt5_nano_mcp_example.yaml +24 -0
  146. massgen/configs/tools/mcp/gpt5_nano_mcp_test.yaml +27 -0
  147. massgen/configs/tools/mcp/gpt5mini_claude_code_discord_mcp_example.yaml +38 -0
  148. massgen/configs/tools/mcp/gpt_oss_mcp_example.yaml +25 -0
  149. massgen/configs/tools/mcp/gpt_oss_mcp_test.yaml +28 -0
  150. massgen/configs/tools/mcp/grok3_mini_mcp_example.yaml +24 -0
  151. massgen/configs/tools/mcp/grok3_mini_mcp_test.yaml +27 -0
  152. massgen/configs/tools/mcp/multimcp_gemini.yaml +111 -0
  153. massgen/configs/tools/mcp/qwen_api_mcp_example.yaml +25 -0
  154. massgen/configs/tools/mcp/qwen_api_mcp_test.yaml +28 -0
  155. massgen/configs/tools/mcp/qwen_local_mcp_example.yaml +24 -0
  156. massgen/configs/tools/mcp/qwen_local_mcp_test.yaml +27 -0
  157. massgen/configs/tools/planning/five_agents_discord_mcp_planning_mode.yaml +140 -0
  158. massgen/configs/tools/planning/five_agents_filesystem_mcp_planning_mode.yaml +151 -0
  159. massgen/configs/tools/planning/five_agents_notion_mcp_planning_mode.yaml +151 -0
  160. massgen/configs/tools/planning/five_agents_twitter_mcp_planning_mode.yaml +155 -0
  161. massgen/configs/tools/planning/gpt5_mini_case_study_mcp_planning_mode.yaml +73 -0
  162. massgen/configs/tools/web-search/claude_streamable_http_test.yaml +43 -0
  163. massgen/configs/tools/web-search/gemini_streamable_http_test.yaml +43 -0
  164. massgen/configs/tools/web-search/gpt5_mini_streamable_http_test.yaml +43 -0
  165. massgen/configs/tools/web-search/gpt_oss_streamable_http_test.yaml +44 -0
  166. massgen/configs/tools/web-search/grok3_mini_streamable_http_test.yaml +43 -0
  167. massgen/configs/tools/web-search/qwen_api_streamable_http_test.yaml +44 -0
  168. massgen/configs/tools/web-search/qwen_local_streamable_http_test.yaml +43 -0
  169. massgen/coordination_tracker.py +708 -0
  170. massgen/docker/README.md +462 -0
  171. massgen/filesystem_manager/__init__.py +21 -0
  172. massgen/filesystem_manager/_base.py +9 -0
  173. massgen/filesystem_manager/_code_execution_server.py +545 -0
  174. massgen/filesystem_manager/_docker_manager.py +477 -0
  175. massgen/filesystem_manager/_file_operation_tracker.py +248 -0
  176. massgen/filesystem_manager/_filesystem_manager.py +813 -0
  177. massgen/filesystem_manager/_path_permission_manager.py +1261 -0
  178. massgen/filesystem_manager/_workspace_tools_server.py +1815 -0
  179. massgen/formatter/__init__.py +10 -0
  180. massgen/formatter/_chat_completions_formatter.py +284 -0
  181. massgen/formatter/_claude_formatter.py +235 -0
  182. massgen/formatter/_formatter_base.py +156 -0
  183. massgen/formatter/_response_formatter.py +263 -0
  184. massgen/frontend/__init__.py +1 -2
  185. massgen/frontend/coordination_ui.py +471 -286
  186. massgen/frontend/displays/base_display.py +56 -11
  187. massgen/frontend/displays/create_coordination_table.py +1956 -0
  188. massgen/frontend/displays/rich_terminal_display.py +1259 -619
  189. massgen/frontend/displays/simple_display.py +9 -4
  190. massgen/frontend/displays/terminal_display.py +27 -68
  191. massgen/logger_config.py +681 -0
  192. massgen/mcp_tools/README.md +232 -0
  193. massgen/mcp_tools/__init__.py +105 -0
  194. massgen/mcp_tools/backend_utils.py +1035 -0
  195. massgen/mcp_tools/circuit_breaker.py +195 -0
  196. massgen/mcp_tools/client.py +894 -0
  197. massgen/mcp_tools/config_validator.py +138 -0
  198. massgen/mcp_tools/docs/circuit_breaker.md +646 -0
  199. massgen/mcp_tools/docs/client.md +950 -0
  200. massgen/mcp_tools/docs/config_validator.md +478 -0
  201. massgen/mcp_tools/docs/exceptions.md +1165 -0
  202. massgen/mcp_tools/docs/security.md +854 -0
  203. massgen/mcp_tools/exceptions.py +338 -0
  204. massgen/mcp_tools/hooks.py +212 -0
  205. massgen/mcp_tools/security.py +780 -0
  206. massgen/message_templates.py +342 -64
  207. massgen/orchestrator.py +1515 -241
  208. massgen/stream_chunk/__init__.py +35 -0
  209. massgen/stream_chunk/base.py +92 -0
  210. massgen/stream_chunk/multimodal.py +237 -0
  211. massgen/stream_chunk/text.py +162 -0
  212. massgen/tests/mcp_test_server.py +150 -0
  213. massgen/tests/multi_turn_conversation_design.md +0 -8
  214. massgen/tests/test_azure_openai_backend.py +156 -0
  215. massgen/tests/test_backend_capabilities.py +262 -0
  216. massgen/tests/test_backend_event_loop_all.py +179 -0
  217. massgen/tests/test_chat_completions_refactor.py +142 -0
  218. massgen/tests/test_claude_backend.py +15 -28
  219. massgen/tests/test_claude_code.py +268 -0
  220. massgen/tests/test_claude_code_context_sharing.py +233 -0
  221. massgen/tests/test_claude_code_orchestrator.py +175 -0
  222. massgen/tests/test_cli_backends.py +180 -0
  223. massgen/tests/test_code_execution.py +679 -0
  224. massgen/tests/test_external_agent_backend.py +134 -0
  225. massgen/tests/test_final_presentation_fallback.py +237 -0
  226. massgen/tests/test_gemini_planning_mode.py +351 -0
  227. massgen/tests/test_grok_backend.py +7 -10
  228. massgen/tests/test_http_mcp_server.py +42 -0
  229. massgen/tests/test_integration_simple.py +198 -0
  230. massgen/tests/test_mcp_blocking.py +125 -0
  231. massgen/tests/test_message_context_building.py +29 -47
  232. massgen/tests/test_orchestrator_final_presentation.py +48 -0
  233. massgen/tests/test_path_permission_manager.py +2087 -0
  234. massgen/tests/test_rich_terminal_display.py +14 -13
  235. massgen/tests/test_timeout.py +133 -0
  236. massgen/tests/test_v3_3agents.py +11 -12
  237. massgen/tests/test_v3_simple.py +8 -13
  238. massgen/tests/test_v3_three_agents.py +11 -18
  239. massgen/tests/test_v3_two_agents.py +8 -13
  240. massgen/token_manager/__init__.py +7 -0
  241. massgen/token_manager/token_manager.py +400 -0
  242. massgen/utils.py +52 -16
  243. massgen/v1/agent.py +45 -91
  244. massgen/v1/agents.py +18 -53
  245. massgen/v1/backends/gemini.py +50 -153
  246. massgen/v1/backends/grok.py +21 -54
  247. massgen/v1/backends/oai.py +39 -111
  248. massgen/v1/cli.py +36 -93
  249. massgen/v1/config.py +8 -12
  250. massgen/v1/logging.py +43 -127
  251. massgen/v1/main.py +18 -32
  252. massgen/v1/orchestrator.py +68 -209
  253. massgen/v1/streaming_display.py +62 -163
  254. massgen/v1/tools.py +8 -12
  255. massgen/v1/types.py +9 -23
  256. massgen/v1/utils.py +5 -23
  257. massgen-0.1.0.dist-info/METADATA +1245 -0
  258. massgen-0.1.0.dist-info/RECORD +273 -0
  259. massgen-0.1.0.dist-info/entry_points.txt +2 -0
  260. massgen/frontend/logging/__init__.py +0 -9
  261. massgen/frontend/logging/realtime_logger.py +0 -197
  262. massgen-0.0.3.dist-info/METADATA +0 -568
  263. massgen-0.0.3.dist-info/RECORD +0 -76
  264. massgen-0.0.3.dist-info/entry_points.txt +0 -2
  265. /massgen/backend/{Function calling openai responses.md → docs/Function calling openai responses.md} +0 -0
  266. {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/WHEEL +0 -0
  267. {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/licenses/LICENSE +0 -0
  268. {massgen-0.0.3.dist-info → massgen-0.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,462 @@
1
+ # MassGen Docker Runtime for Code Execution
2
+
3
+ This directory contains Docker configuration for isolated command execution in MassGen.
4
+
5
+ ## Overview
6
+
7
+ Docker mode provides strong isolation for command execution by running commands inside persistent containers while keeping MCP servers on the host for security.
8
+
9
+ **Key Benefits:**
10
+ - 🔒 **Isolation:** Commands execute in containers, can't access host filesystem
11
+ - 📦 **State Persistence:** Packages stay installed across turns (persistent containers)
12
+ - 🚀 **Easy Setup:** Single command to build, simple config to enable
13
+ - 🛡️ **Security:** Read-only context mounts, optional network isolation, resource limits
14
+ - 🧪 **Clean Environment:** Each agent gets its own isolated container
15
+
16
+ ## Quick Start
17
+
18
+ ### 1. Prerequisites
19
+
20
+ - **Docker installed and running**
21
+ ```bash
22
+ docker --version # Should show Docker Engine >= 28.0.0
23
+ docker ps # Should connect without errors
24
+ ```
25
+
26
+ **Recommended:** Docker Engine 28.0.0+ ([release notes](https://docs.docker.com/engine/release-notes/28/))
27
+
28
+ - **Python docker library (optional, for Docker mode)**
29
+ ```bash
30
+ # Install via optional dependency group
31
+ uv pip install -e ".[docker]"
32
+
33
+ # Or install directly
34
+ pip install docker>=7.0.0
35
+ ```
36
+
37
+ ### 2. Build the Docker Image
38
+
39
+ From the repository root:
40
+
41
+ ```bash
42
+ bash massgen/docker/build.sh
43
+ ```
44
+
45
+ This builds `massgen/mcp-runtime:latest` (~400-500MB).
46
+
47
+ ### 3. Enable in Configuration
48
+
49
+ **Minimal setup:**
50
+ ```yaml
51
+ agent:
52
+ backend:
53
+ cwd: "workspace"
54
+ enable_mcp_command_line: true
55
+ command_line_execution_mode: "docker" # This enables Docker mode!
56
+ ```
57
+
58
+ **That's it!** Container will be created automatically when orchestration starts.
59
+
60
+ ## Configuration Options
61
+
62
+ ### Basic Docker Mode
63
+
64
+ ```yaml
65
+ agent:
66
+ backend:
67
+ cwd: "workspace"
68
+ enable_mcp_command_line: true
69
+ command_line_execution_mode: "docker"
70
+ ```
71
+
72
+ ### With Resource Limits and Network
73
+
74
+ ```yaml
75
+ agent:
76
+ backend:
77
+ cwd: "workspace"
78
+ enable_mcp_command_line: true
79
+ command_line_execution_mode: "docker"
80
+
81
+ # Docker configuration
82
+ command_line_docker_image: "massgen/mcp-runtime:latest" # Default
83
+ command_line_docker_memory_limit: "2g" # Limit memory
84
+ command_line_docker_cpu_limit: 4.0 # Limit CPU cores
85
+ command_line_docker_network_mode: "bridge" # Enable network
86
+ ```
87
+
88
+ ### Multi-Agent Docker Execution
89
+
90
+ ```yaml
91
+ agents:
92
+ - id: "agent_a"
93
+ backend:
94
+ type: "openai"
95
+ model: "gpt-5-mini"
96
+ cwd: "workspace1"
97
+ enable_mcp_command_line: true
98
+ command_line_execution_mode: "docker"
99
+
100
+ - id: "agent_b"
101
+ backend:
102
+ type: "gemini"
103
+ model: "gemini-2.5-pro"
104
+ cwd: "workspace2"
105
+ enable_mcp_command_line: true
106
+ command_line_execution_mode: "docker"
107
+ ```
108
+
109
+ ## Configuration Parameters
110
+
111
+ | Parameter | Default | Description |
112
+ |-----------|---------|-------------|
113
+ | `command_line_execution_mode` | `"local"` | `"local"` or `"docker"` |
114
+ | `command_line_docker_image` | `"massgen/mcp-runtime:latest"` | Docker image to use |
115
+ | `command_line_docker_memory_limit` | None | Memory limit (e.g., `"2g"`, `"512m"`) |
116
+ | `command_line_docker_cpu_limit` | None | CPU cores limit (e.g., `2.0`) |
117
+ | `command_line_docker_network_mode` | `"none"` | `"none"`, `"bridge"`, or `"host"` |
118
+
119
+ ## How It Works
120
+
121
+ ### Container Lifecycle
122
+
123
+ ```
124
+ Orchestration Start
125
+
126
+ FilesystemManager.setup_orchestration_paths()
127
+ ├── Creates persistent container: massgen-{agent_id}
128
+ ├── Mounts workspace at SAME host path (rw) - path transparency
129
+ ├── Mounts context paths at SAME host paths (ro by default)
130
+ └── Mounts temp_workspace at SAME host path (ro)
131
+
132
+ Agent Turn 1
133
+ ├── execute_command("pip install click")
134
+ └── docker exec massgen-{agent_id} sh -c "pip install click"
135
+
136
+ Agent Turn 2
137
+ ├── execute_command("python -c 'import click; print(click.__version__)'")
138
+ └── docker exec massgen-{agent_id} sh -c "python -c 'import click; print(click.__version__)'"
139
+ (click is available - container persisted!)
140
+
141
+ Orchestration End
142
+ ├── FilesystemManager.cleanup()
143
+ └── Stops and removes container
144
+ ```
145
+
146
+ ### Key Design Decisions
147
+
148
+ 1. **Persistent Containers**
149
+ - One container per agent for entire orchestration
150
+ - State persists across turns (packages, files, etc.)
151
+ - Destroyed only at orchestration end
152
+
153
+ 2. **MCP Servers on Host**
154
+ - Code execution MCP server runs on host (not in container)
155
+ - Creates own Docker client connection
156
+ - Executes commands via `docker exec`
157
+ - **Why:** Keeps MCP server source code secure, not exposed to agents
158
+
159
+ 3. **Path Transparency (Volume Mounting)**
160
+ - Paths mounted at SAME location as host (Docker invisible to LLM)
161
+ - Workspace: Read-write access to agent's workspace
162
+ - Context paths: Read-only or read-write based on config
163
+ - Temp workspace: Read-only access to other agents' outputs
164
+
165
+ ## Docker Image Details
166
+
167
+ ### Base Image: massgen/mcp-runtime:latest
168
+
169
+ **Contents:**
170
+ - Base: Python 3.11-slim
171
+ - System packages: git, curl, build-essential, Node.js 20.x
172
+ - Python packages: pytest, requests, numpy, pandas
173
+ - User: non-root (massgen, UID 1000)
174
+ - Working directory: /workspace
175
+
176
+ **Size:** ~400-500MB (compressed)
177
+
178
+ ### Custom Images
179
+
180
+ To add more packages, extend the base image:
181
+
182
+ ```dockerfile
183
+ FROM massgen/mcp-runtime:latest
184
+
185
+ # Install additional system packages
186
+ USER root
187
+ RUN apt-get update && apt-get install -y --no-install-recommends \
188
+ postgresql-client \
189
+ && rm -rf /var/lib/apt/lists/*
190
+
191
+ # Install additional Python packages
192
+ USER massgen
193
+ RUN pip install --no-cache-dir sqlalchemy psycopg2-binary
194
+
195
+ WORKDIR /workspace
196
+ ```
197
+
198
+ Build and use:
199
+ ```bash
200
+ docker build -t my-custom-runtime:latest -f Dockerfile.custom .
201
+ ```
202
+
203
+ ```yaml
204
+ command_line_docker_image: "my-custom-runtime:latest"
205
+ ```
206
+
207
+ ## Security Features
208
+
209
+ ### Filesystem Isolation
210
+ - Containers can only access mounted volumes
211
+ - Workspace: Agent's workspace directory only
212
+ - Context paths: Read-only by default (configurable per path)
213
+ - No access to host filesystem outside mounts
214
+
215
+ ### Network Isolation (Default)
216
+ - `network_mode: "none"` - No network access (default, most secure)
217
+ - `network_mode: "bridge"` - Internet access enabled
218
+ - `network_mode: "host"` - Full host network (use with caution)
219
+
220
+ ### Resource Limits
221
+ - Memory limits prevent memory exhaustion attacks
222
+ - CPU limits prevent CPU exhaustion attacks
223
+ - Enforced at container level by Docker runtime
224
+
225
+ ### Process Isolation
226
+ - Commands run as non-root user (massgen, UID 1000)
227
+ - Cannot affect host processes
228
+ - Cannot access other agent containers
229
+
230
+ ### Combined with Other Security Layers
231
+ 1. AG2-inspired command sanitization (rm -rf /, sudo, etc.)
232
+ 2. Command filtering (whitelist/blacklist)
233
+ 3. Docker container isolation ← **This layer**
234
+ 4. Volume mount permissions (ro/rw)
235
+ 5. PathPermissionManager hooks
236
+
237
+ ## Usage Examples
238
+
239
+ ### Example 1: Python Development
240
+
241
+ ```yaml
242
+ agent:
243
+ backend:
244
+ model: "gpt-4o-mini"
245
+ cwd: "workspace"
246
+ enable_mcp_command_line: true
247
+ command_line_execution_mode: "docker"
248
+ ```
249
+
250
+ ```bash
251
+ uv run python -m massgen.cli --config config.yaml "Write and test a sorting algorithm"
252
+ ```
253
+
254
+ Agent can:
255
+ - Install packages: `pip install numpy`
256
+ - Run code: `python sort.py`
257
+ - Run tests: `pytest tests/`
258
+ - All isolated in container!
259
+
260
+ ### Example 2: With Resource Constraints
261
+
262
+ ```yaml
263
+ agent:
264
+ backend:
265
+ cwd: "workspace"
266
+ enable_mcp_command_line: true
267
+ command_line_execution_mode: "docker"
268
+ command_line_docker_memory_limit: "1g" # Limit memory
269
+ command_line_docker_cpu_limit: 1.0 # Limit to 1 CPU
270
+ command_line_docker_network_mode: "none" # No network
271
+ ```
272
+
273
+ Good for untrusted or resource-intensive tasks.
274
+
275
+ ### Example 3: With Network Access
276
+
277
+ ```yaml
278
+ agent:
279
+ backend:
280
+ cwd: "workspace"
281
+ enable_mcp_command_line: true
282
+ command_line_execution_mode: "docker"
283
+ command_line_docker_network_mode: "bridge" # Enable network
284
+ ```
285
+
286
+ ```bash
287
+ uv run python -m massgen.cli --config config.yaml "Fetch data from an API and analyze it"
288
+ ```
289
+
290
+ Agent can make HTTP requests from inside container.
291
+
292
+ ## Troubleshooting
293
+
294
+ ### Error: "Docker is not installed"
295
+
296
+ **Symptom:** `RuntimeError: Docker Python library not available`
297
+
298
+ **Solution:**
299
+ ```bash
300
+ pip install docker>=7.0.0
301
+ ```
302
+
303
+ ### Error: "Failed to connect to Docker"
304
+
305
+ **Symptom:** `RuntimeError: Failed to connect to Docker: ...`
306
+
307
+ **Possible causes:**
308
+ 1. Docker daemon not running
309
+ ```bash
310
+ # Check if Docker is running
311
+ docker ps
312
+
313
+ # Start Docker Desktop (Mac/Windows) or daemon (Linux)
314
+ ```
315
+
316
+ 2. Permission issues (Linux)
317
+ ```bash
318
+ # Add user to docker group
319
+ sudo usermod -aG docker $USER
320
+ # Log out and back in for changes to take effect
321
+ ```
322
+
323
+ 3. Custom Docker socket path
324
+ ```bash
325
+ # If Docker uses a non-standard socket path, set DOCKER_HOST
326
+ export DOCKER_HOST=unix:///path/to/your/docker.sock
327
+
328
+ # Or for TCP connections
329
+ export DOCKER_HOST=tcp://localhost:2375
330
+ ```
331
+
332
+ The Docker SDK auto-detects socket paths, but you can override with `DOCKER_HOST` if needed.
333
+
334
+ ### Error: "Image not found"
335
+
336
+ **Symptom:** `RuntimeError: Failed to pull Docker image ...`
337
+
338
+ **Solution:** Build the image locally
339
+ ```bash
340
+ bash massgen/docker/build.sh
341
+ ```
342
+
343
+ Or pull if available:
344
+ ```bash
345
+ docker pull massgen/mcp-runtime:latest
346
+ ```
347
+
348
+ ### Container Name Conflict
349
+
350
+ **Symptom:** `Error: The container name "/massgen-{agent_id}" is already in use`
351
+
352
+ **Solution:** This is auto-handled by DockerManager, but if persists:
353
+ ```bash
354
+ # Remove conflicting container
355
+ docker rm -f massgen-{agent_id}
356
+
357
+ # Or remove all massgen containers
358
+ docker ps -a | grep massgen | awk '{print $1}' | xargs docker rm -f
359
+ ```
360
+
361
+ ### Performance Issues
362
+
363
+ **Symptom:** Commands are slow
364
+
365
+ **Solutions:**
366
+ 1. Increase resource limits:
367
+ ```yaml
368
+ command_line_docker_memory_limit: "4g"
369
+ command_line_docker_cpu_limit: 4.0
370
+ ```
371
+
372
+ 2. Use custom image with pre-installed packages (see Custom Images section)
373
+
374
+ 3. Check Docker Desktop resource settings (Mac/Windows)
375
+
376
+ ### Permission Errors in Container
377
+
378
+ **Symptom:** `Permission denied` when writing files
379
+
380
+ **Cause:** User ID mismatch between host and container
381
+
382
+ **Solution:** The container runs as UID 1000. Ensure workspace has correct permissions:
383
+ ```bash
384
+ chmod -R 755 workspace
385
+ ```
386
+
387
+ Or build custom image with matching UID:
388
+ ```dockerfile
389
+ RUN useradd -m -u $(id -u) -s /bin/bash massgen
390
+ ```
391
+
392
+ ## Debugging
393
+
394
+ ### Inspect Running Container
395
+
396
+ ```bash
397
+ # List containers
398
+ docker ps | grep massgen
399
+
400
+ # View logs in real-time
401
+ docker logs -f massgen-{agent_id}
402
+
403
+ # Execute interactive shell
404
+ docker exec -it massgen-{agent_id} /bin/bash
405
+ ```
406
+
407
+ ### Check Container Resource Usage
408
+
409
+ ```bash
410
+ docker stats massgen-{agent_id}
411
+ ```
412
+
413
+ ### Manual Container Management
414
+
415
+ ```bash
416
+ # Stop container
417
+ docker stop massgen-{agent_id}
418
+
419
+ # Remove container
420
+ docker rm massgen-{agent_id}
421
+
422
+ # Remove all stopped containers
423
+ docker container prune -f
424
+ ```
425
+
426
+ ## Comparison: Local vs Docker Mode
427
+
428
+ | Aspect | Local Mode | Docker Mode |
429
+ |--------|-----------|-------------|
430
+ | **Setup** | None required | Docker + image build |
431
+ | **Performance** | Fast (direct execution) | Slight overhead (~100-200ms startup) |
432
+ | **Isolation** | Pattern-based (circumventable) | Container-based (strong) |
433
+ | **Network** | Full host network | Configurable (none/bridge/host) |
434
+ | **Resource Limits** | OS-level only | Docker-enforced (memory, CPU) |
435
+ | **State Persistence** | Direct filesystem | Container + volumes |
436
+ | **Security** | Medium | High |
437
+ | **Best For** | Development, trusted code | Production, untrusted code |
438
+
439
+ ## Best Practices
440
+
441
+ 1. **Use Docker mode for untrusted or production workloads**
442
+ 2. **Set resource limits** to prevent abuse
443
+ 3. **Use network_mode="none"** unless network is required
444
+ 4. **Build custom images** for frequently used packages (faster)
445
+ 5. **Monitor container logs** for debugging
446
+ 6. **Clean up regularly** if testing (containers auto-cleaned normally)
447
+
448
+ ## Examples Directory
449
+
450
+ See `massgen/configs/tools/code-execution/` for example configurations:
451
+ - `docker_simple.yaml` - Minimal Docker setup
452
+ - `docker_with_resource_limits.yaml` - Memory/CPU limits with network access
453
+ - `docker_multi_agent.yaml` - Multi-agent execution with Docker isolation
454
+ - `docker_verification.yaml` - Verify Docker isolation is working
455
+
456
+ ## References
457
+
458
+ - [Docker Documentation](https://docs.docker.com/)
459
+ - [Docker Python SDK](https://docker-py.readthedocs.io/)
460
+ - [Docker Best Practices](https://docs.docker.com/develop/dev-best-practices/)
461
+ - Design Document: `docs/dev_notes/DOCKER_CODE_EXECUTION_DESIGN.md`
462
+ - Build Script: `massgen/docker/build.sh`
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Filesystem management utilities for MassGen backend."""
3
+ from ._base import Permission
4
+ from ._file_operation_tracker import FileOperationTracker
5
+ from ._filesystem_manager import FilesystemManager
6
+ from ._path_permission_manager import (
7
+ ManagedPath,
8
+ PathPermissionManager,
9
+ PathPermissionManagerHook,
10
+ )
11
+ from ._workspace_tools_server import get_copy_file_pairs
12
+
13
+ __all__ = [
14
+ "FileOperationTracker",
15
+ "FilesystemManager",
16
+ "ManagedPath",
17
+ "PathPermissionManager",
18
+ "PathPermissionManagerHook",
19
+ "Permission",
20
+ "get_copy_file_pairs",
21
+ ]
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ from enum import Enum
3
+
4
+
5
+ class Permission(Enum):
6
+ """File access permission types."""
7
+
8
+ READ = "read"
9
+ WRITE = "write"