mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -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);
|
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 () => {
|
it('should not register subagents as tools when agents are disabled', async () => {
|
||||||
const params: ConfigParameters = {
|
const params: ConfigParameters = {
|
||||||
...baseParams,
|
...baseParams,
|
||||||
|
|||||||
@@ -2469,26 +2469,16 @@ export class Config {
|
|||||||
agentsOverrides['codebase_investigator']?.enabled !== false ||
|
agentsOverrides['codebase_investigator']?.enabled !== false ||
|
||||||
agentsOverrides['cli_help']?.enabled !== false
|
agentsOverrides['cli_help']?.enabled !== false
|
||||||
) {
|
) {
|
||||||
const allowedTools = this.getAllowedTools();
|
|
||||||
const definitions = this.agentRegistry.getAllDefinitions();
|
const definitions = this.agentRegistry.getAllDefinitions();
|
||||||
|
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
const isAllowed =
|
try {
|
||||||
!allowedTools || allowedTools.includes(definition.name);
|
const tool = new SubagentTool(definition, this, this.getMessageBus());
|
||||||
|
registry.registerTool(tool);
|
||||||
if (isAllowed) {
|
} catch (e: unknown) {
|
||||||
try {
|
debugLogger.warn(
|
||||||
const tool = new SubagentTool(
|
`Failed to register tool for agent ${definition.name}: ${getErrorMessage(e)}`,
|
||||||
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