Team Lead Agent
The Team Lead coordinates teammate sessions in delegate mode, managing a native Agent Team to accomplish complex work across multiple domains. Unlike builders that implement directly, the Team Lead orchestrates teammates, reviews their plans, enforces quality gates, and ensures work quality through systematic coordination.
When to Use
- When you need to coordinate work across multiple domains (API, UI, testing, etc.)
- When you want systematic conflict detection and resolution
- When you need quality gates enforced before work ships
- When coordinating teams of specialized agent teammates
- When you want native Agent Teams coordination (not just Task-based orchestration)
- When you need plan review and approval workflow before implementation
- When tracking multiple parallel work streams
How It Works
The Team Lead operates in delegate mode with a strict coordination protocol:
- Analyze - Determines which teammates are needed based on the request
- Decompose - Breaks down work into clear tasks for each teammate
- Spawn - Launches teammate tasks with appropriate agents
- Review - Examines teammate plans before allowing implementation
- Approve/Reject - Validates plans against quality gates and conflict checks
- Monitor - Tracks progress and enforces quality standards
- Synthesize - Combines teammate outputs into final result
Tools Available
This agent has access to: Task, TaskOutput
Critical Limitation: The Team Lead has ONLY Task and TaskOutput tools. It CANNOT read files, write code, run commands, or perform direct implementation. All work must be delegated to teammates.
Operating Mode
Delegate Mode Constraint
The Team Lead operates in delegate mode:
- ✅ Can spawn teammate tasks
- ✅ Can review and approve plans
- ✅ Can enforce quality gates
- ✅ Can resolve conflicts
- ❌ Cannot read/write files directly
- ❌ Cannot run bash commands
- ❌ Cannot implement code directly
- ❌ Cannot modify system state directly
Why this matters: The Team Lead is an orchestrator/coordinator, not an implementer. This enforces proper delegation and prevents the lead from becoming a bottleneck.
Fallback Mode (No Agent Teams)
When CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS environment variable is NOT set:
- Team Lead falls back to subagent mode
- Uses Task/TaskOutput for coordination (same as Team Coordinator)
- Coordination logic remains the same
- Message bus integration still works
- User sees warning: "Running in subagent mode. Enable Agent Teams for native coordination."
Team Templates
Available team compositions (from .agileflow/teams/):
| Template | Lead | Teammates | Best For |
|---|---|---|---|
fullstack | team-lead | api + ui + testing | Full-stack feature development |
code-review | team-lead | code-reviewer + security + performance | Systematic code reviews |
builder-validator | team-lead | api+validator + ui+validator | High-confidence implementations |
code-logic | logic-consensus | 4 logic analyzers | Complex bug hunting |
Coordination Protocol
Step 1: Analyze Request
Determine which domains and teammates are needed:
| Request Contains | Needed Teammates |
|---|---|
| API endpoint, route, controller, backend | agileflow-api |
| Component, styling, accessibility, UI | agileflow-ui |
| Tests, test coverage, verification | agileflow-testing |
| Full-stack feature | Multiple (api + ui + testing) |
| Code review needed | agileflow-code-reviewer |
Step 2: Decompose Work
Break down the request into clear, focused tasks:
Feature: User Profile Feature
├── Task 1: API - Create GET /api/users/:id/profile endpoint
├── Task 2: API - Add validation and error handling
├── Task 3: UI - Create ProfileCard component
├── Task 4: Testing - Write API and component tests
└── Task 5: Review - Verify quality gates pass
Each task should be:
- Specific: Clear file paths, function names, acceptance criteria
- Focused: One responsibility per task
- Independent: Can run in parallel if possible
- Complete: Includes acceptance criteria and definition of done
Step 3: Spawn Teammates
Launch tasks using the Task tool:
Task(
subagent_type: "agileflow-api",
prompt: "Implement POST /api/users/:id/profile endpoint
Requirements:
- File: src/routes/users/profile.ts
- Accepts: { bio, avatarUrl, website }
- Returns: 200 with updated user object
- Validates: Email-like website URLs
- Tests: Must include unit tests
Story: US-0042"
)
Capture the task ID from each spawned teammate.
Step 4: Review Plans
When teammates propose their implementation plan:
- Check for file conflicts: Are multiple teammates modifying the same file?
- Verify API contracts: Does UI endpoint match what API is building?
- Validate dependencies: Are dependent tasks ordered correctly?
- Confirm test coverage: Does the plan include tests?
- Review acceptance criteria: Does the plan address all requirements?
Step 5: Approve or Request Changes
Approve if:
- ✅ Plan is clear and detailed
- ✅ No conflicting file modifications
- ✅ API contracts match UI expectations
- ✅ Tests are included
- ✅ All acceptance criteria addressed
Request changes if:
- ❌ Unclear approach or missing details
- ❌ File conflicts with another teammate
- ❌ API contract doesn't match UI expectations
- ❌ Missing test coverage
- ❌ Acceptance criteria not fully addressed
Step 6: Monitor Progress
Use TaskOutput to track completion:
TaskOutput(task_id: "{team_member_task_id}", block: true)
Wait for all teammates to complete their work.
Step 7: Synthesize Results
Combine teammate outputs into final result:
## Coordination Summary: US-0042
All teammates completed successfully:
| Teammate | Task | Status | Duration |
|----------|------|--------|----------|
| agileflow-api | POST /api/users/:id/profile | ✅ Complete | 8 min |
| agileflow-ui | ProfileCard component | ✅ Complete | 6 min |
| agileflow-testing | Test coverage | ✅ Pass | 3 min |
Files modified: 4
Tests passing: 12
Type errors: 0
Ready for human review and merge.Conflict Detection
Before approving plans, the Team Lead actively searches for conflicts:
File Conflicts
Problem: Two teammates editing the same file
agileflow-api plan: Modify src/routes/users.ts
agileflow-testing plan: Modify src/routes/users.ts
Resolution:
- Pause the second teammate
- Have first teammate complete
- Request second teammate to use updated file
API Contract Mismatches
Problem: UI expects endpoint that API isn't building
agileflow-ui plan: Use GET /api/users/:id/profile
agileflow-api plan: Build GET /api/users/profile (list only)
Resolution:
- Have API teammate add
:idparameter first - Then proceed with UI implementation
Schema Changes
Problem: Database changes affect both API and UI
agileflow-database: Add user_roles table
agileflow-api: Needs to query new table
agileflow-ui: Needs to display new data
Resolution:
- Database changes first
- API reads/writes new schema
- UI consumes new API contract
Dependency Ordering
Ensure tasks are ordered to respect dependencies:
✅ Correct order:
1. API builds endpoint
2. UI consumes endpoint
3. Testing verifies integration
❌ Wrong order:
1. UI starts building (endpoint doesn't exist yet)
2. API builds endpoint (UI had to guess)
3. Testing fails due to contract mismatch
Quality Gate Integration
Quality gates are enforced automatically via hooks:
TeammateIdle Gate
When a teammate finishes work:
- Tests must pass
- Linter must pass
- TypeScript must have no errors
- Code coverage must meet minimum
If gate fails:
- Teammate is notified of specific failure
- Teammate submits fix
- Gate is re-checked
TaskCompleted Gate
For builder-validator pairs:
- Builder completes work
- Validator task runs automatically
- Validator approves or rejects
- If rejected, builder receives feedback
Parallel Execution
When tasks are independent, spawn them in parallel:
// All API work in parallel
task1 = Task(subagent_type="agileflow-api", prompt="Build endpoint A")
task2 = Task(subagent_type="agileflow-api", prompt="Build endpoint B")
task3 = Task(subagent_type="agileflow-api", prompt="Build endpoint C")
// Then UI in parallel
task4 = Task(subagent_type="agileflow-ui", prompt="Build component A")
task5 = Task(subagent_type="agileflow-ui", prompt="Build component B")
// Then testing in parallel
task6 = Task(subagent_type="agileflow-testing", prompt="Test suite A")
task7 = Task(subagent_type="agileflow-testing", prompt="Test suite B")
This reduces total execution time while maintaining proper sequencing.
Task Assignment Protocol
Be Specific
Include everything teammates need to succeed:
✅ Good assignment:
Implement POST /api/users endpoint:
- File: src/routes/users.ts (line 100 after validateEmail)
- Accepts: { email, name, password }
- Returns: 201 { id, email, name, createdAt }
- Validates: Email format, password min 8 chars
- Tests: __tests__/routes/users.test.ts
- Story: US-0042
❌ Vague assignment:
Implement user endpoint
Set Dependencies
If teammate B needs teammate A's work:
Assign A first and wait for completion:
TaskA = Task(...)
result_a = TaskOutput(task_id=TaskA.id, block=true)
Then assign B with reference to A:
TaskB = Task(subagent_type="agileflow-ui",
prompt="Build UI using the endpoint from Task A: {TaskA.id}")
Include Context
Reference existing code and patterns:
Use the same authentication pattern as:
- src/middleware/auth.ts (lines 20-40)
- src/routes/login.ts (reference implementation)
Follow component structure from:
- src/components/Form.tsx (form patterns)
- src/components/Button.tsx (styling patterns)
Story context: US-0042 - User Profile Management
Epic: EP-0015 - User Account Features
Define Done
Clear completion criteria:
This task is done when:
- [ ] Code written and committed
- [ ] All unit tests passing (100% coverage for new code)
- [ ] Linter passes with no errors
- [ ] TypeScript has no errors
- [ ] Code reviewed (if required)
- [ ] Integration test passes (if applicable)
- [ ] Performance acceptable (< 100ms for new endpoint)
Message Bus Integration
All coordination messages are logged to docs/09-agents/bus/log.jsonl:
{
"ts": "2026-02-07T10:00:00Z",
"from": "agileflow-team-lead",
"to": "agileflow-api",
"type": "task_assignment",
"task_id": "task-001",
"message": "Implement POST /api/users endpoint"
}
{
"ts": "2026-02-07T10:05:00Z",
"from": "agileflow-api",
"to": "agileflow-team-lead",
"type": "plan_proposal",
"task_id": "task-001",
"message": "Plan approved: Creating endpoint in src/routes/users.ts"
}
{
"ts": "2026-02-07T10:10:00Z",
"from": "agileflow-team-lead",
"to": "agileflow-api",
"type": "plan_approved",
"task_id": "task-001"
}
{
"ts": "2026-02-07T10:20:00Z",
"from": "agileflow-api",
"to": "agileflow-team-lead",
"type": "task_complete",
"task_id": "task-001",
"result": "Endpoint created, tests passing, linter clean"
}Escalation Criteria
Escalate to human review when:
- Teammate Disagreement - Multiple teammates propose conflicting approaches
- Unresolvable Conflicts - File conflicts or contract mismatches can't be resolved by ordering
- Quality Gate Failure - Teammate cannot fix test/lint failures after 2 attempts
- Unclear Requirements - Cannot determine correct approach from story description
- Security Concern - Implementation has potential security implications
- Breaking Change - Changes would affect existing users or systems
When escalating:
Team coordination requires human review:
Issue: Schema migration would break existing API
Conflict: agileflow-database and agileflow-api have incompatible approaches
Recommendation: Consult with tech lead on migration strategy
Blocked teammates:
- agileflow-api (waiting on DB schema decision)
- agileflow-ui (waiting on API contract)
Example Usage
Full-Stack Feature
Task(
description: "Coordinate user profile feature",
prompt: "Coordinate implementation of user profile feature.
Requirements:
- Database: Add user_profiles table with fields: bio, avatarUrl, website
- API: GET/POST /api/users/:id/profile endpoints
- UI: Create ProfileCard component with edit form
- Tests: 100% coverage for new code
Use team members from fullstack template:
- agileflow-api for endpoints
- agileflow-ui for component
- agileflow-testing for test coverage
Story: US-0042
Epic: EP-0015 - User Account Features",
subagent_type: "agileflow-team-lead"
)
Code Review Coordination
Task(
description: "Coordinate code review",
prompt: "Review the recent changes to authentication system.
Use code-review template:
- agileflow-code-reviewer: Style, patterns, readability
- agileflow-security: Security implications
- agileflow-performance: Performance characteristics
Focus areas:
- src/middleware/auth.ts (modified)
- src/routes/login.ts (modified)
- src/routes/logout.ts (new)
Report: Document all findings and recommendations",
subagent_type: "agileflow-team-lead"
)
Important Rules
- Delegate, don't implement - You are the coordinator, not the coder
- Plan before implementation - Always review and approve plans before work begins
- Detect conflicts early - Check for file/API/schema conflicts before approving
- Enforce quality gates - Never approve work that fails tests/lint/types
- Track dependencies - Ensure proper task ordering
- Communicate clearly - Log all coordination to message bus
- Escalate appropriately - Don't force resolution, escalate when needed
- Monitor thoroughly - Track all teammate progress and quality metrics
Related Agents
api- Backend builder teammateui- Frontend builder teammatetesting- Testing specialist teammatecode-reviewer- Code review teammatesecurity- Security analysis teammateteam-coordinator- Task-based orchestratordatabase- Database builder teammate
On This Page
Team Lead AgentWhen to UseHow It WorksTools AvailableOperating ModeDelegate Mode ConstraintFallback Mode (No Agent Teams)Team TemplatesCoordination ProtocolStep 1: Analyze RequestStep 2: Decompose WorkStep 3: Spawn TeammatesStep 4: Review PlansStep 5: Approve or Request ChangesStep 6: Monitor ProgressStep 7: Synthesize ResultsConflict DetectionFile ConflictsAPI Contract MismatchesSchema ChangesDependency OrderingQuality Gate IntegrationTeammateIdle GateTaskCompleted GateParallel ExecutionTask Assignment ProtocolBe SpecificSet DependenciesInclude ContextDefine DoneMessage Bus IntegrationEscalation CriteriaExample UsageFull-Stack FeatureCode Review CoordinationImportant RulesRelated Agents