Skip to content

Commit 8032875

Browse files
committed
fix: improve error messages for API providers without native tool calling support
When an API provider (such as OpenAI-compatible proxies like kie.ai) does not properly support native function/tool calling, the model may output XML-formatted tool calls in its text response. The previous error messages were technical and confusing for users. Updated error messages to: - Explain what happened in user-friendly terms - Identify the likely cause (API provider not supporting native tool calling) - Provide actionable guidance Fixes #11011
1 parent b9cf163 commit 8032875

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/core/assistant-message/__tests__/presentAssistantMessage-images.spec.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ describe("presentAssistantMessage - Image Handling in Native Tool Calling", () =
182182

183183
const textBlocks = mockTask.userMessageContent.filter((item: any) => item.type === "text")
184184
expect(textBlocks.length).toBeGreaterThan(0)
185-
expect(textBlocks.some((b: any) => String(b.text).includes("XML tool calls are no longer supported"))).toBe(
186-
true,
187-
)
185+
expect(
186+
textBlocks.some((b: any) =>
187+
String(b.text).includes("does not fully support OpenAI's function/tool calling"),
188+
),
189+
).toBe(true)
188190
// Should not proceed to execute tool or add images as tool output.
189191
expect(mockTask.userMessageContent.some((item: any) => item.type === "image")).toBe(false)
190192
})
@@ -331,9 +333,11 @@ describe("presentAssistantMessage - Image Handling in Native Tool Calling", () =
331333
await presentAssistantMessage(mockTask)
332334

333335
const textBlocks = mockTask.userMessageContent.filter((item: any) => item.type === "text")
334-
expect(textBlocks.some((b: any) => String(b.text).includes("XML tool calls are no longer supported"))).toBe(
335-
true,
336-
)
336+
expect(
337+
textBlocks.some((b: any) =>
338+
String(b.text).includes("does not fully support OpenAI's function/tool calling"),
339+
),
340+
).toBe(true)
337341
// Ensure no tool_result blocks were added
338342
expect(mockTask.userMessageContent.some((item: any) => item.type === "tool_result")).toBe(false)
339343
})

src/core/assistant-message/__tests__/presentAssistantMessage-unknown-tool.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ describe("presentAssistantMessage - Unknown Tool Handling", () => {
131131
// Should not execute tool; should surface a clear error message.
132132
const textBlocks = mockTask.userMessageContent.filter((item: any) => item.type === "text")
133133
expect(textBlocks.length).toBeGreaterThan(0)
134-
expect(textBlocks.some((b: any) => String(b.text).includes("XML tool calls are no longer supported"))).toBe(
135-
true,
136-
)
134+
expect(
135+
textBlocks.some((b: any) =>
136+
String(b.text).includes("does not fully support OpenAI's function/tool calling"),
137+
),
138+
).toBe(true)
137139

138140
// Verify consecutiveMistakeCount was incremented
139141
expect(mockTask.consecutiveMistakeCount).toBe(1)

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ export async function presentAssistantMessage(cline: Task) {
317317
// fail fast with a clear error.
318318
if (containsXmlToolMarkup(content)) {
319319
const errorMessage =
320-
"XML tool calls are no longer supported. Remove any XML tool markup (e.g. <read_file>...</read_file>) and use native tool calling instead."
320+
"The model is outputting XML-formatted tool calls instead of using native function calling. " +
321+
"This typically happens when your API provider does not fully support OpenAI's function/tool calling feature. " +
322+
"Please verify that your API provider supports native tool calling, or try using a different provider."
321323
cline.consecutiveMistakeCount++
322324
await cline.say("error", errorMessage)
323325
cline.userMessageContent.push({ type: "text", text: errorMessage })
@@ -335,7 +337,9 @@ export async function presentAssistantMessage(cline: Task) {
335337
const toolCallId = (block as any).id as string | undefined
336338
if (!toolCallId) {
337339
const errorMessage =
338-
"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."
340+
"Invalid tool call: the model's tool call is missing a required ID. " +
341+
"This typically happens when your API provider does not fully support OpenAI's function/tool calling feature. " +
342+
"Please verify that your API provider supports native tool calling, or try using a different provider."
339343
// Record a tool error for visibility/telemetry. Use the reported tool name if present.
340344
try {
341345
if (

src/core/tools/BaseTool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export abstract class BaseTool<TName extends ToolName> {
142142
})()
143143
if (paramsText.includes("<") && paramsText.includes(">")) {
144144
throw new Error(
145-
"XML tool calls are no longer supported. Use native tool calling (nativeArgs) instead.",
145+
"The model is outputting XML-formatted tool calls instead of using native function calling. " +
146+
"This typically happens when your API provider does not fully support OpenAI's function/tool calling feature.",
146147
)
147148
}
148149
throw new Error("Tool call is missing native arguments (nativeArgs).")

0 commit comments

Comments
 (0)