5.4 KiB
Technical Specification: Subagent Policy Isolation and Unique Toolsets
Overview
This specification details the implementation of independent policies and unique, isolated toolsets for subagents. Currently, subagents inherit the primary agent's policy and toolset, which limits isolation and security. The proposed mechanism allows subagents to have private tools (built-in and MCP) that are hidden from the primary agent and subject to their own scoped policies.
1. YAML Frontmatter Schema
The subagent Markdown configuration (.md files) will be updated to support a policy block and an mcp_servers block in the YAML frontmatter.
Schema Definition
---
name: security-specialist
display_name: Security Specialist
description: Expert in vulnerability scanning and security audits.
# Explicitly listed tools available to the subagent
tools:
- builtin:read_file
- mcp:security-scanner:scan_vulnerabilities
# Scoped policy for the subagent
policy:
tools:
allowed:
- "builtin:read_file"
- "mcp:security-scanner:*"
exclude:
- "builtin:shell"
- "builtin:write_file"
mcp:
allowed:
- "security-scanner"
excluded:
- "*"
# Trust configuration for MCP servers
mcp_servers:
security-scanner:
trust: true
# MCP servers private to this subagent
mcp_servers:
security-scanner:
command: "npx"
args: ["@security/mcp-server"]
env:
API_KEY: "${SECURITY_API_KEY}"
---
2. Orchestration and Scoping Logic
The isolation is enforced by creating a scoped execution context for each subagent.
Scoped Config and Policy Engine
LocalAgentExecutor.create: When a subagent is instantiated, it will no longer share the globalConfigdirectly.- Config Scoping: A new method
Config.createScopedConfig()will be implemented to create a lightweight fork of the configuration. - Policy Isolation: If the subagent definition includes a
policyblock, a newPolicyEngineinstance will be created using these settings. This engine will be used by the subagent'sToolRegistry. - Tool Registry Scoping: The subagent's
ToolRegistrywill be initialized with the scopedPolicyEngine. It will prioritize tools explicitly defined in the subagent'stoolslist andmcp_serversblock.
3. Extension Authors and Private MCP Tools
Extension authors can now define MCP servers that are only available to specific agents within that extension, hiding them from the primary agent.
gemini-extension.json Updates
MCP servers in extensions can now specify a visibility field.
{
"name": "security-extension",
"mcpServers": {
"private-audit-tool": {
"command": "...",
"visibility": "private"
}
},
"agents": [
{
"name": "auditor",
"path": "agents/auditor.md"
}
]
}
visibility: "public"(default): Registered globally and available to the primary agent.visibility: "private": Not registered globally. TheExtensionManagerwill attach these server configurations to the agents loaded from the same extension.
4. Component Updates
Agent Registry (packages/core/src/agents/registry.ts)
- Update
AgentDefinitionand its internal storage to hold the scopedpolicyand privatemcpServers. - Ensure
registerAgenthandles the ingestion of these new fields.
Tool Registry / Dispatcher (packages/core/src/tools/tool-registry.ts)
- The registry will now correctly filter tools based on the scoped
PolicyEngineprovided during construction. - It will support dynamic registration of subagent-specific MCP servers without affecting the global registry.
Configuration Parser (packages/core/src/agents/agentLoader.ts)
- Update
FrontmatterLocalAgentDefinitionandlocalAgentSchema(Zod) to include thepolicyandmcp_serversfields. - Update
markdownToAgentDefinitionto map these fields to the internalAgentDefinition.
5. Runtime Enforcement
Boundaries are enforced at multiple levels:
- Discovery Boundary: The primary agent's
ToolRegistrynever sees "private" or "internal" MCP tools. - Policy Boundary: The subagent's
PolicyEngineindependently evaluates every tool call against the subagent's specificallow/excluderules. - Execution Boundary:
LocalAgentExecutorvalidates all incomingfunction_callrequests against the subagent's scopedToolRegistrybefore scheduling execution.
Implementation Roadmap
Phase 1: Core Types and Parsing
- Update
AgentDefinitionandLocalAgentDefinitiontypes incore/agents/types.ts. - Update Zod schemas and parsing logic in
core/agents/agentLoader.ts. - Add
visibilityfield toMCPServerConfigincore/config/config.ts.
Phase 2: Configuration Scoping
- Implement
Config.createScopedConfig()incore/config/config.ts. - Update
PolicyEngineto support initialization fromPolicySettings.
Phase 3: Isolated Execution
- Modify
LocalAgentExecutor.createto use scoped config and policy. - Implement logic to start and register subagent-specific MCP servers in the isolated
ToolRegistry. - Update
ExtensionManagerincli/config/extension-manager.tsto handle private MCP server visibility.
Phase 4: Validation and Testing
- Add unit tests for scoped policy enforcement.
- Add integration tests for subagent-specific MCP tools.
- Verify that private tools are not leaked to the primary agent's
ToolRegistry.