Subagents 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: Subagents are currently an experimental feature.
To use custom subagents, you must ensure they are enabled in your
settings.json (enabled by default):
Subagents are “specialists” that the main Gemini agent can hire for a specific
job.
Focused context: Each subagent has its own system prompt and persona.
Specialized tools: Subagents can have a restricted or specialized set of
tools.
Independent context window: Interactions with a subagent happen in a
separate context loop, which saves tokens in your main conversation history.
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
findings.
Gemini CLI’s main agent is instructed to use specialized subagents when a task
matches their expertise. For example, if you ask “How does the auth system
work?”, the main agent may decide to call the codebase_investigator subagent
to perform the research.
You can explicitly direct a task to a specific subagent by using the @ symbol
followed by the subagent’s name at the beginning of your prompt. This is useful
when you want to bypass the main agent’s decision-making and go straight to a
specialist.
Purpose: Analyze the codebase, reverse engineer, and understand complex
dependencies.
When to use: “How does the authentication system work?”, “Map out the
dependencies of the AgentRegistry class.”
Configuration: Enabled by default. You can override its settings in
settings.json under agents.overrides. Example (forcing a specific model
and increasing turns):
Purpose: Automate web browser tasks — navigating websites, filling forms,
clicking buttons, and extracting information from web pages — using the
accessibility tree.
When to use: “Go to example.com and fill out the contact form,” “Extract
the pricing table from this page,” “Click the login button and enter my
credentials.”
Note: This is a preview feature currently under active development.
The sessionMode setting controls how Chrome is launched and managed. Set it
under agents.browser:
{
"agents": {
"overrides": {
"browser_agent": {
"enabled": true
}
},
"browser": {
"sessionMode": "persistent"
}
}
}
The available modes are:
Mode
Description
persistent
(Default) Launches Chrome with a persistent profile stored at ~/.gemini/cli-browser-profile/. Cookies, history, and settings are preserved between sessions.
isolated
Launches Chrome with a temporary profile that is deleted after each session. Use this for clean-state automation.
existing
Attaches to an already-running Chrome instance. You must enable remote debugging first by navigating to chrome://inspect/#remote-debugging in Chrome. No new browser process is launched.
The browser agent enforces the following security restrictions:
Blocked URL patterns:file://, javascript:, data:text/html,
chrome://extensions, and chrome://settings/passwords are always blocked.
Sensitive action confirmation: Actions like form filling, file uploads,
and form submissions require user confirmation through the standard policy
engine.
By default, the browser agent interacts with pages through the accessibility
tree using element uid values. For tasks that require visual identification
(for example, “click the yellow button” or “find the red error message”), you
can enable the visual agent by setting a visualModel:
When enabled, the agent gains access to the analyze_screenshot tool, which
captures a screenshot and sends it to the vision model for analysis. The model
returns coordinates and element descriptions that the browser agent uses with
the click_at tool for precise, coordinate-based interactions.
Note: The visual agent requires API key or Vertex AI authentication. It is
not available when using “Sign in with Google”.
You can create your own subagents to automate specific workflows or enforce
specific personas. To use custom subagents, you must enable them in your
settings.json:
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. Supports wildcards: * (all tools), mcp_* (all MCP tools), mcp_server_* (all tools from a server). If omitted, it inherits all tools from the parent session.
model
string
No
Specific model to use (e.g., gemini-3-preview). Defaults to inherit (uses the main session model).
temperature
number
No
Model temperature (0.0 - 2.0). Defaults to 1.
max_turns
number
No
Maximum number of conversation turns allowed for this agent before it must return. Defaults to 30.
timeout_mins
number
No
Maximum execution time in minutes. Defaults to 10.
Each subagent runs in its own isolated context loop. This means:
Independent history: The subagent’s conversation history does not bloat
the main agent’s context.
Isolated tools: The subagent only has access to the tools you explicitly
grant it.
Recursion protection: To prevent infinite loops and excessive token usage,
subagents cannot call other subagents. If a subagent is granted the *
tool wildcard, it will still be unable to see or invoke other agents.
If you are in an interactive CLI session, you can use the /agents command to
manage subagents without editing configuration files manually. This is the
recommended way to quickly enable, disable, or re-configure agents on the fly.
While the /agents command and agent definition files provide a starting point,
you can use settings.json for global, persistent overrides. This is useful for
enforcing specific models or execution limits across all sessions.
You can target specific subagents with custom model settings (like system
instruction prefixes or specific safety settings) using the overrideScope
field.
The main agent’s system prompt encourages it to use an expert subagent 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 subagent 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 subagent, 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 subagent was called with a specific prompt and the given description.