2026-02-18 16:10:49 -08:00
# Subagents (experimental)
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
Subagents are specialized agents that operate within your main Gemini CLI
2026-01-27 18:24:37 +00:00
session. They are designed to handle specific, complex tasks—like deep codebase
analysis, documentation lookup, or domain-specific reasoning—without cluttering
the main agent's context or toolset.
2026-02-18 16:10:49 -08:00
> **Note: Subagents are currently an experimental feature.**
2026-01-27 18:24:37 +00:00
>
2026-02-18 16:10:49 -08:00
> To use custom subagents, you must explicitly enable them in your
2026-01-27 18:24:37 +00:00
> `settings.json`:
>
> ```json
> {
> "experimental": { "enableAgents": true }
> }
> ```
>
2026-02-18 16:10:49 -08:00
> **Warning:** Subagents currently operate in
2026-01-27 18:24:37 +00:00
> ["YOLO mode"](../get-started/configuration.md#command-line-arguments), meaning
> they may execute tools without individual user confirmation for each step.
> Proceed with caution when defining agents with powerful tools like
> `run_shell_command` or `write_file`.
2026-02-18 16:10:49 -08:00
## What are subagents?
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
Subagents are "specialists" that the main Gemini agent can hire for a specific
2026-01-29 15:52:06 -08:00
job.
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
- **Focused context:** Each subagent has its own system prompt and persona.
- **Specialized tools:** Subagents can have a restricted or specialized set of
2026-01-27 18:24:37 +00:00
tools.
2026-02-18 16:10:49 -08:00
- **Independent context window:** Interactions with a subagent happen in a
2026-01-29 15:52:06 -08:00
separate context loop, which saves tokens in your main conversation history.
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
Subagents are exposed to the main agent as a tool of the same name. When the
main agent calls the tool, it delegates the task to the subagent. Once the
subagent completes its task, it reports back to the main agent with its
2026-01-29 15:52:06 -08:00
findings.
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
## Built-in subagents
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
Gemini CLI comes with the following built-in subagents:
2026-01-27 18:24:37 +00:00
### Codebase Investigator
- **Name:** `codebase_investigator`
2026-01-29 15:52:06 -08:00
- **Purpose:** Analyze the codebase, reverse engineer, and understand complex
dependencies.
2026-01-27 18:24:37 +00:00
- **When to use:** "How does the authentication system work?", "Map out the
dependencies of the `AgentRegistry` class."
- **Configuration:** Enabled by default. You can configure it in
`settings.json` . Example (forcing a specific model):
```json
{
"experimental": {
"codebaseInvestigatorSettings": {
"enabled": true,
"maxNumTurns": 20,
"model": "gemini-2.5-pro"
}
}
}
```
### CLI Help Agent
- **Name:** `cli_help`
2026-01-29 15:52:06 -08:00
- **Purpose:** Get expert knowledge about Gemini CLI itself, its commands,
2026-01-27 18:24:37 +00:00
configuration, and documentation.
- **When to use:** "How do I configure a proxy?", "What does the `/rewind`
command do?"
- **Configuration:** Enabled by default.
2026-01-29 15:52:06 -08:00
### Generalist Agent
2026-01-27 18:24:37 +00:00
2026-01-29 15:52:06 -08:00
- **Name:** `generalist_agent`
2026-02-18 16:10:49 -08:00
- **Purpose:** Route tasks to the appropriate specialized subagent.
2026-01-29 15:52:06 -08:00
- **When to use:** Implicitly used by the main agent for routing. Not directly
invoked by the user.
- **Configuration:** Enabled by default. No specific configuration options.
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
## Creating custom subagents
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
You can create your own subagents to automate specific workflows or enforce
specific personas. To use custom subagents, you must enable them in your
2026-01-29 15:52:06 -08:00
`settings.json` :
2026-01-27 18:24:37 +00:00
```json
{
"experimental": {
"enableAgents": true
}
}
```
### Agent definition files
Custom agents are defined as Markdown files (`.md` ) with YAML frontmatter. You
can place them in:
1. **Project-level: ** `.gemini/agents/*.md` (Shared with your team)
2. **User-level: ** `~/.gemini/agents/*.md` (Personal agents)
### File format
The file **MUST ** start with YAML frontmatter enclosed in triple-dashes `---` .
The body of the markdown file becomes the agent's **System Prompt ** .
**Example: `.gemini/agents/security-auditor.md` **
```markdown
---
name: security-auditor
description: Specialized in finding security vulnerabilities in code.
kind: local
tools:
- read_file
2026-02-02 20:18:24 -08:00
- grep_search
2026-01-27 18:24:37 +00:00
model: gemini-2.5-pro
temperature: 0.2
max_turns: 10
---
You are a ruthless Security Auditor. Your job is to analyze code for potential
vulnerabilities.
Focus on:
2026-01-29 15:52:06 -08:00
1. SQL Injection
2. XSS (Cross-Site Scripting)
3. Hardcoded credentials
4. Unsafe file operations
2026-01-27 18:24:37 +00:00
When you find a vulnerability, explain it clearly and suggest a fix. Do not fix
it yourself; just report it.
```
### Configuration schema
2026-02-18 16:10:49 -08:00
| Field | Type | Required | Description |
| :------------- | :----- | :------- | :------------------------------------------------------------------------------------------------------------------------ |
| `name` | string | Yes | Unique identifier (slug) used as the tool name for the agent. Only lowercase letters, numbers, hyphens, and underscores. |
| `description` | string | Yes | Short description of what the agent does. This is visible to the main agent to help it decide when to call this subagent. |
| `kind` | string | No | `local` (default) or `remote` . |
| `tools` | array | No | List of tool names this agent can use. If omitted, it may have access to a default set. |
| `model` | string | No | Specific model to use (e.g., `gemini-2.5-pro` ). Defaults to `inherit` (uses the main session model). |
| `temperature` | number | No | Model temperature (0.0 - 2.0). |
| `max_turns` | number | No | Maximum number of conversation turns allowed for this agent before it must return. Defaults to `15` . |
| `timeout_mins` | number | No | Maximum execution time in minutes. Defaults to `5` . |
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
### Optimizing your subagent
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
The main agent's system prompt encourages it to use an expert subagent when one
2026-01-29 15:52:06 -08:00
is available. It decides whether an agent is a relevant expert based on the
agent's description. You can improve the reliability with which an agent is used
by updating the description to more clearly indicate:
2026-01-27 18:24:37 +00:00
- Its area of expertise.
- When it should be used.
- Some example scenarios.
2026-02-18 16:10:49 -08:00
For example, the following subagent description should be called fairly
2026-01-27 18:24:37 +00:00
consistently for Git operations.
> Git expert agent which should be used for all local and remote git operations.
> For example:
>
> - Making commits
> - Searching for regressions with bisect
> - Interacting with source control and issues providers such as GitHub.
2026-02-18 16:10:49 -08:00
If you need to further tune your subagent, you can do so by selecting the model
2026-01-27 18:24:37 +00:00
to optimize for with `/model` and then asking the model why it does not think
2026-02-18 16:10:49 -08:00
that your subagent was called with a specific prompt and the given description.
2026-01-27 18:24:37 +00:00
2026-01-29 09:48:27 -05:00
## Remote subagents (Agent2Agent) (experimental)
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
Gemini CLI can also delegate tasks to remote subagents using the Agent-to-Agent
2026-01-27 17:15:28 -05:00
(A2A) protocol.
2026-01-27 18:24:37 +00:00
2026-01-29 09:48:27 -05:00
> **Note: Remote subagents are currently an experimental feature.**
2026-01-27 17:15:28 -05:00
See the [Remote Subagents documentation ](/docs/core/remote-agents ) for detailed
configuration and usage instructions.
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
## Extension subagents
2026-01-27 18:24:37 +00:00
2026-02-18 16:10:49 -08:00
Extensions can bundle and distribute subagents. See the
[Extensions documentation ](../extensions/index.md#subagents ) for details on how
2026-01-27 18:24:37 +00:00
to package agents within an extension.