Skip to content

Commit f5cdf65

Browse files
committed
fix: improve error messages for OpenAI-compatible providers
- Add specific guidance when OpenAI-compatible models fail to use tools - Provide clearer instructions about XML tool format requirements - Help users understand common issues with tool usage formatting - Add tests for the new error message variations Fixes #7226
1 parent 0cf0ee8 commit f5cdf65

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

src/core/prompts/__tests__/responses-openai-compatible.spec.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@ describe("formatResponse.noToolsUsed", () => {
1818
expect(result).not.toContain("OpenAI Compatible")
1919
})
2020

21-
it("should include OpenAI Compatible specific hints when apiProvider is openai-compatible", () => {
22-
const result = formatResponse.noToolsUsed("openai-compatible")
23-
24-
expect(result).toContain("[ERROR] You did not use a tool in your previous response!")
25-
expect(result).toContain("# Important Note for OpenAI Compatible Models")
26-
expect(result).toContain("Your model appears to not be using the required XML tool format")
27-
expect(result).toContain("Use XML tags for ALL tool invocations")
28-
expect(result).toContain("Place tool uses at the END of your message")
29-
expect(result).toContain("Use only ONE tool per message")
30-
expect(result).toContain("Follow the exact XML format shown below")
31-
expect(result).toContain("# Reminder: Instructions for Tool Use")
21+
it("should include OpenAI Compatible specific hints for OpenAI-compatible providers", () => {
22+
// Test with various OpenAI-compatible providers
23+
const openAICompatibleProviders = ["openai", "openai-native", "fireworks", "groq", "ollama"]
24+
25+
for (const provider of openAICompatibleProviders) {
26+
const result = formatResponse.noToolsUsed(provider)
27+
28+
expect(result).toContain("[ERROR] You did not use a tool in your previous response!")
29+
expect(result).toContain("# Important Note for OpenAI Compatible Models")
30+
expect(result).toContain("Your model appears to not be using the required XML tool format")
31+
expect(result).toContain("Use XML tags for ALL tool invocations")
32+
expect(result).toContain("Place tool uses at the END of your message")
33+
expect(result).toContain("Use only ONE tool per message")
34+
expect(result).toContain("Follow the exact XML format shown below")
35+
expect(result).toContain("# Reminder: Instructions for Tool Use")
36+
}
3237
})
3338

3439
it("should maintain the same structure with Next Steps section", () => {

src/core/prompts/responses.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,27 @@ export const formatResponse = {
2121
noToolsUsed: (apiProvider?: string) => {
2222
const baseMessage = `[ERROR] You did not use a tool in your previous response! Please retry with a tool use.`
2323

24+
// List of providers that use OpenAI-compatible APIs
25+
const openAICompatibleProviders = [
26+
"openai",
27+
"openai-native",
28+
"fireworks",
29+
"groq",
30+
"sambanova",
31+
"chutes",
32+
"roo",
33+
"zai",
34+
"io-intelligence",
35+
"deepseek",
36+
"moonshot",
37+
"doubao",
38+
"litellm",
39+
"lmstudio",
40+
"ollama",
41+
]
42+
2443
let providerSpecificHint = ""
25-
if (apiProvider === "openai-compatible") {
44+
if (apiProvider && openAICompatibleProviders.includes(apiProvider)) {
2645
providerSpecificHint = `
2746
2847
# Important Note for OpenAI Compatible Models

src/core/task/Task.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,14 +1539,33 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
15391539
}
15401540

15411541
if (this.consecutiveMistakeLimit > 0 && this.consecutiveMistakeCount >= this.consecutiveMistakeLimit) {
1542-
// Provide more specific guidance for OpenAI Compatible providers
1543-
const isOpenAICompatible = this.apiConfiguration.apiProvider === "openai-compatible"
1542+
// Provide more specific guidance for OpenAI-style API providers
1543+
const openAICompatibleProviders = [
1544+
"openai",
1545+
"openai-native",
1546+
"fireworks",
1547+
"groq",
1548+
"sambanova",
1549+
"chutes",
1550+
"roo",
1551+
"zai",
1552+
"io-intelligence",
1553+
"deepseek",
1554+
"moonshot",
1555+
"doubao",
1556+
"litellm",
1557+
"lmstudio",
1558+
"ollama",
1559+
]
1560+
const isOpenAICompatible =
1561+
this.apiConfiguration.apiProvider &&
1562+
openAICompatibleProviders.includes(this.apiConfiguration.apiProvider)
15441563
const modelId = getModelId(this.apiConfiguration)
15451564

15461565
let guidanceMessage = t("common:errors.mistake_limit_guidance")
15471566

15481567
if (isOpenAICompatible) {
1549-
guidanceMessage = `The model appears to be having difficulty with tool usage. This often happens with OpenAI Compatible providers when the model doesn't properly format tool calls using XML tags.
1568+
guidanceMessage = `The model appears to be having difficulty with tool usage. This often happens with OpenAI-compatible API providers when the model doesn't properly format tool calls using XML tags.
15501569
15511570
Common issues with ${modelId || "this model"}:
15521571
1. The model may not be following the XML tool format correctly
@@ -1557,7 +1576,7 @@ Try these solutions:
15571576
• Break down your request into smaller, more specific steps
15581577
• Be more explicit about what you want to accomplish
15591578
• Try a different model that better supports tool usage
1560-
• Ensure your OpenAI Compatible endpoint is properly configured`
1579+
• Ensure your API endpoint is properly configured`
15611580
}
15621581

15631582
const { response, text, images } = await this.ask("mistake_limit_reached", guidanceMessage)

0 commit comments

Comments
 (0)