Subagent Delegation
Overview
A subagent is a focused task handed to an agent that runs in its own isolated context. Kiro launches subagents automatically when a request matches an agent's description, or on demand when you say "Run subagents to ...". Use them to keep the main conversation lean, run independent tracks in parallel, or chain specialists into a pipeline.
Subagents are Markdown files in .kiro/agents/ (workspace) or ~/.kiro/agents/ (user). This starter ships three, mirrored from .github/agents/:
| Subagent |
Delegate when you need… |
code-reviewer |
Five-axis review (correctness, readability, architecture, security, performance) + Buildpad/DaaS compliance, after writing or changing code |
test-engineer |
Test-suite design, coverage-gap analysis, or writing Playwright/Vitest tests |
security-auditor |
Security review of auth, CORS/RLS, input handling, secrets |
When to Delegate
- Parallel, independent work — several read-only research tracks, or reviewing multiple modules at once.
- Specialized review — hand a finished slice to
code-reviewer / security-auditor instead of self-reviewing inline.
- Context isolation — a large exploration (e.g., "map how auth flows through the app") would flood the main context; a subagent returns just the summary.
- Pipelines — implement →
code-reviewer → security-auditor, each stage building on the last.
When NOT to Delegate
- The task is trivial or you need tight, iterative back-and-forth.
- Steps share mutable state or must run in strict order (DB migrations, a single edit sequence).
- The subagent would need most of your current context to make progress — the hand-off cost outweighs the benefit.
Delegation adds coordination overhead. If a task is small and sequential, just do it on the main thread.
How to Delegate
- Write a self-contained brief. Subagents do NOT see your conversation. State the goal, the exact files/paths, constraints, and the output you want back.
- Launch. Let Kiro auto-match by description, or be explicit: "Run subagents to review
app/items/ with code-reviewer and audit app/api/auth/ with security-auditor."
- Parallelize only independent work. For work that shares an interface, define the contract first (see
planning-and-task-breakdown), then fan out.
- Integrate on the main thread. Treat subagent output as advisory. Apply fixes, resolve conflicts, and run the build/tests yourself before declaring done.
Patterns
Fan-out (research): main ─┬─ subagent: "map data model in src/collections"
├─ subagent: "list all /api routes + auth guards"
└─ subagent: "inventory Buildpad components used"
main merges the three summaries.
Pipeline (quality): implement slice → code-reviewer → security-auditor → fix → verify
Map (review at scale): one code-reviewer subagent per changed module, in parallel
DaaS / Buildpad Notes
- Route Buildpad-First and proxy-pattern compliance checks to
code-reviewer.
- Route CORS/RLS/OAuth and secret-handling checks to
security-auditor.
- Route Playwright coverage and RBAC test design to
test-engineer.
- Give research subagents the MCP context they need (project detail, collection schemas) in the brief — they start with a clean context.
Common Rationalizations
| Rationalization |
Reality |
| "Delegating is always faster" |
Only for independent or isolatable work. Sequential, shared-state work is slower split up. |
| "The subagent knows what I know" |
It starts fresh. An underspecified brief produces a useless result. |
| "I'll skip the main-thread verification" |
Subagent output is advisory. Nothing is done until the build and tests pass on the main thread. |
Red Flags
- Delegating a task that needs your live context to make sense.
- Parallelizing work that shares an API contract without defining it first.
- Accepting subagent results without integrating and verifying them.
- Spawning subagents for a one-file change.
Verification
1---2name: subagent-delegation3description: Delegates focused work to Kiro subagents that run in isolated context. Use when work can run in parallel, when a specialized agent fits (code review, testing, security, research), or when a long task would otherwise bloat the main conversation. Trigger with "run subagents to ...".4---56# Subagent Delegation78## Overview910A subagent is a focused task handed to an agent that runs in its **own isolated context**. Kiro launches subagents automatically when a request matches an agent's `description`, or on demand when you say "Run subagents to ...". Use them to keep the main conversation lean, run independent tracks in parallel, or chain specialists into a pipeline.1112Subagents are Markdown files in `.kiro/agents/` (workspace) or `~/.kiro/agents/` (user). This starter ships three, mirrored from `.github/agents/`:1314| Subagent | Delegate when you need… |15|---|---|16| `code-reviewer` | Five-axis review (correctness, readability, architecture, security, performance) + Buildpad/DaaS compliance, after writing or changing code |17| `test-engineer` | Test-suite design, coverage-gap analysis, or writing Playwright/Vitest tests |18| `security-auditor` | Security review of auth, CORS/RLS, input handling, secrets |1920## When to Delegate2122- **Parallel, independent work** — several read-only research tracks, or reviewing multiple modules at once.23- **Specialized review** — hand a finished slice to `code-reviewer` / `security-auditor` instead of self-reviewing inline.24- **Context isolation** — a large exploration (e.g., "map how auth flows through the app") would flood the main context; a subagent returns just the summary.25- **Pipelines** — implement → `code-reviewer` → `security-auditor`, each stage building on the last.2627## When NOT to Delegate2829- The task is trivial or you need tight, iterative back-and-forth.30- Steps share mutable state or must run in strict order (DB migrations, a single edit sequence).31- The subagent would need most of your current context to make progress — the hand-off cost outweighs the benefit.3233Delegation adds coordination overhead. If a task is small and sequential, just do it on the main thread.3435## How to Delegate36371. **Write a self-contained brief.** Subagents do NOT see your conversation. State the goal, the exact files/paths, constraints, and the output you want back.382. **Launch.** Let Kiro auto-match by description, or be explicit: "Run subagents to review `app/items/` with code-reviewer and audit `app/api/auth/` with security-auditor."393. **Parallelize only independent work.** For work that shares an interface, define the contract first (see `planning-and-task-breakdown`), then fan out.404. **Integrate on the main thread.** Treat subagent output as advisory. Apply fixes, resolve conflicts, and run the build/tests yourself before declaring done.4142## Patterns4344```45Fan-out (research): main ─┬─ subagent: "map data model in src/collections"46 ├─ subagent: "list all /api routes + auth guards"47 └─ subagent: "inventory Buildpad components used"48 main merges the three summaries.4950Pipeline (quality): implement slice → code-reviewer → security-auditor → fix → verify5152Map (review at scale): one code-reviewer subagent per changed module, in parallel53```5455## DaaS / Buildpad Notes5657- Route Buildpad-First and proxy-pattern compliance checks to `code-reviewer`.58- Route CORS/RLS/OAuth and secret-handling checks to `security-auditor`.59- Route Playwright coverage and RBAC test design to `test-engineer`.60- Give research subagents the MCP context they need (project detail, collection schemas) in the brief — they start with a clean context.6162## Common Rationalizations6364| Rationalization | Reality |65|---|---|66| "Delegating is always faster" | Only for independent or isolatable work. Sequential, shared-state work is slower split up. |67| "The subagent knows what I know" | It starts fresh. An underspecified brief produces a useless result. |68| "I'll skip the main-thread verification" | Subagent output is advisory. Nothing is done until the build and tests pass on the main thread. |6970## Red Flags7172- Delegating a task that needs your live context to make sense.73- Parallelizing work that shares an API contract without defining it first.74- Accepting subagent results without integrating and verifying them.75- Spawning subagents for a one-file change.7677## Verification7879- [ ] Each delegated task had a self-contained brief (goal, files, constraints, expected output).80- [ ] Only independent work was parallelized; shared contracts were defined first.81- [ ] Subagent results were integrated on the main thread.82- [ ] Build and tests pass after integration.