fix(core): ensure sub-agent schema and prompt refresh during runtime (#16409)

Co-authored-by: Sehoon Shon <sshon@google.com>
This commit is contained in:
Adam Weidman
2026-01-12 12:11:24 -05:00
committed by GitHub
parent 950244f6b0
commit 465ec9759d
7 changed files with 101 additions and 16 deletions
+8 -3
View File
@@ -167,13 +167,18 @@ const mockCoreEvents = vi.hoisted(() => ({
emitFeedback: vi.fn(),
emitModelChanged: vi.fn(),
emitConsoleLog: vi.fn(),
on: vi.fn(),
}));
const mockSetGlobalProxy = vi.hoisted(() => vi.fn());
vi.mock('../utils/events.js', () => ({
coreEvents: mockCoreEvents,
}));
vi.mock('../utils/events.js', async (importOriginal) => {
const actual = await importOriginal<typeof import('../utils/events.js')>();
return {
...actual,
coreEvents: mockCoreEvents,
};
});
vi.mock('../utils/fetch.js', () => ({
setGlobalProxy: mockSetGlobalProxy,
+43 -5
View File
@@ -43,7 +43,7 @@ import {
DEFAULT_OTLP_ENDPOINT,
uiTelemetryService,
} from '../telemetry/index.js';
import { coreEvents } from '../utils/events.js';
import { coreEvents, CoreEvent } from '../utils/events.js';
import { tokenLimit } from '../core/tokenLimits.js';
import {
DEFAULT_GEMINI_EMBEDDING_MODEL,
@@ -735,6 +735,8 @@ export class Config {
this.agentRegistry = new AgentRegistry(this);
await this.agentRegistry.initialize();
coreEvents.on(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed);
this.toolRegistry = await this.createToolRegistry();
discoverToolsHandle?.end();
this.mcpClientManager = new McpClientManager(
@@ -1764,6 +1766,17 @@ export class Config {
// Register Subagents as Tools
// Register DelegateToAgentTool if agents are enabled
this.registerDelegateToAgentTool(registry);
await registry.discoverAllTools();
registry.sortTools();
return registry;
}
/**
* Registers the DelegateToAgentTool if agents or related features are enabled.
*/
private registerDelegateToAgentTool(registry: ToolRegistry): void {
if (
this.isAgentsEnabled() ||
this.getCodebaseInvestigatorSettings().enabled ||
@@ -1783,10 +1796,6 @@ export class Config {
registry.registerTool(delegateTool);
}
}
await registry.discoverAllTools();
registry.sortTools();
return registry;
}
/**
@@ -1870,6 +1879,35 @@ export class Config {
});
debugLogger.debug('Experiments loaded', summaryString);
}
private onAgentsRefreshed = async () => {
if (this.toolRegistry) {
this.registerDelegateToAgentTool(this.toolRegistry);
}
// Propagate updates to the active chat session
const client = this.getGeminiClient();
if (client?.isInitialized()) {
await client.setTools();
await client.updateSystemInstruction();
} else {
debugLogger.debug(
'[Config] GeminiClient not initialized; skipping live prompt/tool refresh.',
);
}
};
/**
* Disposes of resources and removes event listeners.
*/
async dispose(): Promise<void> {
coreEvents.off(CoreEvent.AgentsRefreshed, this.onAgentsRefreshed);
if (this.agentRegistry) {
this.agentRegistry.dispose();
}
if (this.mcpClientManager) {
await this.mcpClientManager.stop();
}
}
}
// Export model constants for use in CLI
export { DEFAULT_GEMINI_FLASH_MODEL };