← Back to Index

Lesson 9

Custom Agents

What Custom Agents Are

A custom agent is a specialised version of Kiro with its own system prompt, tool access, and optionally its own MCP servers. You define it in a config file, and Kiro can spawn it as a sub-agent when the task matches its description - or you can invoke it explicitly.

Think of it as: a sub-agent with a personality and toolbox you've defined in advance.

Where Custom Agents Live

ScopeLocationUse for
Workspace.kiro/agents/*.mdProject-specific agents (frontend agent, API agent)
Global~/.kiro/agents/*.mdPersonal agents you use across projects (review agent, docs agent)

Same two-scope pattern as steering and skills.

The Agent File Format (IDE)

In the IDE, a custom agent is a markdown file with YAML front-matter. The body is the agent's system prompt - the instructions it follows when spawned.

---
name: frontend-agent
description: Specialist in Angular components, templates, and browser tooling
model: auto
tools:
  - read_file
  - fs_write
  - str_replace
  - execute_bash
  - grep_search
mcpServers:
  - component-docs
---

You are a frontend specialist working on an Angular 18 application.

## Your expertise
- Angular standalone components with signals
- RxJS for async data streams
- Template syntax and change detection
- SCSS styling with our design token system

## Rules
- Always create standalone components
- Use inject() over constructor injection
- Prefer signals over BehaviorSubject for new code
- Run ng lint after changes

Front-matter Schema (IDE)

FieldRequiredWhat it does
nameNoAgent identifier (derived from filename if not specified)
descriptionYesUsed for auto-selection - Kiro matches tasks against this
modelNoWhich model to use (auto, claude-opus-4, claude-sonnet-4, etc.)
toolsNoList of tools this agent can access (restricts to only these)
mcpServersNoMCP servers available to this agent (by name from your mcp.json)

If you omit tools, the agent gets all tools. If you specify it, the agent is restricted to only those tools - useful for creating read-only agents or agents that can't run shell commands.

Tools format note: Recent versions of Kiro also support category-based tool access using tags like read, write, shell instead of individual tool names. Both approaches work - individual tool names give finer control, categories are more future-proof (new tools in a category are included automatically). Check the official docs for the current recommended format.

How Custom Agents Get Used

Automatic selection

Kiro reads the description of all available custom agents. When a task matches, it spawns the appropriate agent as a sub-agent. For example, if you ask "update the header component's styling" and you have a frontend-agent with a matching description, Kiro may choose to delegate to it.

Explicit invocation

You can name the agent directly: "Use the frontend-agent to refactor this component" or "Run the docs-agent on this file."

How is this different from asking a skill to run in parallel?

Both can run in parallel - the difference is about constraints and identity, not concurrency:

Skill (run in parallel)Custom agent (invoked explicitly)
Where instructions liveLoaded into whatever agent runs them (main or generic sub-agent)Permanently bound to the agent - its own system prompt
Tool accessFull - the executing agent has all toolsRestricted to only what's listed in the config
MCP accessAll configured MCP serversOnly the MCP servers specified in the agent's config
ModelUses whatever model is currently selectedCan specify its own model
IdentityTemporary instructions - different each time you invokeFixed identity that persists across uses

A skill is instructions anyone can follow. A custom agent is a specific person with defined capabilities and limits.

Practical Examples

Read-only research agent

---
description: Research and analyse code without making changes
tools:
  - read_file
  - grep_search
  - file_search
  - list_directory
---

You are a research assistant. Your job is to explore the codebase and
provide analysis. You cannot modify any files or run commands.

When asked to investigate something:
1. Search for relevant files
2. Read and understand the code
3. Provide a clear summary of findings
4. Suggest next steps (but don't implement them)

Test writer agent

---
description: Write and run unit tests for Angular components and services
tools:
  - read_file
  - fs_write
  - str_replace
  - execute_bash
  - grep_search
---

You are a testing specialist for an Angular application using Jest.

## Rules
- Every test file lives next to its source: `foo.component.spec.ts`
- Use Testing Library for component tests
- Mock HTTP calls with HttpClientTestingModule
- Run tests after writing: `npx jest --testPathPattern=<file>`
- Aim for meaningful assertions, not just coverage

Backend API agent

---
description: Work with the Node.js/Express API layer and database
tools:
  - read_file
  - fs_write
  - str_replace
  - execute_bash
  - grep_search
mcpServers:
  - postgres
---

You are a backend specialist working on the Express API.

## Your domain
- Routes in src/api/
- Services in src/services/
- Database access via the postgres MCP server

## Rules
- All endpoints validate input with zod
- Use parameterised queries (never string interpolation)
- Return consistent error responses: { error: string, code: number }
Ad

When and Why: Custom Agents vs. Just Asking Kiro

You might think: "Why not just ask Kiro to do this in the main conversation, or use a skill?" Here's when a custom agent genuinely adds value over alternatives:

Use a custom agent when you need:

NeedWhy a custom agent solves itWhy a skill/main agent doesn't
Tool restrictionAgent only has access to specific tools - can't accidentally write files or run commandsSkills and main agent always have all tools available
Scoped MCP accessAgent only connects to specific MCP servers (e.g. just the database, not GitHub)Main agent sees all configured MCP servers
Context isolationAgent's exploration doesn't bloat the main conversationSkills run in main context - every file read costs main tokens
A different modelCan use a cheaper/faster model for simple tasks, or a more capable one for hard tasksMain agent uses whatever model is currently selected
Repeatable identityThe agent's persona, rules, and constraints are defined once and reused across sessionsSkills provide instructions but no constraints on what tools can be used

Just use a skill (or ask Kiro directly) when:

Concrete comparison

Scenario: "Lint all components and fix issues"

Scenario: "Research how auth works in this codebase"

Rule of thumb: If you'd be comfortable giving the task to any sub-agent with full access, just ask Kiro directly (or use a skill). If you want constraints on what it can do, or a persistent identity with domain knowledge, that's when a custom agent earns its keep.

Tool restriction is a safety and focus mechanism:

Connection to hooks: You can combine this with PreToolUse hooks for defence in depth. The agent config restricts what tools are available; hooks can gate how those tools are used (e.g. blocking writes to certain directories).

Custom Agents vs Skills

Custom AgentsSkills
What they defineA whole agent identity (prompt + tools + model + MCP)Instructions for the main agent to follow
ExecutionRun in their own isolated context as sub-agentsRun in the main agent's context
Context isolationYes - own context windowNo - shares the main context
Tool restrictionCan limit which tools are availableNo - main agent keeps all tools
MCP scopingCan specify which MCP servers to useNo - uses whatever's configured globally
Best forDomain-specific delegation with safety constraintsReusable workflows the main agent follows

The CLI Difference

In the Kiro CLI, custom agents use a more elaborate YAML/JSON config format (not markdown) and support additional features like:

The IDE format (markdown with front-matter) is simpler but covers the common cases. If you move to the CLI for more advanced workflows, the config options expand significantly. See CLI Agent Config Reference for the full schema.

Your Tangible Win

You can now create custom agents with scoped tools, specific MCP access, and focused system prompts. You know how they differ from skills (isolated context, tool restriction, MCP scoping), how Kiro auto-selects them, and how to invoke them explicitly. You can build a team of specialised agents for your project.

Quiz

You want an agent that can read code but never modify it. How?

Add "read-only: true" to the front-matter
List only read tools in the "tools" front-matter field (read_file, grep_search, etc.)
You can't - all agents have all tools

What's the key difference between a custom agent and a skill?

Skills are more powerful
Custom agents run in their own isolated context as sub-agents; skills run in the main agent's context
Custom agents are CLI-only; skills are IDE-only

Where do IDE custom agents live?

.kiro/skills/*.md
.kiro/settings/agents.json
.kiro/agents/*.md (workspace) or ~/.kiro/agents/*.md (global)