This commit is contained in:
roomote-v0[bot] 2026-04-08 17:36:31 +00:00 • committed by GitHub
commit 3d0dff822c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 7 deletions

View file

@ -300,22 +300,27 @@ export async function presentAssistantMessage(cline: Task) {
// A tool_use block without an id is invalid and cannot be executed. // A tool_use block without an id is invalid and cannot be executed.
const toolCallId = (block as any).id as string | undefined const toolCallId = (block as any).id as string | undefined
if (!toolCallId) { if (!toolCallId) {
const errorMessage = const userFacingError =
"Invalid tool call: missing tool_use.id. XML tool calls are no longer supported. Remove any XML tool markup (e.g. <read_file>...</read_file>) and use native tool calling instead." "XML tool calls are no longer supported. Remove any XML tool markup (e.g. <read_file>...</read_file>) and use native tool calling instead."
// Record a tool error for visibility/telemetry. Use the reported tool name if present. // Record a tool error for visibility/telemetry. Use the reported tool name if present.
try { try {
if ( if (
typeof (cline as any).recordToolError === "function" && typeof (cline as any).recordToolError === "function" &&
typeof (block as any).name === "string" typeof (block as any).name === "string"
) { ) {
;(cline as any).recordToolError((block as any).name as ToolName, errorMessage) ;(cline as any).recordToolError((block as any).name as ToolName, userFacingError)
} }
} catch { } catch {
// Best-effort only // Best-effort only
} }
cline.consecutiveMistakeCount++ cline.consecutiveMistakeCount++
await cline.say("error", errorMessage) await cline.say("error", userFacingError)
cline.userMessageContent.push({ type: "text", text: errorMessage }) // Push comprehensive error with tool-use instructions so the model
// can self-correct on the next turn (see #11106).
cline.userMessageContent.push({
type: "text",
text: formatResponse.xmlToolCallError(),
})
cline.didAlreadyUseTool = true cline.didAlreadyUseTool = true
break break
} }

View file

@ -0,0 +1,38 @@
// npx vitest core/prompts/__tests__/responses-xml-tool-call-error.spec.ts
import { formatResponse } from "../responses"
describe("formatResponse.xmlToolCallError", () => {
it("should return a string containing the XML error explanation", () => {
const result = formatResponse.xmlToolCallError()
expect(result).toContain("XML tool calls are no longer supported")
})
it("should include instruction to not embed XML tags in text", () => {
const result = formatResponse.xmlToolCallError()
expect(result).toContain("Do NOT embed tool invocations as XML tags")
})
it("should include tool use instructions reminder", () => {
const result = formatResponse.xmlToolCallError()
expect(result).toContain("Reminder: Instructions for Tool Use")
expect(result).toContain("native tool calling mechanism")
})
it("should include next steps guidance", () => {
const result = formatResponse.xmlToolCallError()
expect(result).toContain("Next Steps")
expect(result).toContain("attempt_completion")
expect(result).toContain("ask_followup_question")
})
it("should include the [ERROR] prefix", () => {
const result = formatResponse.xmlToolCallError()
expect(result).toMatch(/^\[ERROR\]/)
})
it("should include automated message notice", () => {
const result = formatResponse.xmlToolCallError()
expect(result).toContain("This is an automated message")
})
})

View file

@ -54,6 +54,24 @@ Otherwise, if you have not completed the task and do not need additional informa
(This is an automated message, so do not respond to it conversationally.)` (This is an automated message, so do not respond to it conversationally.)`
}, },
xmlToolCallError: () => {
const instructions = getToolInstructionsReminder()
return `[ERROR] XML tool calls are no longer supported. The model produced XML-style tool markup (e.g. <tool_name>...</tool_name>) instead of using the API's native tool calling mechanism.
Do NOT embed tool invocations as XML tags in your text response. Instead, use the platform's built-in function/tool calling feature to invoke tools.
${instructions}
# Next Steps
Please retry your previous action using proper native tool calls.
If you have completed the user's task, use the attempt_completion tool.
If you require additional information from the user, use the ask_followup_question tool.
Otherwise, proceed with the next step of the task using native tool calls.
(This is an automated message, so do not respond to it conversationally.)`
},
tooManyMistakes: (feedback?: string) => tooManyMistakes: (feedback?: string) =>
JSON.stringify({ JSON.stringify({
status: "guidance", status: "guidance",

View file

@ -142,10 +142,15 @@ export abstract class BaseTool<TName extends ToolName> {
})() })()
if (paramsText.includes("<") && paramsText.includes(">")) { if (paramsText.includes("<") && paramsText.includes(">")) {
throw new Error( throw new Error(
"XML tool calls are no longer supported. Use native tool calling (nativeArgs) instead.", "XML tool calls are no longer supported. " +
"Do not embed tool invocations as XML tags in your text response. " +
"Use the platform's native tool calling mechanism (nativeArgs) instead.",
) )
} }
throw new Error("Tool call is missing native arguments (nativeArgs).") throw new Error(
"Tool call is missing native arguments (nativeArgs). " +
"Use the platform's native tool calling mechanism to invoke tools.",
)
} }
} catch (error) { } catch (error) {
console.error(`Error parsing parameters:`, error) console.error(`Error parsing parameters:`, error)