You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/core/assistant-message/presentAssistantMessage.ts
+34-10Lines changed: 34 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -252,16 +252,25 @@ export async function presentAssistantMessage(cline: Task) {
252
252
253
253
if(cline.didRejectTool){
254
254
// Ignore any tool content after user has rejected tool once.
255
-
if(!block.partial){
255
+
// For native protocol, we must send a tool_result for every tool_use to avoid API errors
256
+
consttoolCallId=block.id
257
+
consterrorMessage=!block.partial
258
+
? `Skipping tool ${toolDescription()} due to user rejecting a previous tool.`
259
+
: `Tool ${toolDescription()} was interrupted and not executed due to user rejecting a previous tool.`
260
+
261
+
if(toolCallId){
262
+
// Native protocol: MUST send tool_result for every tool_use
256
263
cline.userMessageContent.push({
257
-
type: "text",
258
-
text: `Skipping tool ${toolDescription()} due to user rejecting a previous tool.`,
259
-
})
264
+
type: "tool_result",
265
+
tool_use_id: toolCallId,
266
+
content: errorMessage,
267
+
is_error: true,
268
+
}asAnthropic.ToolResultBlockParam)
260
269
}else{
261
-
// Partial tool after user rejected a previous tool.
270
+
// XML protocol: send as text
262
271
cline.userMessageContent.push({
263
272
type: "text",
264
-
text: `Tool ${toolDescription()} was interrupted and not executed due to user rejecting a previous tool.`,
273
+
text: errorMessage,
265
274
})
266
275
}
267
276
@@ -270,10 +279,25 @@ export async function presentAssistantMessage(cline: Task) {
270
279
271
280
if(cline.didAlreadyUseTool){
272
281
// Ignore any content after a tool has already been used.
273
-
cline.userMessageContent.push({
274
-
type: "text",
275
-
text: `Tool [${block.name}] was not executed because a tool has already been used in this message. Only one tool may be used per message. You must assess the first tool's result before proceeding to use the next tool.`,
276
-
})
282
+
// For native protocol, we must send a tool_result for every tool_use to avoid API errors
283
+
consttoolCallId=block.id
284
+
consterrorMessage=`Tool [${block.name}] was not executed because a tool has already been used in this message. Only one tool may be used per message. You must assess the first tool's result before proceeding to use the next tool.`
285
+
286
+
if(toolCallId){
287
+
// Native protocol: MUST send tool_result for every tool_use
0 commit comments