You are orchestrating a MassGen multi-agent run. Multiple LLM agents will collaborate on the user's task through answer generation, voting, and consensus.
Pre-Flight Checks
Before doing anything else, verify the environment:
- Read
.massgen-quality/environment.json— checkmassgen.availableand notemassgen.source("uvx"or"local:/path") for Step 3 launch method - If massgen unavailable: tell the user and provide install instructions:
cd /path/to/massgen && uv sync - Read
api_keysfrom.massgen-quality/environment.json— check which providers are authenticated. The hook checks both environment variables AND.envfiles (at$CWD/.envand$HOME/.env). If all keys show missing but the user says keys exist, check for a.envfile and suggest creating one:
MassGen Docker configs already use# .env (at project root or $HOME) OPENAI_API_KEY=sk-... GOOGLE_API_KEY=AI... ANTHROPIC_API_KEY=sk-ant-...env_file: .envfor credential injection, so a.envfile ensures keys are available in containers too. - Map requested backends to required keys:
openai,codex→openaikeygemini→googlekeyclaude,claude_code→anthropickeygrok→xaikey
- Warn if any requested backend lacks its API key — skip that backend
- If ALL backends lack keys: abort with clear message
Docker checks (unless --no-docker)
Docker is the default. Check:
- Read
dockerfrom.massgen-quality/environment.json— checkdocker.available - If Docker unavailable: warn, suggest
--no-docker, or ask user to start Docker - Check
docker.image_available— if false:docker pull ghcr.io/massgen/mcp-runtime-sudo:latest # or build locally: cd /path/to/massgen && bash massgen/docker/build.sh --sudo - If user passed
--no-docker: skip Docker config, use local execution mode
Step 1: Parse Arguments
Parse from the user's input:
query: the task/question for agents--models: list ofbackend/modelpairs (e.g.,codex/gpt-5.4 gemini/gemini-3.1-pro-preview)--no-docker: disable Docker containerization--max-duration N: override orchestrator timeout (default: 1800s)
If no --models specified, use defaults based on available API keys:
- If openai + google available:
openai/gpt-5.4 gemini/gemini-3.1-pro-preview(default pair) - If only openai:
openai/gpt-5.4 - If only google:
gemini/gemini-3.1-pro-preview - Include additional backends (claude, grok) as available
Note: coding agent backends (codex, claude_code) require Docker mode.
Default to openai and gemini backends which work without Docker.
Step 2: Generate YAML Config
Write config to .massgen-quality/sessions/<session_id>/configs/run_<timestamp>.yaml
(where <session_id> is run_<YYYYMMDD_HHMMSS>).
For each backend/model pair, create an agent entry. See
references/config-templates.md for the full template.
context_paths (critical): Lives under orchestrator:, not agents:. Each
entry is a {path, permission} dict. Agents can only see files in paths listed
here. If the task involves specific files or a project directory, you MUST
include the absolute path. Use read for reference material, write if agents
should modify files:
orchestrator:
context_paths:
- path: "/absolute/path/to/project"
permission: "read"
Key settings:
ui.display_type: "simple"(must be valid;--automationoverrides to silent)ui.logging_enabled: true
If Docker mode (not --no-docker), add per-agent:
enable_code_based_tools: trueexclude_file_operation_mcps: trueenable_mcp_command_line: truecommand_line_execution_mode: dockercommand_line_docker_image: ghcr.io/massgen/mcp-runtime-sudo:latestcommand_line_docker_credentialswith env_file and API keys
If --no-docker (or Docker unavailable): use local CLI execution instead:
enable_mcp_command_line: truecommand_line_execution_mode: local- Do NOT include Docker-specific fields (image, network, sudo, credentials) Agents can run commands and edit files directly on the host via local execution.
Step 3: Launch MassGen
MassGen runs take a while (often 5-30 minutes). Always use run_in_background: true
on the Bash tool — the hard 10-minute timeout will kill foreground runs.
Read plugin_dir from .massgen-quality/environment.json. Use the massgen
wrapper which handles API key sourcing and massgen resolution automatically:
bash "<plugin_dir>/scripts/run-massgen.sh" --automation \
--config "<config_path>" \
"<query>" 2>&1
Parse stderr output for automation status lines:
LOG_DIR: <path>— the session log directorySTATUS: <path>— path tostatus.jsonfor monitoring
Launch sequence:
- Run the command with
run_in_background: trueon the Bash tool - Tell the user the run is in progress and will take a while
- Spawn a
massgen-monitorbackground agent with the PID and LOG_DIR - The user will be notified on completion
Step 4: Extract and Present Results
Find status.json at <LOG_DIR>/turn_0/attempt_0/status.json (or latest turn/attempt).
Read and extract:
results.winner— the winning agent IDresults.votes— vote distributionagents.<id>.answer— each agent's answeragents.<id>.status— each agent's final statusmeta.elapsed_seconds— durationcosts.total_estimated_cost— cost estimate
Present to the user:
- Winning answer (from the consensus winner)
- Vote distribution (which agents voted for whom)
- Per-agent answers (collapsed/summarized if long)
- Duration and cost
If the user wants to use the answer, offer to write it to a file or apply it.
Error Handling
- Exit code 1 (config error): Check the YAML config for syntax issues. Read the massgen log for details.
- Exit code 2 (execution error): An agent failed. Read
status.jsonforagents.<id>.errordetails. - Exit code 3 (timeout): Increase
--max-durationor reduce agent count. - massgen not found: Provide install instructions.
- Docker not available: Suggest
--no-dockeror starting Docker.