Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/extension/intents/node/toolCallingLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { InteractionOutcomeComputer } from '../../inlineChat/node/promptCrafting
import { ChatVariablesCollection } from '../../prompt/common/chatVariablesCollection';
import { Conversation, IResultMetadata, ResponseStreamParticipant, TurnStatus } from '../../prompt/common/conversation';
import { IBuildPromptContext, InternalToolReference, IToolCall, IToolCallRound } from '../../prompt/common/intents';
import { cancelText, IToolCallIterationIncrease } from '../../prompt/common/specialRequestTypes';
import { ThinkingDataItem, ToolCallRound } from '../../prompt/common/toolCallRound';
import { IBuildPromptResult, IResponseProcessor } from '../../prompt/node/intents';
import { PseudoStopStartResponseProcessor } from '../../prompt/node/pseudoStartStopConversationCallback';
Expand All @@ -38,7 +39,6 @@ import { ToolName } from '../../tools/common/toolNames';
import { ToolCallCancelledError } from '../../tools/common/toolsService';
import { ReadFileParams } from '../../tools/node/readFileTool';
import { PauseController } from './pauseController';
import { cancelText, IToolCallIterationIncrease } from '../../prompt/common/specialRequestTypes';


export const enum ToolCallLimitBehavior {
Expand Down Expand Up @@ -623,6 +623,16 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
}
};

// Simulate error for tools with "file" in the name before they execute
const lastRound = this.toolCallRounds.at(-1);
if (lastRound) {
for (const toolCall of lastRound.toolCalls) {
if (toolCall.name.toLowerCase().includes('file')) {
throw new ToolCallExecutionError(toolCall.name, `Simulated error: Tool "${toolCall.name}" failed during execution`);
}
}
}

const buildPromptResult = await this.buildPrompt(buildPromptContext, progress, token);
for (const metadata of buildPromptResult.metadata.getAll(ToolResultMetadata)) {
this.logToolResult(buildPromptContext, metadata);
Expand Down Expand Up @@ -669,6 +679,17 @@ export class EmptyPromptError extends Error {
}
}

/**
* Error thrown when a tool call fails during execution.
* This error is handled specially to show a "Try Again" button.
*/
export class ToolCallExecutionError extends Error {
constructor(public readonly toolName: string, message: string) {
super(message);
this.name = 'ToolCallExecutionError';
}
}

export interface IToolCallSingleResult {
response: ChatResponse;
round: IToolCallRound;
Expand Down
17 changes: 15 additions & 2 deletions src/extension/prompt/node/defaultIntentRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { ChatResponseMarkdownPart, ChatResponseProgressPart, ChatResponseTextEdi
import { CodeBlocksMetadata, CodeBlockTrackingChatResponseStream } from '../../codeBlocks/node/codeBlockProcessor';
import { CopilotInteractiveEditorResponse, InteractionOutcomeComputer } from '../../inlineChat/node/promptCraftingTypes';
import { PauseController } from '../../intents/node/pauseController';
import { EmptyPromptError, IToolCallingBuiltPromptEvent, IToolCallingLoopOptions, IToolCallingResponseEvent, IToolCallLoopResult, ToolCallingLoop, ToolCallingLoopFetchOptions, ToolCallLimitBehavior } from '../../intents/node/toolCallingLoop';
import { EmptyPromptError, IToolCallingBuiltPromptEvent, IToolCallingLoopOptions, IToolCallingResponseEvent, IToolCallLoopResult, ToolCallingLoop, ToolCallingLoopFetchOptions, ToolCallExecutionError, ToolCallLimitBehavior } from '../../intents/node/toolCallingLoop';
import { UnknownIntent } from '../../intents/node/unknownIntent';
import { ResponseStreamWithLinkification } from '../../linkify/common/responseStreamWithLinkification';
import { SummarizedConversationHistoryMetadata } from '../../prompts/node/agent/summarizedConversationHistory';
Expand All @@ -45,7 +45,7 @@ import { IToolGrouping, IToolGroupingService } from '../../tools/common/virtualT
import { ChatVariablesCollection } from '../common/chatVariablesCollection';
import { Conversation, getUniqueReferences, GlobalContextMessageMetadata, IResultMetadata, RenderedUserMessageMetadata, RequestDebugInformation, ResponseStreamParticipant, Turn, TurnStatus } from '../common/conversation';
import { IBuildPromptContext, IToolCallRound } from '../common/intents';
import { isToolCallLimitCancellation } from '../common/specialRequestTypes';
import { IContinueOnErrorConfirmation, isToolCallLimitCancellation } from '../common/specialRequestTypes';
import { ChatTelemetry, ChatTelemetryBuilder } from './chatParticipantTelemetry';
import { IntentInvocationMetadata } from './conversation';
import { IDocumentContext } from './documentContext';
Expand Down Expand Up @@ -155,6 +155,19 @@ export class DefaultIntentRequestHandler {
return CanceledResult;
} else if (err instanceof EmptyPromptError) {
return {};
} else if (err instanceof ToolCallExecutionError) {
this._logService.error(err);
const errorMessage = err.message;
const chatResult = {
errorDetails: {
message: errorMessage,
confirmationButtons: [
{ data: { copilotContinueOnError: true } satisfies IContinueOnErrorConfirmation, label: l10n.t('Try Again') },
]
}
};
this.turn.setResponse(TurnStatus.Error, { message: errorMessage, type: 'meta' }, undefined, chatResult);
return chatResult;
}

this._logService.error(err);
Expand Down