mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-21 19:40:40 -07:00
fix(core): ensure sub-agents are registered regardless of tools.allowed (#18870)
This commit is contained in:
@@ -1036,6 +1036,44 @@ describe('Server Config (config.ts)', () => {
|
||||
expect(registeredWrappers).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should register subagents as tools even when they are not in allowedTools', async () => {
|
||||
const params: ConfigParameters = {
|
||||
...baseParams,
|
||||
allowedTools: ['read_file'], // codebase-investigator is NOT here
|
||||
agents: {
|
||||
overrides: {
|
||||
codebase_investigator: { enabled: true },
|
||||
},
|
||||
},
|
||||
};
|
||||
const config = new Config(params);
|
||||
|
||||
const mockAgentDefinition = {
|
||||
name: 'codebase-investigator',
|
||||
description: 'Agent 1',
|
||||
instructions: 'Inst 1',
|
||||
};
|
||||
|
||||
const AgentRegistryMock = (
|
||||
(await vi.importMock('../agents/registry.js')) as {
|
||||
AgentRegistry: Mock;
|
||||
}
|
||||
).AgentRegistry;
|
||||
AgentRegistryMock.prototype.getAllDefinitions.mockReturnValue([
|
||||
mockAgentDefinition,
|
||||
]);
|
||||
|
||||
const SubAgentToolMock = (
|
||||
(await vi.importMock('../agents/subagent-tool.js')) as {
|
||||
SubagentTool: Mock;
|
||||
}
|
||||
).SubagentTool;
|
||||
|
||||
await config.initialize();
|
||||
|
||||
expect(SubAgentToolMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not register subagents as tools when agents are disabled', async () => {
|
||||
const params: ConfigParameters = {
|
||||
...baseParams,
|
||||
|
||||
@@ -2469,26 +2469,16 @@ export class Config {
|
||||
agentsOverrides['codebase_investigator']?.enabled !== false ||
|
||||
agentsOverrides['cli_help']?.enabled !== false
|
||||
) {
|
||||
const allowedTools = this.getAllowedTools();
|
||||
const definitions = this.agentRegistry.getAllDefinitions();
|
||||
|
||||
for (const definition of definitions) {
|
||||
const isAllowed =
|
||||
!allowedTools || allowedTools.includes(definition.name);
|
||||
|
||||
if (isAllowed) {
|
||||
try {
|
||||
const tool = new SubagentTool(
|
||||
definition,
|
||||
this,
|
||||
this.getMessageBus(),
|
||||
);
|
||||
registry.registerTool(tool);
|
||||
} catch (e: unknown) {
|
||||
debugLogger.warn(
|
||||
`Failed to register tool for agent ${definition.name}: ${getErrorMessage(e)}`,
|
||||
);
|
||||
}
|
||||
try {
|
||||
const tool = new SubagentTool(definition, this, this.getMessageBus());
|
||||
registry.registerTool(tool);
|
||||
} catch (e: unknown) {
|
||||
debugLogger.warn(
|
||||
`Failed to register tool for agent ${definition.name}: ${getErrorMessage(e)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user