mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-01 15:34:29 -07:00
feat(agents): migrate subagents to event-driven scheduler (#17567)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type { Config } from '../config/config.js';
|
||||
import { Scheduler } from '../scheduler/scheduler.js';
|
||||
import type {
|
||||
ToolCallRequestInfo,
|
||||
CompletedToolCall,
|
||||
} from '../scheduler/types.js';
|
||||
import type { ToolRegistry } from '../tools/tool-registry.js';
|
||||
import type { EditorType } from '../utils/editor.js';
|
||||
|
||||
/**
|
||||
* Options for scheduling agent tools.
|
||||
*/
|
||||
export interface AgentSchedulingOptions {
|
||||
/** The unique ID for this agent's scheduler. */
|
||||
schedulerId: string;
|
||||
/** The ID of the tool call that invoked this agent. */
|
||||
parentCallId?: string;
|
||||
/** The tool registry specific to this agent. */
|
||||
toolRegistry: ToolRegistry;
|
||||
/** AbortSignal for cancellation. */
|
||||
signal: AbortSignal;
|
||||
/** Optional function to get the preferred editor for tool modifications. */
|
||||
getPreferredEditor?: () => EditorType | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a batch of tool calls for an agent using the new event-driven Scheduler.
|
||||
*
|
||||
* @param config The global runtime configuration.
|
||||
* @param requests The list of tool call requests from the agent.
|
||||
* @param options Scheduling options including registry and IDs.
|
||||
* @returns A promise that resolves to the completed tool calls.
|
||||
*/
|
||||
export async function scheduleAgentTools(
|
||||
config: Config,
|
||||
requests: ToolCallRequestInfo[],
|
||||
options: AgentSchedulingOptions,
|
||||
): Promise<CompletedToolCall[]> {
|
||||
const {
|
||||
schedulerId,
|
||||
parentCallId,
|
||||
toolRegistry,
|
||||
signal,
|
||||
getPreferredEditor,
|
||||
} = options;
|
||||
|
||||
// Create a proxy/override of the config to provide the agent-specific tool registry.
|
||||
const agentConfig: Config = Object.create(config);
|
||||
agentConfig.getToolRegistry = () => toolRegistry;
|
||||
|
||||
const scheduler = new Scheduler({
|
||||
config: agentConfig,
|
||||
messageBus: config.getMessageBus(),
|
||||
getPreferredEditor: getPreferredEditor ?? (() => undefined),
|
||||
schedulerId,
|
||||
parentCallId,
|
||||
});
|
||||
|
||||
return scheduler.schedule(requests, signal);
|
||||
}
|
||||
Reference in New Issue
Block a user