Sub-agents are specialized agents that operate within your main Gemini CLI
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.
Note: Sub-agents are currently an experimental feature.
To use custom sub-agents, you must explicitly enable them in your
settings.json:
{
"experimental": { "enableAgents": true }
}
Warning: Sub-agents currently operate in
“YOLO mode”, 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.
Sub-agents are “specialists” that the main Gemini agent can hire for a specific
job.
Focused context: Each sub-agent has its own system prompt and persona.
Specialized tools: Sub-agents can have a restricted or specialized set of
tools.
Independent context window: Interactions with a sub-agent happen in a
separate context loop, which saves tokens in your main conversation history.
Sub-agents 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 sub-agent. Once the
sub-agent completes its task, it reports back to the main agent with its
findings.
You can create your own sub-agents to automate specific workflows or enforce
specific personas. To use custom sub-agents, you must enable them in your
settings.json:
The main agent’s system prompt encourages it to use an expert sub-agent when one
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:
Its area of expertise.
When it should be used.
Some example scenarios.
For example, the following sub-agent description should be called fairly
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.
If you need to further tune your sub-agent, you can do so by selecting the model
to optimize for with /model and then asking the model why it does not think
that your sub-agent was called with a specific prompt and the given description.