fix(patch): cherry-pick b2d6dc4 to release/v0.35.0-preview.4-pr-23546 [CONFLICTS] (#23585)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Abhi <abhipatel@google.com>
This commit is contained in:
gemini-cli-robot
2026-03-23 15:40:50 -07:00
committed by GitHub
parent 63c6560a38
commit e88b56bbcb
10 changed files with 63 additions and 11 deletions
+22 -4
View File
@@ -44,6 +44,7 @@ export class AgentRegistry {
private readonly agents = new Map<string, AgentDefinition<any>>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly allDefinitions = new Map<string, AgentDefinition<any>>();
private readonly builtInAgents = new Set<string>();
constructor(private readonly config: Config) {}
@@ -56,6 +57,13 @@ export class AgentRegistry {
await this.loadAgents();
}
/**
* Returns true if the agent is a built-in agent.
*/
isBuiltIn(name: string): boolean {
return this.builtInAgents.has(name);
}
private onModelChanged = () => {
this.refreshAgents().catch((e) => {
debugLogger.error(
@@ -240,15 +248,25 @@ export class AgentRegistry {
}
private loadBuiltInAgents(): void {
this.registerLocalAgent(CodebaseInvestigatorAgent(this.config));
this.registerLocalAgent(CliHelpAgent(this.config));
this.registerLocalAgent(GeneralistAgent(this.config));
const codebaseAgent = CodebaseInvestigatorAgent(this.config);
this.builtInAgents.add(codebaseAgent.name);
this.registerLocalAgent(codebaseAgent);
const helpAgent = CliHelpAgent(this.config);
this.builtInAgents.add(helpAgent.name);
this.registerLocalAgent(helpAgent);
const generalistAgent = GeneralistAgent(this.config);
this.builtInAgents.add(generalistAgent.name);
this.registerLocalAgent(generalistAgent);
// Register the browser agent if enabled in settings.
// Tools are configured dynamically at invocation time via browserAgentFactory.
const browserConfig = this.config.getBrowserAgentConfig();
if (browserConfig.enabled) {
this.registerLocalAgent(BrowserAgentDefinition(this.config));
const browserAgent = BrowserAgentDefinition(this.config);
this.builtInAgents.add(browserAgent.name);
this.registerLocalAgent(browserAgent);
}
}
+7
View File
@@ -185,6 +185,7 @@ vi.mock('../agents/registry.js', () => {
AgentRegistryMock.prototype.initialize = vi.fn();
AgentRegistryMock.prototype.getAllDefinitions = vi.fn(() => []);
AgentRegistryMock.prototype.getDefinition = vi.fn();
AgentRegistryMock.prototype.isBuiltIn = vi.fn();
return { AgentRegistry: AgentRegistryMock };
});
@@ -1262,6 +1263,9 @@ describe('Server Config (config.ts)', () => {
AgentRegistryMock.prototype.getAllDefinitions.mockReturnValue([
mockAgentDefinition,
]);
AgentRegistryMock.prototype.isBuiltIn.mockImplementation(
(name: string) => name === 'codebase_investigator',
);
const SubAgentToolMock = (
(await vi.importMock('../agents/subagent-tool.js')) as {
@@ -1317,6 +1321,9 @@ describe('Server Config (config.ts)', () => {
AgentRegistryMock.prototype.getAllDefinitions.mockReturnValue([
mockAgentDefinition,
]);
AgentRegistryMock.prototype.isBuiltIn.mockImplementation(
(name: string) => name === 'codebase_investigator',
);
const SubAgentToolMock = (
(await vi.importMock('../agents/subagent-tool.js')) as {
+3 -2
View File
@@ -951,7 +951,7 @@ export class Config implements McpContext, AgentLoopContext {
this.model = params.model;
this.disableLoopDetection = params.disableLoopDetection ?? false;
this._activeModel = params.model;
this.enableAgents = params.enableAgents ?? true;
this.enableAgents = params.enableAgents ?? false;
this.agents = params.agents ?? {};
this.disableLLMCorrection = params.disableLLMCorrection ?? true;
this.planEnabled = params.plan ?? true;
@@ -3196,7 +3196,8 @@ export class Config implements McpContext, AgentLoopContext {
for (const definition of definitions) {
try {
if (
!this.isAgentsEnabled() ||
(!this.isAgentsEnabled() &&
!this.agentRegistry.isBuiltIn(definition.name)) ||
agentsOverrides[definition.name]?.enabled === false
) {
continue;