Fix bug where tool scheduler was repeatedly created. (#11767)

This commit is contained in:
Jacob Richman
2025-10-23 09:35:32 -07:00
committed by GitHub
parent 8ad72ec1ae
commit 9e91aafe40
4 changed files with 131 additions and 16 deletions
+4 -5
View File
@@ -10,7 +10,6 @@ import type {
ToolCallConfirmationDetails,
ToolResult,
ToolResultDisplay,
ToolRegistry,
EditorType,
Config,
ToolConfirmationPayload,
@@ -332,7 +331,6 @@ interface CoreToolSchedulerOptions {
}
export class CoreToolScheduler {
private toolRegistry: ToolRegistry;
private toolCalls: ToolCall[] = [];
private outputUpdateHandler?: OutputUpdateHandler;
private onAllToolCallsComplete?: AllToolCallsCompleteHandler;
@@ -351,7 +349,6 @@ export class CoreToolScheduler {
constructor(options: CoreToolSchedulerOptions) {
this.config = options.config;
this.toolRegistry = options.config.getToolRegistry();
this.outputUpdateHandler = options.outputUpdateHandler;
this.onAllToolCallsComplete = options.onAllToolCallsComplete;
this.onToolCallsUpdate = options.onToolCallsUpdate;
@@ -603,7 +600,7 @@ export class CoreToolScheduler {
* @returns A suggestion string like " Did you mean 'tool'?" or " Did you mean one of: 'tool1', 'tool2'?", or an empty string if no suggestions are found.
*/
private getToolSuggestion(unknownToolName: string, topN = 3): string {
const allToolNames = this.toolRegistry.getAllToolNames();
const allToolNames = this.config.getToolRegistry().getAllToolNames();
const matches = allToolNames.map((toolName) => ({
name: toolName,
@@ -680,7 +677,9 @@ export class CoreToolScheduler {
const newToolCalls: ToolCall[] = requestsToProcess.map(
(reqInfo): ToolCall => {
const toolInstance = this.toolRegistry.getTool(reqInfo.name);
const toolInstance = this.config
.getToolRegistry()
.getTool(reqInfo.name);
if (!toolInstance) {
const suggestion = this.getToolSuggestion(reqInfo.name);
const errorMessage = `Tool "${reqInfo.name}" not found in registry. Tools must use the exact names that are registered.${suggestion}`;