Skip to content

docs(core): add subagent tool isolation draft doc#23275

Merged
abhipatel12 merged 7 commits intomainfrom
docs/subagent-tool-isolation
Apr 1, 2026
Merged

docs(core): add subagent tool isolation draft doc#23275
abhipatel12 merged 7 commits intomainfrom
docs/subagent-tool-isolation

Conversation

@akh64bit
Copy link
Copy Markdown
Contributor

Summary

This PR introduces a draft documentation file for the new "Subagent Tool Isolation" feature. It consolidates the behavior, architecture, and user experience improvements shipped across PRs #21935, #22708, #22712, #22718, and #21431.

Details

The document, docs/core/subagent-tool-isolation-draft.md, provides a comprehensive overview of how subagents can now define their own tools and inline MCP servers in their frontmatter. It also covers the multi-registry architecture for state isolation and the new TOML-based granular policy enforcement per subagent.

Related Issues

Related to #21935, #22708, #22712, #22718, #21431.

How to Validate

Read the newly added docs/core/subagent-tool-isolation-draft.md file and verify it aligns with the expected format and content.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
    • Windows
    • Linux

@akh64bit akh64bit requested review from a team as code owners March 20, 2026 17:30
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 20, 2026

Hi @akh64bit, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive documentation for the "Subagent Tool Isolation" feature in Gemini CLI. This feature significantly enhances the security and stability of subagents by enabling them to operate within isolated execution environments. It provides mechanisms for subagents to declare their own tools and inline MCP servers, and allows for granular, subagent-specific policy enforcement, thereby preventing unintended interactions and improving overall system reliability.

Highlights

  • Subagent Tool Definition: Subagents can now explicitly define their own set of tools using a "tools" list within their markdown frontmatter, moving away from a shared global tool registry.
  • Inline MCP Server Configuration: The feature allows subagents to configure inline Model Context Protocol (MCP) servers directly in their markdown frontmatter, ensuring these servers are isolated to that specific agent.
  • Granular Policy Enforcement: Subagent-specific policies can be enforced using TOML configuration, allowing for fine-grained control over permissions by adding a "subagent" property to policy rules.
  • State Isolation: The architecture ensures state isolation for subagents by using an isolated "MessageBus" and cloning tools for each subagent, preventing state leakage and improving reliability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 20, 2026

Size Change: -4 B (0%)

Total Size: 34.6 MB

Filename Size Change
./bundle/chunk-7MO7ZKXS.js 0 B -14.7 MB (removed) 🏆
./bundle/chunk-VOLHWSGT.js 0 B -3.82 MB (removed) 🏆
./bundle/core-YGWW6N7R.js 0 B -44.8 kB (removed) 🏆
./bundle/devtoolsService-DTUJ4BBJ.js 0 B -28.4 kB (removed) 🏆
./bundle/interactiveCli-SIBN4M6R.js 0 B -1.66 MB (removed) 🏆
./bundle/oauth2-provider-6ZPMT4JX.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-W6X5LEV4.js 14.7 MB +14.7 MB (new file) 🆕
./bundle/chunk-XWPWWYSS.js 3.82 MB +3.82 MB (new file) 🆕
./bundle/core-H4TWHWS4.js 44.8 kB +44.8 kB (new file) 🆕
./bundle/devtoolsService-NBKG6G6F.js 28.4 kB +28.4 kB (new file) 🆕
./bundle/interactiveCli-CECTG6UB.js 1.66 MB +1.66 MB (new file) 🆕
./bundle/oauth2-provider-YQBEIN5E.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
./bundle/bundled/third_party/index.js 8 MB
./bundle/chunk-34MYV7JD.js 2.45 kB
./bundle/chunk-5AUYMPVF.js 858 B
./bundle/chunk-664ZODQF.js 124 kB
./bundle/chunk-DAHVX5MI.js 206 kB
./bundle/chunk-IUUIT4SU.js 56.5 kB
./bundle/chunk-R5X4CMUM.js 1.96 MB
./bundle/chunk-RJTRUG2J.js 39.8 kB
./bundle/chunk-U4FACSVX.js 1.13 kB
./bundle/devtools-36NN55EP.js 696 kB
./bundle/dist-T73EYRDX.js 356 B
./bundle/events-CLX3JQHP.js 418 B
./bundle/gemini.js 533 kB
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB
./bundle/memoryDiscovery-VL3OH25S.js 980 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB
./bundle/src-QVCVGIUX.js 47 kB
./bundle/tree-sitter-7U6MW5PS.js 274 kB
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB

compressed-size-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR adds a new documentation file, docs/core/subagent-tool-isolation-draft.md, which comprehensively explains the subagent tool isolation feature in Gemini CLI. The document covers configuration, policies, architecture, and user experience improvements. The review identified a high severity issue regarding clarity on MCP and a critical issue with an incorrect TOML example, both of which have been retained.

