mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 21:44:25 -07:00
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:
@@ -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,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 };
|
||||
|
||||
Reference in New Issue
Block a user