MoAI Agent Teams Workflow
Overview
This skill manages Agent Teams execution for MoAI workflows. When team mode is selected (via --team flag, auto-detection, or configuration), MoAI operates as Team Lead coordinating persistent teammates.
Prerequisites
Agent Teams requires:
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in settings.json env
workflow.team.enabled: true in workflow.yaml
- Claude Code v2.1.32 or later
Mode Selection
The mode selector determines execution strategy:
- Check --team/--solo flags (user override)
- Check workflow.yaml execution_mode setting
- If "auto": Analyze complexity score
- Domain count >= 3: team mode
- Affected files >= 10: team mode
- Complexity score >= 7: team mode
- Otherwise: sub-agent mode
- Verify AGENT_TEAMS is enabled
- If not enabled: warn user, fall back to sub-agent
Team Lifecycle
Phase 1: Team Creation
TeamCreate(team_name: "moai-{workflow}-{timestamp}")
Team naming convention:
- Plan phase:
moai-plan-SPEC-XXX
- Run phase:
moai-run-SPEC-XXX
- Debug:
moai-debug-{issue}
- Review:
moai-review-{target}
Phase 2: Task Decomposition
Before spawning teammates, create the complete shared task list:
TaskCreate(subject: "Task description", description: "Detailed requirements")
Rules for task decomposition:
- Each task should be self-contained (one clear deliverable)
- Define dependencies between tasks (addBlockedBy)
- Assign file ownership boundaries per teammate role
- Target 5-6 tasks per teammate for optimal flow
- Tasks should map to SPEC requirements where applicable
Phase 3: Teammate Spawning
Spawn teammates using Task tool with team_name parameter:
Task(
subagent_type: "team-backend-dev",
team_name: "moai-run-SPEC-XXX",
name: "backend-dev",
prompt: "You are the backend developer for this team. Your file ownership: {detected_ownership}. SPEC context: {spec_summary}",
mode: "plan"
)
Spawning rules:
- Include SPEC context in the spawn prompt
- Assign file ownership boundaries detected from project structure (see File Ownership Detection)
- Use appropriate model per role (haiku for research, sonnet for implementation)
Plan approval (when workflow.yaml team.require_plan_approval: true):
- Spawn implementation teammates with
mode: "plan"
- Teammates must submit a plan before writing any code
- Team lead receives plan_approval_request messages from teammates
- Team lead reviews plan scope, file ownership compliance, and approach
- Approve via:
SendMessage(type: "plan_approval_response", request_id: "{id}", recipient: "{name}", approve: true)
- Reject with feedback via:
SendMessage(type: "plan_approval_response", request_id: "{id}", recipient: "{name}", approve: false, content: "Feedback here")
- After approval, teammate exits plan mode and begins implementation
- When
require_plan_approval is false, spawn with mode: "acceptEdits" instead
Phase 4: Coordination
MoAI as Team Lead monitors and coordinates:
- Receive automatic messages from teammates (progress, completion, issues)
- Use SendMessage for direct coordination
- Broadcast critical updates to all teammates
- Resolve file ownership conflicts
- Reassign tasks if a teammate is blocked
Coordination patterns:
- When backend completes API: notify frontend-dev of available endpoints
- When implementation completes: assign quality validation tasks
- When quality finds issues: direct fix messages to responsible teammate
- When all tasks complete: begin shutdown sequence
Delegate mode (when workflow.yaml team.delegate_mode: true):
- MoAI operates in coordination-only mode
- Focus on task assignment, message routing, progress monitoring, and conflict resolution
- Do NOT directly implement code or modify files (no Write, Edit, or Bash for implementation)
- Delegate ALL implementation work to teammates via task assignment and SendMessage
- Read and Grep are permitted for understanding context and reviewing teammate output
- If a task has no suitable teammate, spawn a new one rather than implementing directly
- When delegate_mode is false, team lead may implement small tasks directly alongside teammates
Phase 5: Shutdown
Graceful shutdown sequence:
- Verify all tasks are completed via TaskList
- Send shutdown_request to each teammate:
SendMessage(type: "shutdown_request", recipient: "backend-dev")
- Wait for shutdown approval from each
- Clean up team resources:
TeamDelete()
File Ownership Strategy
Prevent write conflicts by assigning exclusive file ownership.
[HARD] Team lead MUST analyze project structure before assigning ownership. Use Explore agent or Glob/Grep to map directory structure and assign ownership boundaries that match the actual project layout. Never use hardcoded patterns from a different project type.
File Ownership Detection
Ownership patterns depend on the project type. Detect the project structure first, then assign accordingly:
Go projects:
| Role |
Ownership |
| backend-dev |
internal/, pkg/, cmd/** |
| tester |
_test.go, testdata/**, test/* |
| quality |
(read-only, no file ownership) |
Web projects (React, Vue, Angular):
| Role |
Ownership |
| backend-dev |
src/api/, src/models/, src/services/** |
| frontend-dev |
src/ui/, src/components/, src/pages/** |
| tester |
tests/, tests/, .test., .spec. |
| quality |
(read-only, no file ownership) |
Full-stack projects (separate client/server):
| Role |
Ownership |
| backend-dev |
server/, api/, src/server/** |
| frontend-dev |
client/, app/, src/client/** |
| data-layer |
db/, migrations/, schema/** |
| tester |
tests/, tests/, *_test.go, .test., .spec. |
| quality |
(read-only, no file ownership) |
Monorepo projects:
| Role |
Ownership |
| Per-domain teammate |
packages//, apps// |
| tester |
/tests/, /tests/, **/*_test.go, **/.test., **/.spec. |
| quality |
(read-only, no file ownership) |
Python projects:
| Role |
Ownership |
| backend-dev |
src//, / |
| tester |
tests/**, **/test_*.py, **/*_test.py |
| quality |
(read-only, no file ownership) |
Ownership Rules
- No two teammates own the same file
- Shared types/interfaces: owned by the creating teammate, shared via message
- Config files: owned by team lead or explicitly assigned
- If ownership conflict: team lead resolves via SendMessage
- Test files always belong to the tester role regardless of location
Team Patterns Reference
Plan Research Team
- Roles: researcher (haiku), analyst (sonnet), architect (sonnet)
- Use: Complex SPEC creation requiring multi-angle exploration
- Duration: Short-lived (exploration phase only)
Implementation Team
- Roles: backend-dev (sonnet), frontend-dev (sonnet), tester (sonnet)
- Use: Cross-layer feature implementation
- Duration: Medium (full run phase)
Full-Stack Team
- Roles: api-layer, ui-layer, data-layer, quality (all sonnet)
- Use: Large-scale full-stack features
- Duration: Medium-long
Investigation Team
- Roles: hypothesis-1, hypothesis-2, hypothesis-3 (all haiku)
- Use: Complex debugging with competing theories
- Duration: Short
Review Team
- Roles: security-reviewer, perf-reviewer, quality-reviewer (all sonnet)
- Use: Multi-perspective code review
- Duration: Short
Error Recovery
- Teammate crash: Spawn replacement with same role and resume context
- Task stuck: Team lead reassigns to different teammate
- File conflict: Team lead mediates via SendMessage, adjusts ownership
- All teammates idle: Check if tasks remain, assign or shutdown
- Token limit: Shutdown team gracefully, fall back to sub-agent for remaining work
Version: 1.1.0
Last Updated: 2026-02-07
1---2name: moai-workflow-team3description: Agent Teams workflow management for MoAI-ADK. Handles team creation, teammate spawning, task decomposition, inter-agent messaging, and graceful shutdown. Integrates with SPEC workflow for team-based Plan and Run phases. Supports dual-mode execution with automatic fallback to sub-agent mode when teams are unavailable.4license: Apache-2.05---67# MoAI Agent Teams Workflow89## Overview1011This skill manages Agent Teams execution for MoAI workflows. When team mode is selected (via --team flag, auto-detection, or configuration), MoAI operates as Team Lead coordinating persistent teammates.1213## Prerequisites1415Agent Teams requires:16- `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` in settings.json env17- `workflow.team.enabled: true` in workflow.yaml18- Claude Code v2.1.32 or later1920## Mode Selection2122The mode selector determines execution strategy:23241. Check --team/--solo flags (user override)252. Check workflow.yaml execution_mode setting263. If "auto": Analyze complexity score27 - Domain count >= 3: team mode28 - Affected files >= 10: team mode29 - Complexity score >= 7: team mode30 - Otherwise: sub-agent mode314. Verify AGENT_TEAMS is enabled325. If not enabled: warn user, fall back to sub-agent3334## Team Lifecycle3536### Phase 1: Team Creation3738```39TeamCreate(team_name: "moai-{workflow}-{timestamp}")40```4142Team naming convention:43- Plan phase: `moai-plan-SPEC-XXX`44- Run phase: `moai-run-SPEC-XXX`45- Debug: `moai-debug-{issue}`46- Review: `moai-review-{target}`4748### Phase 2: Task Decomposition4950Before spawning teammates, create the complete shared task list:5152```53TaskCreate(subject: "Task description", description: "Detailed requirements")54```5556Rules for task decomposition:57- Each task should be self-contained (one clear deliverable)58- Define dependencies between tasks (addBlockedBy)59- Assign file ownership boundaries per teammate role60- Target 5-6 tasks per teammate for optimal flow61- Tasks should map to SPEC requirements where applicable6263### Phase 3: Teammate Spawning6465Spawn teammates using Task tool with team_name parameter:6667```68Task(69 subagent_type: "team-backend-dev",70 team_name: "moai-run-SPEC-XXX",71 name: "backend-dev",72 prompt: "You are the backend developer for this team. Your file ownership: {detected_ownership}. SPEC context: {spec_summary}",73 mode: "plan"74)75```7677Spawning rules:78- Include SPEC context in the spawn prompt79- Assign file ownership boundaries detected from project structure (see File Ownership Detection)80- Use appropriate model per role (haiku for research, sonnet for implementation)8182Plan approval (when workflow.yaml `team.require_plan_approval: true`):83- Spawn implementation teammates with `mode: "plan"`84- Teammates must submit a plan before writing any code85- Team lead receives plan_approval_request messages from teammates86- Team lead reviews plan scope, file ownership compliance, and approach87- Approve via: `SendMessage(type: "plan_approval_response", request_id: "{id}", recipient: "{name}", approve: true)`88- Reject with feedback via: `SendMessage(type: "plan_approval_response", request_id: "{id}", recipient: "{name}", approve: false, content: "Feedback here")`89- After approval, teammate exits plan mode and begins implementation90- When `require_plan_approval` is false, spawn with `mode: "acceptEdits"` instead9192### Phase 4: Coordination9394MoAI as Team Lead monitors and coordinates:95961. Receive automatic messages from teammates (progress, completion, issues)972. Use SendMessage for direct coordination983. Broadcast critical updates to all teammates994. Resolve file ownership conflicts1005. Reassign tasks if a teammate is blocked101102Coordination patterns:103- When backend completes API: notify frontend-dev of available endpoints104- When implementation completes: assign quality validation tasks105- When quality finds issues: direct fix messages to responsible teammate106- When all tasks complete: begin shutdown sequence107108Delegate mode (when workflow.yaml `team.delegate_mode: true`):109- MoAI operates in coordination-only mode110- Focus on task assignment, message routing, progress monitoring, and conflict resolution111- Do NOT directly implement code or modify files (no Write, Edit, or Bash for implementation)112- Delegate ALL implementation work to teammates via task assignment and SendMessage113- Read and Grep are permitted for understanding context and reviewing teammate output114- If a task has no suitable teammate, spawn a new one rather than implementing directly115- When delegate_mode is false, team lead may implement small tasks directly alongside teammates116117### Phase 5: Shutdown118119Graceful shutdown sequence:1201211. Verify all tasks are completed via TaskList1222. Send shutdown_request to each teammate:123 ```124 SendMessage(type: "shutdown_request", recipient: "backend-dev")125 ```1263. Wait for shutdown approval from each1274. Clean up team resources:128 ```129 TeamDelete()130 ```131132## File Ownership Strategy133134Prevent write conflicts by assigning exclusive file ownership.135136[HARD] Team lead MUST analyze project structure before assigning ownership. Use Explore agent or Glob/Grep to map directory structure and assign ownership boundaries that match the actual project layout. Never use hardcoded patterns from a different project type.137138### File Ownership Detection139140Ownership patterns depend on the project type. Detect the project structure first, then assign accordingly:141142**Go projects:**143144| Role | Ownership |145|------|-----------|146| backend-dev | internal/**, pkg/**, cmd/** |147| tester | *_test.go, testdata/**, test/** |148| quality | (read-only, no file ownership) |149150**Web projects (React, Vue, Angular):**151152| Role | Ownership |153|------|-----------|154| backend-dev | src/api/**, src/models/**, src/services/** |155| frontend-dev | src/ui/**, src/components/**, src/pages/** |156| tester | tests/**, __tests__/**, *.test.*, *.spec.* |157| quality | (read-only, no file ownership) |158159**Full-stack projects (separate client/server):**160161| Role | Ownership |162|------|-----------|163| backend-dev | server/**, api/**, src/server/** |164| frontend-dev | client/**, app/**, src/client/** |165| data-layer | db/**, migrations/**, schema/** |166| tester | tests/**, __tests__/**, *_test.go, *.test.*, *.spec.* |167| quality | (read-only, no file ownership) |168169**Monorepo projects:**170171| Role | Ownership |172|------|-----------|173| Per-domain teammate | packages/<domain-name>/**, apps/<domain-name>/** |174| tester | **/tests/**, **/__tests__/**, **/*_test.go, **/*.test.*, **/*.spec.* |175| quality | (read-only, no file ownership) |176177**Python projects:**178179| Role | Ownership |180|------|-----------|181| backend-dev | src/<package>/**, <package>/** |182| tester | tests/**, **/test_*.py, **/*_test.py |183| quality | (read-only, no file ownership) |184185### Ownership Rules186187- No two teammates own the same file188- Shared types/interfaces: owned by the creating teammate, shared via message189- Config files: owned by team lead or explicitly assigned190- If ownership conflict: team lead resolves via SendMessage191- Test files always belong to the tester role regardless of location192193## Team Patterns Reference194195### Plan Research Team196- Roles: researcher (haiku), analyst (sonnet), architect (sonnet)197- Use: Complex SPEC creation requiring multi-angle exploration198- Duration: Short-lived (exploration phase only)199200### Implementation Team201- Roles: backend-dev (sonnet), frontend-dev (sonnet), tester (sonnet)202- Use: Cross-layer feature implementation203- Duration: Medium (full run phase)204205### Full-Stack Team206- Roles: api-layer, ui-layer, data-layer, quality (all sonnet)207- Use: Large-scale full-stack features208- Duration: Medium-long209210### Investigation Team211- Roles: hypothesis-1, hypothesis-2, hypothesis-3 (all haiku)212- Use: Complex debugging with competing theories213- Duration: Short214215### Review Team216- Roles: security-reviewer, perf-reviewer, quality-reviewer (all sonnet)217- Use: Multi-perspective code review218- Duration: Short219220## Error Recovery221222- Teammate crash: Spawn replacement with same role and resume context223- Task stuck: Team lead reassigns to different teammate224- File conflict: Team lead mediates via SendMessage, adjusts ownership225- All teammates idle: Check if tasks remain, assign or shutdown226- Token limit: Shutdown team gracefully, fall back to sub-agent for remaining work227228---229230Version: 1.1.0231Last Updated: 2026-02-07