mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
feat(core): Fully migrate packages/core to AgentLoopContext. (#22115)
This commit is contained in:
@@ -28,10 +28,10 @@ describe('agent-scheduler', () => {
|
||||
mockMessageBus = {} as Mocked<MessageBus>;
|
||||
mockToolRegistry = {
|
||||
getTool: vi.fn(),
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
messageBus: mockMessageBus,
|
||||
} as unknown as Mocked<ToolRegistry>;
|
||||
mockConfig = {
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
messageBus: mockMessageBus,
|
||||
toolRegistry: mockToolRegistry,
|
||||
} as unknown as Mocked<Config>;
|
||||
(mockConfig as unknown as { messageBus: MessageBus }).messageBus =
|
||||
@@ -42,7 +42,7 @@ describe('agent-scheduler', () => {
|
||||
|
||||
it('should create a scheduler with agent-specific config', async () => {
|
||||
const mockConfig = {
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
messageBus: mockMessageBus,
|
||||
toolRegistry: mockToolRegistry,
|
||||
} as unknown as Mocked<Config>;
|
||||
|
||||
@@ -87,11 +87,11 @@ describe('agent-scheduler', () => {
|
||||
const mainRegistry = { _id: 'main' } as unknown as Mocked<ToolRegistry>;
|
||||
const agentRegistry = {
|
||||
_id: 'agent',
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
messageBus: mockMessageBus,
|
||||
} as unknown as Mocked<ToolRegistry>;
|
||||
|
||||
const config = {
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
messageBus: mockMessageBus,
|
||||
} as unknown as Mocked<Config>;
|
||||
Object.defineProperty(config, 'toolRegistry', {
|
||||
get: () => mainRegistry,
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function scheduleAgentTools(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const agentConfig: Config = Object.create(config);
|
||||
agentConfig.getToolRegistry = () => toolRegistry;
|
||||
agentConfig.getMessageBus = () => toolRegistry.getMessageBus();
|
||||
agentConfig.getMessageBus = () => toolRegistry.messageBus;
|
||||
// Override toolRegistry property so AgentLoopContext reads the agent-specific registry.
|
||||
Object.defineProperty(agentConfig, 'toolRegistry', {
|
||||
get: () => toolRegistry,
|
||||
@@ -69,7 +69,7 @@ export async function scheduleAgentTools(
|
||||
|
||||
const scheduler = new Scheduler({
|
||||
context: agentConfig,
|
||||
messageBus: toolRegistry.getMessageBus(),
|
||||
messageBus: toolRegistry.messageBus,
|
||||
getPreferredEditor: getPreferredEditor ?? (() => undefined),
|
||||
schedulerId,
|
||||
subagent,
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
import type { AgentDefinition } from './types.js';
|
||||
import { GEMINI_MODEL_ALIAS_FLASH } from '../config/models.js';
|
||||
import { z } from 'zod';
|
||||
import type { Config } from '../config/config.js';
|
||||
import { GetInternalDocsTool } from '../tools/get-internal-docs.js';
|
||||
import type { AgentLoopContext } from '../config/agent-loop-context.js';
|
||||
|
||||
const CliHelpReportSchema = z.object({
|
||||
answer: z
|
||||
@@ -24,7 +24,7 @@ const CliHelpReportSchema = z.object({
|
||||
* using its own documentation and runtime state.
|
||||
*/
|
||||
export const CliHelpAgent = (
|
||||
config: Config,
|
||||
context: AgentLoopContext,
|
||||
): AgentDefinition<typeof CliHelpReportSchema> => ({
|
||||
name: 'cli_help',
|
||||
kind: 'local',
|
||||
@@ -69,7 +69,7 @@ export const CliHelpAgent = (
|
||||
},
|
||||
|
||||
toolConfig: {
|
||||
tools: [new GetInternalDocsTool(config.getMessageBus())],
|
||||
tools: [new GetInternalDocsTool(context.messageBus)],
|
||||
},
|
||||
|
||||
promptConfig: {
|
||||
|
||||
@@ -22,9 +22,19 @@ describe('GeneralistAgent', () => {
|
||||
|
||||
it('should create a valid generalist agent definition', () => {
|
||||
const config = makeFakeConfig();
|
||||
vi.spyOn(config, 'getToolRegistry').mockReturnValue({
|
||||
const mockToolRegistry = {
|
||||
getAllToolNames: () => ['tool1', 'tool2', 'agent-tool'],
|
||||
} as unknown as ToolRegistry);
|
||||
} as unknown as ToolRegistry;
|
||||
vi.spyOn(config, 'getToolRegistry').mockReturnValue(mockToolRegistry);
|
||||
Object.defineProperty(config, 'toolRegistry', {
|
||||
get: () => mockToolRegistry,
|
||||
});
|
||||
Object.defineProperty(config, 'config', {
|
||||
get() {
|
||||
return this;
|
||||
},
|
||||
});
|
||||
|
||||
vi.spyOn(config, 'getAgentRegistry').mockReturnValue({
|
||||
getDirectoryContext: () => 'mock directory context',
|
||||
getAllAgentNames: () => ['agent-tool'],
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { AgentLoopContext } from '../config/agent-loop-context.js';
|
||||
import { getCoreSystemPrompt } from '../core/prompts.js';
|
||||
import type { LocalAgentDefinition } from './types.js';
|
||||
|
||||
@@ -18,7 +18,7 @@ const GeneralistAgentSchema = z.object({
|
||||
* It uses the same core system prompt as the main agent but in a non-interactive mode.
|
||||
*/
|
||||
export const GeneralistAgent = (
|
||||
config: Config,
|
||||
context: AgentLoopContext,
|
||||
): LocalAgentDefinition<typeof GeneralistAgentSchema> => ({
|
||||
kind: 'local',
|
||||
name: 'generalist',
|
||||
@@ -46,7 +46,7 @@ export const GeneralistAgent = (
|
||||
model: 'inherit',
|
||||
},
|
||||
get toolConfig() {
|
||||
const tools = config.getToolRegistry().getAllToolNames();
|
||||
const tools = context.toolRegistry.getAllToolNames();
|
||||
return {
|
||||
tools,
|
||||
};
|
||||
@@ -54,7 +54,7 @@ export const GeneralistAgent = (
|
||||
get promptConfig() {
|
||||
return {
|
||||
systemPrompt: getCoreSystemPrompt(
|
||||
config,
|
||||
context.config,
|
||||
/*useMemory=*/ undefined,
|
||||
/*interactiveOverride=*/ false,
|
||||
),
|
||||
|
||||
@@ -313,12 +313,9 @@ describe('LocalAgentExecutor', () => {
|
||||
get: () => 'test-prompt-id',
|
||||
configurable: true,
|
||||
});
|
||||
parentToolRegistry = new ToolRegistry(
|
||||
mockConfig,
|
||||
mockConfig.getMessageBus(),
|
||||
);
|
||||
parentToolRegistry = new ToolRegistry(mockConfig, mockConfig.messageBus);
|
||||
parentToolRegistry.registerTool(
|
||||
new LSTool(mockConfig, mockConfig.getMessageBus()),
|
||||
new LSTool(mockConfig, mockConfig.messageBus),
|
||||
);
|
||||
parentToolRegistry.registerTool(
|
||||
new MockTool({ name: READ_FILE_TOOL_NAME }),
|
||||
@@ -524,7 +521,7 @@ describe('LocalAgentExecutor', () => {
|
||||
toolName,
|
||||
'description',
|
||||
{},
|
||||
mockConfig.getMessageBus(),
|
||||
mockConfig.messageBus,
|
||||
);
|
||||
|
||||
// Mock getTool to return our real DiscoveredMCPTool instance
|
||||
|
||||
Reference in New Issue
Block a user