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.TONE MANDATE (SIGNAL-TO-NOISE): To eliminate conversational noise, conserve tokens, and maximize parsing stability, the Orchestrator MUST instruct ALL sub-agents (except itself) to adopt a neutral, data-driven tone.
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."
ENVIRONMENT GROUNDING MANDATE: All sub-agents MUST read
project.magi.json#environment immediately upon invocation to ground
themselves in the active VCS (JJ or GIT) and Harness (JETSKI or
GENERIC_CLI). They MUST adjust their tool usage and command construction
natively to match this environment.
THE CHECKLIST LIFECYCLE STATE MACHINE: The session's verification integrity is governed by a deterministic boolean checklist state machine. While the MAGI protocol has 11 overall workflow phases (Phases 0–10), the automated checklist state itself only transitions or is modified during four key phases:
project.magi.json#checklist as an empty object {}.personas/**/*.json checklists, takes the Union Set of all keys,
and initializes the active checklist in state_block.magi.json with all
values set to false.ReviewFeedback checklist. The Supervisor/Review Analyst performs a
Logical AND consolidation across all reviews. A key in the consolidated
state_block.magi.json#checklist only becomes true if ALL reviewers
evaluating that key asserted true. Any false keys or
unlisted_issues_found are translated into strict constraints in
constraints.magi.[iteration].json.true), the Trainer uses unlisted_issues_found history to append new
keys to the appropriate personas/**/*.json checklists.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
TRAININGSYNTHESIS (if iteration needed) or TRAININGVALIDATIONDEPLOYMENTThe Investigation: When a bug or feature is requested, the Orchestrator MUST NOT read the raw logs or attempt to hold the requirements in its own context window. Instead, invoke a "Scoping Lead" sub-agent.
The Specification: The Scoping Lead investigates the codebase
(grep_search, read_file) to locate the relevant code and writes a strict
specification to project.magi.json conforming to magi_schema.json.
The "checklist" field MUST be initialized as an empty object {}.
Environment Discovery: Before writing the file, the Scoping Lead MUST discover the environment:
.jj/ directory or run jj status. If successful,
set vcs to "JJ". Otherwise, default to "GIT".code_search, view_file) are
available. If yes, set harness to "JETSKI". Otherwise, set to
"GENERIC_CLI".The project.magi.json file MUST contain a next_phase of SCAFFOLDING and
the following structure:
{
"$schema": "./magi_schema.json#definitions/ProjectSpec",
"checklist": {},
"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."],
"build_targets": ["//remoting/host:host"],
"next_phase": "SCAFFOLDING",
"paranoia_mode": false,
"auditability_level": "NORMAL",
"environment": {
"repo_type": "CHROMIUM",
"vcs": "JJ",
"harness": "JETSKI",
"output_directory": "out/Default"
}
}
Tooling Selection: The combination of repo_type, vcs, and
harness in the environment block determines the exact build, test,
and upload commands used by the agents.
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 MUST signal next_phase: SCAFFOLDING.*_unittest.cc),
define the required test fixtures, and stub out the critical test cases based
on the Architect's scaffold. To ensure failure in Chromium's GTest framework
(confirming TDD behavior), the Test Expert MUST insert
ADD_FAILURE("NOT IMPLEMENTED"); into the stubbed test cases.
The Test Expert SHOULD signal next_phase: PREPARATION.build_targets are defined in
project.magi.json, the Orchestrator MUST verify that the scaffold compiles
and that all newly added tests fail (confirming TDD behavior).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.checklist from
every selected persona JSON file, compute the Union Set of all checklist
keys, and initialize state_block.magi.json#checklist with all these keys
set to false.review_mode (SUPERVISOR or CONSENSUS) and include it in the initial
state_block.magi.json.
auditability_level == "VERBOSE",
paranoia_mode == true, or if the number of selected reviewers > 3.
For critical or P1 tasks, the Engineering Manager SHOULD mandate a
minimum of 3 specialized reviewers to ensure broad coverage.(Reviewer Count * Target Files) and select
state_transport:
paranoia_mode == true or Risk Score > 15. All
drafts, reviews, and state updates are written to .magi.*.json files..magi.*.json files on disk for auditing. (These files MUST be stored
in a dedicated directory, e.g., .magi_logs/)..magi_logs/ directory must be excluded from
all generated CLs and must be cleaned up at the end of the run.EPHEMERAL mode is active, the Orchestrator
MUST strictly validate incoming JSON payloads against magi_schema.json in
memory before proceeding, as disk-based presubmit checks will be bypassed.
If JSON parsing fails (e.g., malformed JSON), the Orchestrator SHOULD NOT
request a retry from the same sub-agent. Instead, it SHOULD discard that
sub-agent instance, spawn a new one with a fresh context window, and replay
the prompt.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).review_mode decision to the human. Ensure the
workspace is clean. The Engineering Manager MUST set 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",
"checklist": {
"[Merged keys from selected personas]": false
},
"iteration": 1,
"stall_count": 0,
"active_constraints": [],
"resolved_constraints": [],
"personas": ["[Selected Experts]"],
"next_phase": "CRITIQUE",
"review_mode": "[SUPERVISOR/CONSENSUS]",
"state_transport": "[FILE_IO/EPHEMERAL/EPHEMERAL_WITH_LOGS]"
}
[filename].[persona].magi.[N]
drafts and synthesize them into "Draft A" in the original file.
build_targets are defined in
project.magi.json, the Synthesizing Architect MUST run the local
build/test suite on "Draft A" and attach the build logs to the
synthesis report before signaling next_phase: CRITIQUE.Blind Critique: Push Draft A to an expanded panel of Reviewers.
File I/O: Output routing depends on state_transport:
FILE_IO: Save feedback to disk as
review.[persona].magi.[iteration].json.EPHEMERAL: Return the JSON object directly to the Orchestrator.EPHEMERAL_WITH_LOGS: Return JSON natively AND save to disk.
Prompt Template:Role Details: Read your mandate from
[persona_file_path]. Audit Mandate: You are a rigorous, objective auditor. Drop all politeness. Focus exclusively on technical data and facts. Be concise and pointed. Dynamic Strictness (Iteration [N]): [If N<=2: "Exhaustively reject for any flaw or deviation based on technical facts." | If N==3-4: "Accept minor nits. Reject only for functional/security bugs." | If N>=5: "Stall prevention. Accept unless catastrophic."] Project Spec: Read the requirements fromproject.magi.json. Priority: [Priority]. Task: Review Draft [filename]. Auditing against your persona checklist. Save a JSON object conforming tomagi_schema.json#definitions/ReviewFeedbackwithchecklist(updating your evaluated keys to true/false),verdict("ACCEPT" or "REJECT"),reasoning(array of bullet points),comments(array of objects withfile, optionalline, andcomment), optionalunlisted_issues_found(array of strings), andnext_phase("ANALYSIS") toreview.[persona].magi.[iteration].json.
Overlapping Mandates: For critical checklist items (e.g., security, data safety), the Engineering Manager SHOULD ensure that at least two independent reviewers evaluate the same item to achieve consensus.
If review_mode == SUPERVISOR, the Orchestrator (or a specialized Supervisor
agent) performs the following in a single turn:
review.*.magi.[iteration].json files.true in state_block.magi.json#checklist if all reviewers
evaluating it set it to true). Append any unlisted_issues_found to the
historical logs. Update state_block.magi.json with the new iteration and
stall count. (The stall count MUST only be incremented if the iteration
fails to resolve any checklist items or Actionable Constraints).false checklist keys and unlisted_issues_found) and
the current review_mode to constraints.magi.[iteration].json.next_phase: SYNTHESIS (if more work is needed) or
TRAINING.If review_mode == CONSENSUS, use the granular relay:
review.*.magi.[iteration].json files, performs the Logical AND
consolidation on the checklists, and saves a strict list of 3-5 Actionable
Constraints (derived from false checklist keys and
unlisted_issues_found), review_mode: "CONSENSUS", 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. The
stall count MUST only be incremented if the iteration fails to resolve
any checklist items or Actionable Constraints. 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 reaches 3, the Technical Program Manager
SHOULD attempt an automated fallback (e.g., reducing strictness or
switching to SUPERVISOR mode) before declaring deadlock. If Stall Count
exceeds 3, the Technical Program Manager MUST output a valid
state_block.magi.json with next_phase: DEADLOCK and append a
structured deadlock report (Core
Conflict, Blocked Personas, Human Decision Needed) to the
active_constraints array.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").next_phase: DEADLOCK signal, 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.review_mode: CONSENSUS.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/*.json file by adding a new Boolean constraint to their checklist.
Persona Splitting (Hierarchical Specialization): The Trainer MUST NOT let a
persona's checklist exceed 10 items. If adding a new constraint exceeds this
limit, the Trainer MUST "fork" the persona using a nested directory structure
representing [category]/[domain]/[specialty].json (e.g., split
core/security.json into core/security/memory.json and
core/security/network.json). Do not use flat files with underscores. The
directory depth MUST NOT exceed 5 levels (counting from /personas). Migrate
the relevant checks and update PERSONAS.md.
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. The staging and submission workflow branches dynamically based on
project.magi.json#environment/vcs:
main@origin) from the start: one for the feature/bugfix and one for the
MAGI upgrades. If they accidentally get mixed, the Release Engineer MUST
use jj split or jj squash -i to cleanly separate the changes before
pushing.To ensure agents operate safely within the specific environment, specialized
tooling personas are available in personas/infra/:
infra/jj_git.json: Expert in jj on Git workflow. Agents performing
file operations or commit management in a JJ environment SHOULD consult
this persona to avoid losing Gerrit Change-Ids or mishandling detached
HEAD states.infra/chromium_build.json: Expert in Chromium build tools. Agents
performing builds or adding new files SHOULD consult this persona to ensure
correct target discovery and usage of autoninja.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:
project.magi.json#environment/vcs. Run jj st (for JJ) or git status
(for Git). 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/**/*.json files
updated by the Recruiter or Trainer as a secondary CL.If project.magi.json#environment/harness == "JETSKI", the Orchestrator:
personas/**/*.json files and
inject their mandate and checklist directly into the Prompt or Role
arguments of invoke_subagent tool calls. This eliminates a redundant
file-reading turn (view_file call) for every sub-agent.next_phase token from sub-agent output JSONs and manually
calling the next tool (standard Jetski does not have an automatic
background router).To validate the MAGI protocol execution and prevent regressions in prompt instructions and state machine transitions, consult the SKILL_TEST.md document. It defines unit tests for each phase of the protocol using isolated mock data.