fix(core): ensure sub-agents are registered regardless of tools.allowed (#18870)

This commit is contained in:
matt korwel
2026-02-11 20:12:01 -06:00
committed by GitHub
parent fe75de3efb
commit 099aa9621c
2 changed files with 45 additions and 17 deletions

View File

@@ -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,

View File

@@ -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)}`,
);
}
}
}