mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
feat: Add enableSubagents configuration and wire up subagent registration (#9988)
This commit is contained in:
@@ -76,6 +76,9 @@ import type { PolicyEngineConfig } from '../policy/types.js';
|
||||
import type { UserTierId } from '../code_assist/types.js';
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
|
||||
import { AgentRegistry } from '../agents/registry.js';
|
||||
import { SubagentToolWrapper } from '../agents/subagent-tool-wrapper.js';
|
||||
|
||||
export enum ApprovalMode {
|
||||
DEFAULT = 'default',
|
||||
AUTO_EDIT = 'autoEdit',
|
||||
@@ -255,11 +258,13 @@ export interface ConfigParameters {
|
||||
output?: OutputSettings;
|
||||
useModelRouter?: boolean;
|
||||
enableMessageBusIntegration?: boolean;
|
||||
enableSubagents?: boolean;
|
||||
}
|
||||
|
||||
export class Config {
|
||||
private toolRegistry!: ToolRegistry;
|
||||
private promptRegistry!: PromptRegistry;
|
||||
private agentRegistry!: AgentRegistry;
|
||||
private readonly sessionId: string;
|
||||
private fileSystemService: FileSystemService;
|
||||
private contentGeneratorConfig!: ContentGeneratorConfig;
|
||||
@@ -345,6 +350,7 @@ export class Config {
|
||||
private readonly outputSettings: OutputSettings;
|
||||
private readonly useModelRouter: boolean;
|
||||
private readonly enableMessageBusIntegration: boolean;
|
||||
private readonly enableSubagents: boolean;
|
||||
|
||||
constructor(params: ConfigParameters) {
|
||||
this.sessionId = params.sessionId;
|
||||
@@ -433,6 +439,7 @@ export class Config {
|
||||
this.useModelRouter = params.useModelRouter ?? false;
|
||||
this.enableMessageBusIntegration =
|
||||
params.enableMessageBusIntegration ?? false;
|
||||
this.enableSubagents = params.enableSubagents ?? false;
|
||||
this.extensionManagement = params.extensionManagement ?? true;
|
||||
this.storage = new Storage(this.targetDir);
|
||||
this.enablePromptCompletion = params.enablePromptCompletion ?? false;
|
||||
@@ -474,6 +481,10 @@ export class Config {
|
||||
await this.getGitService();
|
||||
}
|
||||
this.promptRegistry = new PromptRegistry();
|
||||
|
||||
this.agentRegistry = new AgentRegistry(this);
|
||||
await this.agentRegistry.initialize();
|
||||
|
||||
this.toolRegistry = await this.createToolRegistry();
|
||||
|
||||
await this.geminiClient.initialize();
|
||||
@@ -620,6 +631,10 @@ export class Config {
|
||||
return this.workspaceContext;
|
||||
}
|
||||
|
||||
getAgentRegistry(): AgentRegistry {
|
||||
return this.agentRegistry;
|
||||
}
|
||||
|
||||
getToolRegistry(): ToolRegistry {
|
||||
return this.toolRegistry;
|
||||
}
|
||||
@@ -996,6 +1011,10 @@ export class Config {
|
||||
return this.enableMessageBusIntegration;
|
||||
}
|
||||
|
||||
getEnableSubagents(): boolean {
|
||||
return this.enableSubagents;
|
||||
}
|
||||
|
||||
async createToolRegistry(): Promise<ToolRegistry> {
|
||||
const registry = new ToolRegistry(this, this.eventEmitter);
|
||||
|
||||
@@ -1087,6 +1106,41 @@ export class Config {
|
||||
registerCoreTool(WriteTodosTool, this);
|
||||
}
|
||||
|
||||
// Register Subagents as Tools
|
||||
if (this.getEnableSubagents()) {
|
||||
const agentDefinitions = this.agentRegistry.getAllDefinitions();
|
||||
for (const definition of agentDefinitions) {
|
||||
// We must respect the main allowed/exclude lists for agents too.
|
||||
const excludeTools = this.getExcludeTools() || [];
|
||||
const allowedTools = this.getAllowedTools();
|
||||
|
||||
const isExcluded = excludeTools.includes(definition.name);
|
||||
const isAllowed =
|
||||
!allowedTools || allowedTools.includes(definition.name);
|
||||
|
||||
if (isAllowed && !isExcluded) {
|
||||
try {
|
||||
const messageBusEnabled = this.getEnableMessageBusIntegration();
|
||||
const wrapper = new SubagentToolWrapper(
|
||||
definition,
|
||||
this,
|
||||
messageBusEnabled ? this.getMessageBus() : undefined,
|
||||
);
|
||||
registry.registerTool(wrapper);
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to wrap agent '${definition.name}' as a tool:`,
|
||||
error,
|
||||
);
|
||||
}
|
||||
} else if (this.getDebugMode()) {
|
||||
console.log(
|
||||
`[Config] Skipping registration of agent '${definition.name}' due to allow/exclude configuration.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await registry.discoverAllTools();
|
||||
return registry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user