diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index 886e722ba0..4a732bbedb 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -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, diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index db4085c1fa..944d14fb39 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -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)}`, + ); } } }