← Back to Index

Lesson 8

Sub-agents

What Sub-agents Are

A sub-agent is a separate agent instance that Kiro spawns to handle a focused task. It runs in its own isolated context window - meaning it doesn't share the main conversation's history, and its work doesn't pollute the main agent's context.

When it finishes, it returns its results to the main agent, which incorporates them into the conversation.

Why They Exist

Two problems they solve:

  1. Context preservation - if Kiro needs to read 20 files to answer a question, doing that in the main conversation eats your context budget. A sub-agent does the exploration in its own window, then returns a concise summary. Your main context stays lean.
  2. Parallelism - Kiro can run multiple sub-agents at the same time. "Update the tests AND update the docs" can happen concurrently rather than sequentially.

The Built-in Sub-agents

Kiro has several built-in sub-agents in the IDE. The two you'll encounter most often:

Sub-agentPurposeWhen Kiro uses it
Context gathererExplores the codebase to find relevant files and understand structureWhen it needs to understand an unfamiliar area before making changes
General purposeExecutes any task - code changes, file operations, researchWhen parallelising independent tasks

There are also specialised built-in sub-agents for tasks like creating custom agent configurations and performing semantic code reviews. Each has its own context window, tools, and decision-making. They can read files, run commands, and make changes - same capabilities as the main agent.

Automatic vs Manual Launch

Automatic

Kiro decides on its own when to use sub-agents. For complex tasks, it may spin up a context gatherer to explore before acting, or launch parallel general-purpose agents to work on independent parts simultaneously. You don't need to ask - it happens transparently.

You'll see sub-agent activity in the chat as collapsible sections showing what each agent did.

Manual

You can explicitly instruct Kiro to use sub-agents:

When you say "in parallel" or "use subagents", Kiro takes the hint and delegates accordingly.

Context Isolation: The Key Mechanic

This is the important part to understand. Each sub-agent gets:

What it does NOT get:

Why this matters: A sub-agent exploring 20 files to find relevant context uses tokens in its own window. When it reports back, only the concise result enters the main conversation - not all 20 files. This is how sub-agents keep the main context lean.
Ad

Custom Sub-agents

Beyond the two built-in ones, you can create custom sub-agents for specialised tasks. This is where it connects to Custom Agents (covered in Lesson 9) - you define an agent configuration with specific tools, MCP servers, and prompts, then Kiro can spawn it as a sub-agent when relevant.

Example use cases for custom sub-agents:

Each stays focused on its domain, managing its own context efficiently.

When Sub-agents Help vs. When They Don't

Good use casesDon't bother when
Exploring unfamiliar code before making changesThe task is simple and linear
Independent tasks that can run in parallelTasks are tightly dependent on each other
Keeping main context clean during researchYou need to see every step interactively
Large-scale changes across many filesYou're editing one file
Different domains (frontend + backend) simultaneouslyEverything is in one domain

What You See in the UI

When sub-agents run, you'll see:

Sub-agents are only available in Autopilot mode - they don't run in Supervised mode (where you approve each action individually).

Practical Example

You ask: "Refactor the user service to use signals instead of BehaviorSubjects"

Kiro might:

  1. Launch a context gatherer sub-agent to find all files that use UserService and understand the dependency graph
  2. Based on the gathered context, plan the refactor
  3. Launch parallel general-purpose sub-agents to:
    • Update the service itself
    • Update the components that consume it
    • Update the related tests
  4. Synthesize the results back into the main conversation

You see one coherent result, but the work was distributed across multiple agents with isolated contexts.

Your Tangible Win

You now understand what sub-agents are, why context isolation matters, how to trigger them manually, and when they're worth using. You know the two built-in types (context gatherer and general purpose) and that custom sub-agents are possible for specialised domains.

Quiz

A sub-agent reads 15 files while exploring your codebase. How many of those files' contents end up in the main conversation's context?

All 15 - the main agent inherits everything
None directly - only the sub-agent's concise result/summary enters the main context
Only the files that were relevant to the final answer

You want Kiro to update tests and docs simultaneously. How do you trigger parallel sub-agents?

Configure sub-agents in .kiro/settings/
Just ask - "update the tests and docs in parallel" or "use subagents to..."
Sub-agents only run automatically - you can't trigger them manually

Sub-agents are available in which autonomy mode?

Autopilot only
Both Autopilot and Supervised
Supervised only (since they need approval)