Spawn PAI agents via MCP factory tool. Loads identity, injects RAG context, validates spawn chain, and executes via Task(). The bridge between MCP tools and Claude Code's agent spawning.
Spawn PAI agents via MCP factory tool. Loads identity, injects RAG context, validates spawn chain, and executes via Task(). The bridge between MCP tools and Claude Code's agent spawning.
Need to create a new agent (use /agent-factory instead)
Usage
Basic Syntax
/spawn-agent AGENT_NAME mission description here
Examples
/spawn-agent SCHEDULER Generate Block 10 schedule with ACGME compliance
/spawn-agent COMPLIANCE_AUDITOR Audit Block 10 for work hour violations
/spawn-agent G2_RECON Find all constraint implementations in the codebase
/spawn-agent COORD_ENGINE Optimize solver performance for schedule generation
spawn_chain_valid: Must be True (or no parent specified)
identity_found: Must be True
tier and model: Determine execution parameters
If validation fails:
ifnot spec["spawn_chain_valid"]:
# Escalate: parent cannot spawn this childraise SpawnChainViolation(spec["spawn_chain_error"])
ifnot spec["identity_found"]:
# Escalate: need to create identity card firstraise IdentityNotFound(f"Create identity: .claude/Identities/{agent_name}.identity.md")
Step 4: Execute via Task()
result = Task(
prompt=spec["full_prompt"],
subagent_type=spec["subagent_type"], # "general-purpose"
model=spec["model"], # haiku/sonnet/opus
max_turns=spec["max_turns"], # 5/20/50 based on tier
description=f"{spec['agent_name']}: {mission[:30]}..."
)
Step 5: Handle Checkpoint (Optional)
If the agent needs to persist state:
# Agent writes checkpoint to spec["checkpoint_path"]# Example: .claude/Scratchpad/AGENT_SCHEDULER_20260116_143022.md# To resume later:# Read checkpoint, include in next spawn's context
Tier-Based Execution
Tier
Model
Max Turns
Use Case
Specialist
haiku
5
Single-shot focused tasks
Coordinator
sonnet
20
Multi-step domain work
Deputy
opus
50
Strategic cross-domain work
G-Staff
sonnet
15
Advisory/research roles
Rule: Match task complexity to tier. Don't spawn opus for simple validation.
Spawn Chain Validation
The MCP tool validates that parent agents can spawn children:
Subagents spawned via Task() do NOT have Task() available. They have all other tools (Bash, Edit, MCP, etc.) but cannot spawn further agents via Task().
ORCHESTRATOR ──┬── Agent 1 (no Task(), works directly)
├── Agent 2 (no Task(), works directly)
└── Agent N (no Task(), works directly)
Pattern B: CLI Spawning (for hierarchical)
ORCHESTRATOR ── Coordinator (via Task, no Task())
│
└── Bash: claude -p → Specialist (HAS Task())
│
└── Can spawn further agents
CLI Spawning Syntax
When a subagent needs to spawn another agent:
claude -p "
You are SPECIALIST.
## Identity
[Include identity card content or key details]
## Mission
[Mission description with full context]
## Constraints
- Budget: Do not exceed this mission scope
- Report: Write findings to [path]
" --model haiku --max-budget-usd 1.00
Key points:
CLI agents have full capabilities including Task()
Context must be passed in prompt (same as Task() spawning)
Use --max-budget-usd to prevent runaway costs
Spawn chain validation is NOT enforced via CLI (governance by convention)
RAG Injection
By default, inject_rag=True queries relevant context:
Error: Identity card not found for agent: NEW_AGENT
Resolution:
1. Check if agent exists in .claude/agents.yaml
2. If not, use /agent-factory to create the agent
3. Create identity card at .claude/Identities/NEW_AGENT.identity.md
Spawn Chain Violation
Error: Spawn chain violation: SCHEDULER cannot spawn ARCHITECT
Resolution:
1. SCHEDULER can only spawn: [] (no children)
2. ARCHITECT should be spawned by: ORCHESTRATOR
3. Escalate to correct parent or invoke as ORCHESTRATOR
Registry Not Found
Error: Agent registry not found at .claude/agents.yaml
Resolution:
1. Verify .claude/agents.yaml exists
2. Check for YAML syntax errors
3. Regenerate from identity cards if needed
/search-party, /qa-party can spawn multiple agents in parallel:
# Spawn 10 G2_RECON probesfor i inrange(10):
specs.append(spawn_agent_tool("G2_RECON", f"Probe {i}: {target}"))
# Execute in parallelfor spec in specs:
Task(prompt=spec["full_prompt"], ..., run_in_background=True)
Quick Reference
Agent Tiers
Tier
Agents (Examples)
Deputy
ARCHITECT, SYNTHESIZER
Coordinator
COORD_ENGINE, COORD_PLATFORM, COORD_FRONTEND
Specialist
SCHEDULER, COMPLIANCE_AUDITOR, TEST_WRITER
G-Staff
G1_PERSONNEL, G2_RECON, G3_OPERATIONS
SOF
SF_MEDIC, SF_ENGINEER, SF_WEAPONS
Common Spawns
# Scheduling
/spawn-agent SCHEDULER Generate Block X schedule
# Validation
/spawn-agent COMPLIANCE_AUDITOR Audit Block X for ACGME
# Research
/spawn-agent G2_RECON Find implementations of X
# Testing
/spawn-agent QA_TESTER Run test suite for X
# Documentation
/spawn-agent META_UPDATER Update docs for feature X
Aliases
/spawn-agent (primary)
/spawn (short form)
/agent (alternative)
spawn-agent: The bridge between MCP governance and Claude Code execution.