remoting/tools/magi-mode/SKILL.md
This skill implements the MAGI multi-agent debate protocol to resolve complex, high-stakes, or ambiguous problems. It utilizes a "Consensus Loop" of specialized sub-agents to explore dimensions, moderate feedback, and synthesize code without overwhelming the main Orchestrator.
The Orchestrator MUST dynamically select 3+ expert personas best suited for the specific task. While Security, Performance, and Architect are the defaults for production code, the Orchestrator may swap them for others (e.g., Test Expert, Platform Expert) if the task context warrants it.
Each persona prompt MUST be anchored with the relevant Platform and Language (e.g., "Windows C++ Security Expert").
To prevent context bloat and semantic drift, the Orchestrator MUST NOT write code or summarize state itself. It delegates to several auxiliary personas:
project.magi.json specification document
conforming to magi_schema.json.constraints.magi.[iteration].json conforming to magi_schema.json.TOOL AGNOSTIC MANDATE: The protocol instructions MUST remain tool-agnostic.
Do not assume specific tool names (e.g., update_topic, read_file,
write_file). Use generic terms like "read from disk," "save to disk," or
"report status."
PHASE SIGNALING: The Orchestrator MUST use an appropriate status-reporting mechanism prior to invoking any sub-agents to clearly identify the current phase of the MAGI protocol to the user (e.g., "MAGI Phase 2: Engineering Manager").
DECENTRALIZED HANDOFFS: To reduce Orchestrator overhead, agents SHOULD
include a next_phase field in their JSON output to signal the intended
successor. The environment will use this token to automatically route to the
next expert.
SCAFFOLDINGPREPARATIONIMPLEMENTATIONSYNTHESISCRITIQUEANALYSISTPM_UPDATESYNTHESIS (if iteration needed) or
TRAININGVALIDATIONDEPLOYMENTgrep_search, read_file) to locate the relevant code and writes a strict
specification to project.magi.json conforming to magi_schema.json. This
file MUST contain a next_phase of SCAFFOLDING and the following structure:
{
"$schema": "./magi_schema.json#definitions/ProjectSpec",
"goal": "A one-sentence summary of the fix/feature.",
"target_files": ["Absolute paths to the files that must be modified."],
"anti_goals": ["What should explicitly NOT be changed."],
"edge_cases": ["Specific warnings from logs or code context."],
"next_phase": "SCAFFOLDING"
}
project.magi.json to understand the goal. Their mandate
is to create necessary files, define class interfaces, set up Mojo pipes, and
GN/DEPS rules. Leave implementation details empty or stubbed (e.g.,
NOTIMPLEMENTED()). The Architect SHOULD signal next_phase: SCAFFOLDING (if
Test Expert yet to be invoked) or PREPARATION.*_unittest.cc), define the required test fixtures, and stub out the
critical test cases based on the Architect's scaffold. The Test Expert SHOULD
signal next_phase: PREPARATION.next_phase: PREPARATION.project.magi.json to understand the
requirements and src/remoting/tools/magi-mode/PERSONAS.md (the routing
catalog) to assess and select the most appropriate Domain Experts required
to implement the stubs. It returns the absolute file paths of their definition
files to the Orchestrator.src/remoting/tools/magi-mode/personas/ and updating the PERSONAS.md
catalog.
CRITICAL: These MAGI system changes MUST NOT be entangled with the main
work CL (see VCS Isolation rule below).next_phase to IMPLEMENTATION in its output.Invoke the selected expert sub-agents in parallel (wait_for_previous: false).
Instruct each to implement the stubbed internals from the Base Scaffold.
File I/O: Each sub-agent MUST read project.magi.json to ground their
implementation in the actual requirements. They MUST securely save their draft
to disk using the versioned naming convention
[filename].[persona].magi.[iteration] (e.g., host.cc.security.magi.1).
Expert sub-agents SHOULD signal next_phase: SYNTHESIS upon completion.
Note: Sub-agents are permitted to change scaffolded signatures if their
priority requires it.
Once the Domain Experts finish:
state_block.magi.json using the schema defined in
magi_schema.json to prevent invoking a boilerplate agent:
{
"$schema": "./magi_schema.json#definitions/StateBlock",
"iteration": 1,
"stall_count": 0,
"active_constraints": [],
"resolved_constraints": [],
"personas": ["[Selected Experts]"],
"next_phase": "CRITIQUE"
}
[filename].[persona].magi.[N]
drafts and synthesize them into "Draft A" in the original file. Signal
next_phase: CRITIQUE.review.[persona].magi.[iteration].json conforming to
magi_schema.json. Do NOT return feedback as text to the Orchestrator.
Prompt Template:
Role Details: Read your mandate from
[persona_file_path]. Project Spec: Read the requirements fromproject.magi.json. Priority: [Priority]. Task: Review Draft [filename]. Save a JSON object withverdict("ACCEPT" or "REJECT"),reasoning(array of bullet points),comments(array of objects withfile, optionalline, andcomment), andnext_phase("ANALYSIS") toreview.[persona].magi.[iteration].json.
review.*.magi.[iteration].json files and saves a strict list of 3-5
Actionable Constraints and next_phase: TPM_UPDATE to
constraints.magi.[iteration].json on disk.constraints.magi.[iteration].json
and updates state_block.magi.json conforming to magi_schema.json. Checks
for "flip-flopping" (e.g., Constraint 1 violates a constraint from Round 1).
Set next_phase to SYNTHESIS if more work is needed, otherwise
TRAINING.
Deadlock API: If Stall Count exceeds 3, the Technical Program
Manager's ONLY output must be the exact string STATUS: DEADLOCK followed
by a structured report (Core Conflict, Blocked Personas, Human Decision
Needed).constraints.magi.[iteration].json
and outputs it directly to the user as a status update. Do NOT invoke a
separate Liaison agent.state_block.magi.json and constraints.magi.[iteration].json to generate
the next iteration (e.g., "Draft B").STATUS: DEADLOCK string, it MUST immediately halt the loop, print the
structured report to the human, and wait for a tie-breaking decision..magi files yet; the Trainer will need them.
The Orchestrator reports the final conclusion of the work.The Synthesizing Architect MUST ensure:
base::RefCountedDeleteOnSequence for timers.std::move and base::RefCountedString.if (callback_)) are
atomically sound or strictly sequence-enforced to prevent double-runs.Once consensus is reached, the Orchestrator MUST invoke a "Trainer" sub-agent.
The Trainer evaluates the final State Block and Review Analyst constraints to
identify systemic gaps in the Personas' knowledge. If a Persona made a recurring
mistake or lacked domain context, the Trainer proposes an upgrade to their
personas/*.md file and applies the improvements. The Trainer SHOULD signal
next_phase: VALIDATION.
VCS Isolation Rule: Any modifications to MAGI files (e.g., adding/updating personas by the Recruiter or Trainer) MUST be excluded from the feature/bugfix CL. Ensure MAGI paths are not staged during upload. Once the main solution is uploaded, create a completely separate, independent CL for the MAGI upgrades.
Run the standard suite (git cl presubmit, gn check, and unit tests). Upon
success, signal next_phase: DEPLOYMENT.
Once Validation passes, the Orchestrator pauses its own actions and delegates strictly to the Release Engineer sub-agent. The Orchestrator passes only two pieces of information: the name of the feature/bug, and the list of MAGI files updated by the Trainer/Recruiter.
The Release Engineer's exclusive mandate is:
git status / jj st. Detect and revert
accidental submodule bumps. Remove any lingering temporary files generated by
the protocol (e.g., *.magi, *.magi.*).git cl format or project-specific formatters.PERSONAS.md and
personas/*.md files updated by the Recruiter/Trainer. Upload the secondary
CL.