Note: Security Review has been skipped due to the limited scope of the PR.

Comment on lines +77 to +85
```toml
[[rules]]
name = "Allow docs-writer to read docs"
subagent = "docs-writer"
description = "Permit reading files in the docs directory."
action = "allow"
tools = ["read_file"]
args = { file_path = "^docs/.*" }
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The TOML example lacks a [[rules]] block name, which is required. This could lead to confusion and incorrect policy configurations. The example should be corrected to include the [[rules]] block name.

Suggested change
```toml
[[rules]]
name = "Allow docs-writer to read docs"
subagent = "docs-writer"
description = "Permit reading files in the docs directory."
action = "allow"
tools = ["read_file"]
args = { file_path = "^docs/.*" }
```
[[rules]]
name = "Allow docs-writer to read docs"
subagent = "docs-writer"
description = "Permit reading files in the docs directory."
action = "allow"
tools = ["read_file"]
args = { file_path = "^docs/.*" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name attribute is already present in the TOML example.

Comment on lines +8 to +11

Subagent tool isolation moves Gemini CLI away from a single global tool
registry. Previously, subagents shared the same tool instances as the main
agent. This caused state leakage and prevented you from defining agent-specific
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The description mentions integration via MCP (Model Context Protocol). It would be helpful to briefly define MCP here, as some readers may not be familiar with it. This is especially important given the document focuses on MCP server configurations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I have added a brief explanation of MCP in the overview section where it is first mentioned.

@gemini-cli gemini-cli bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 20, 2026
Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few commnents, lmk what you think

(which provide a standardized way to connect AI models to external tools and
data sources) directly in the subagent's markdown frontmatter, isolating them
to that specific agent.
- **Maintain state isolation:** Use an isolated `MessageBus` for communication,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an impl detail. We don't need this in the public documentation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've removed the MessageBus implementation details.

- **Maintain state isolation:** Use an isolated `MessageBus` for communication,
as tools are cloned for each subagent.
- **Apply subagent-specific policies:** Enforce granular policy rules based on
the executing subagent's name using TOML configuration.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it clear that this is talking about the policy engine / policy toml files

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've updated the terminology to explicitly reference the Policy Engine and TOML files.

To restrict a policy rule to a specific subagent, add the `subagent` property to
the `[[rules]]` block in your `policy.toml` file.

**Example:**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a different example? Isn't the read tool default allow already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I've updated the example to use run_shell_command with git push to demonstrate a more practical use case for restricting a tool.

---
```

### Subagent-specific policies
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkcinouye Is the expert here, but should we put this in the policy section and link there with some short example, or link from the policy docs to this section?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a link from this section directly to the Policy Engine reference to tie them together.


In this configuration, the policy rule only triggers if the executing subagent's
name matches `docs-writer`. Rules without the `subagent` property apply
universally to all agents. The `LocalAgentExecutor` automatically injects the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid implementation details like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

subagent's context into the tool execution flow to ensure accurate policy
enforcement.

### How it works
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire section feels like a lot of technical details that are not entirely necessary for users that want to configure subagents. Maybe we can track this in the future for a architecture style doc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I've removed the 'How it works' section entirely to keep this focused on user configuration.

Copy link
Copy Markdown
Contributor

@jkcinouye jkcinouye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

abhipatel12 and others added 3 commits March 30, 2026 14:37
- Remove MessageBus and LocalAgentExecutor implementation details from subagents.md

- Clarify TOML terminology in policy-engine.md

- Update quick start example to use rm -rf for better clarity

- Update subagent example to codebase_investigator
@akh64bit akh64bit enabled auto-merge March 31, 2026 19:42
@akh64bit akh64bit added this pull request to the merge queue Mar 31, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 31, 2026
@akh64bit akh64bit added this pull request to the merge queue Mar 31, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 31, 2026
@akh64bit akh64bit added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@abhipatel12 abhipatel12 enabled auto-merge April 1, 2026 18:29
@abhipatel12 abhipatel12 added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit d9d51ba Apr 1, 2026
26 of 27 checks passed
@abhipatel12 abhipatel12 deleted the docs/subagent-tool-isolation branch April 1, 2026 18:57
DavidAPierce pushed a commit that referenced this pull request Apr 2, 2026
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
danzaharia1 pushed a commit that referenced this pull request Apr 2, 2026
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
kalenkevich pushed a commit to kalenkevich/gemini-cli that referenced this pull request Apr 3, 2026
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
afanty2021 pushed a commit to afanty2021/gemini-cli that referenced this pull request Apr 4, 2026
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants