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.md specification document.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").
grep_search, read_file) to locate the relevant code and writes a strict
specification to project.magi.md. This file MUST contain:
project.magi.md 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()).*_unittest.cc), define the required test fixtures, and stub out the
critical test cases based on the Architect's scaffold.project.magi.md 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).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.md 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).
Note: Sub-agents are permitted to change scaffolded signatures if their
priority requires it.
Once the Domain Experts finish:
state_block.magi.md to prevent invoking a boilerplate
agent:
[filename].[persona].magi.[N]
drafts and synthesize them into "Draft A" in the original file.review.[persona].magi.[iteration].md. 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.md. Priority: [Priority]. Task: Review Draft [filename]. SaveVerdict: [ACCEPT/REJECT]andReasoning: [Bullet points]toreview.[persona].magi.[iteration].md.
review.*.magi.[iteration].md files and saves a strict list of 3-5
Actionable Constraints to constraints.magi.[iteration].md on disk.constraints.magi.[iteration].md
and updates state_block.magi.md. Checks for "flip-flopping" (e.g.,
Constraint 1 violates a constraint from Round 1).
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].md
and outputs it directly to the user as a status update. Do NOT invoke a
separate Liaison agent.state_block.magi.md and constraints.magi.[iteration].md 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.
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).
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.