mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
fix(core): prevent redundant remote agent loading on model switch (#23576)
This commit is contained in:
@@ -1206,6 +1206,32 @@ describe('AgentRegistry', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('inheritance and refresh', () => {
|
describe('inheritance and refresh', () => {
|
||||||
|
it('should skip remote agents when refreshing on model change', async () => {
|
||||||
|
const remoteAgent: AgentDefinition = {
|
||||||
|
kind: 'remote',
|
||||||
|
name: 'RemoteAgent',
|
||||||
|
description: 'A remote agent',
|
||||||
|
agentCardUrl: 'https://example.com/card',
|
||||||
|
inputConfig: { inputSchema: { type: 'object' } },
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadAgentSpy = vi.fn().mockResolvedValue({ name: 'RemoteAgent' });
|
||||||
|
vi.spyOn(mockConfig, 'getA2AClientManager').mockReturnValue({
|
||||||
|
loadAgent: loadAgentSpy,
|
||||||
|
clearCache: vi.fn(),
|
||||||
|
} as unknown as A2AClientManager);
|
||||||
|
|
||||||
|
await registry.testRegisterAgent(remoteAgent);
|
||||||
|
|
||||||
|
expect(loadAgentSpy).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
coreEvents.emitModelChanged('new-model');
|
||||||
|
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
|
expect(loadAgentSpy).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should resolve "inherit" to the current model from configuration', async () => {
|
it('should resolve "inherit" to the current model from configuration', async () => {
|
||||||
const config = makeMockedConfig({ model: 'current-model' });
|
const config = makeMockedConfig({ model: 'current-model' });
|
||||||
const registry = new TestableAgentRegistry(config);
|
const registry = new TestableAgentRegistry(config);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export class AgentRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onModelChanged = () => {
|
private onModelChanged = () => {
|
||||||
this.refreshAgents().catch((e) => {
|
this.refreshAgents('local').catch((e) => {
|
||||||
debugLogger.error(
|
debugLogger.error(
|
||||||
'[AgentRegistry] Failed to refresh agents on model change:',
|
'[AgentRegistry] Failed to refresh agents on model change:',
|
||||||
e,
|
e,
|
||||||
@@ -270,12 +270,16 @@ export class AgentRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refreshAgents(): Promise<void> {
|
private async refreshAgents(
|
||||||
|
scope: AgentDefinition['kind'] | 'all' = 'all',
|
||||||
|
): Promise<void> {
|
||||||
this.loadBuiltInAgents();
|
this.loadBuiltInAgents();
|
||||||
await Promise.allSettled(
|
await Promise.allSettled(
|
||||||
Array.from(this.agents.values()).map((agent) =>
|
Array.from(this.agents.values()).map(async (agent) => {
|
||||||
this.registerAgent(agent),
|
if (scope === 'all' || agent.kind === scope) {
|
||||||
),
|
await this.registerAgent(agent);
|
||||||
|
}
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user