diff --git a/src/api/providers/__tests__/anthropic.spec.ts b/src/api/providers/__tests__/anthropic.spec.ts index 5832b96352..92180131f3 100644 --- a/src/api/providers/__tests__/anthropic.spec.ts +++ b/src/api/providers/__tests__/anthropic.spec.ts @@ -454,8 +454,8 @@ describe("AnthropicHandler", () => { ) }) - it("should include tools even when toolProtocol is set to xml (user preference now ignored)", async () => { - // XML protocol deprecation: user preference is now ignored when model supports native tools + it("should not include tools when toolProtocol is set to xml (user preference takes precedence)", async () => { + // When toolProtocol is set to xml, it takes precedence over supportsNativeTools const xmlHandler = new AnthropicHandler({ ...mockOptions, toolProtocol: "xml", @@ -471,14 +471,10 @@ describe("AnthropicHandler", () => { // Just consume } - // Native is forced when supportsNativeTools===true, so tools should still be included + // XML protocol means no tools should be included in the request expect(mockCreate).toHaveBeenCalledWith( - expect.objectContaining({ - tools: expect.arrayContaining([ - expect.objectContaining({ - name: "get_weather", - }), - ]), + expect.not.objectContaining({ + tools: expect.anything(), }), expect.anything(), ) diff --git a/src/utils/__tests__/resolveToolProtocol.spec.ts b/src/utils/__tests__/resolveToolProtocol.spec.ts index 513a7eaa35..47acd2b200 100644 --- a/src/utils/__tests__/resolveToolProtocol.spec.ts +++ b/src/utils/__tests__/resolveToolProtocol.spec.ts @@ -44,7 +44,7 @@ describe("resolveToolProtocol", () => { } // undefined lockedProtocol should return native const result = resolveToolProtocol(settings, undefined, undefined) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) + expect(result).toBe(TOOL_PROTOCOL.XML) }) }) @@ -54,7 +54,7 @@ describe("resolveToolProtocol", () => { apiProvider: "anthropic", } const result = resolveToolProtocol(settings) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) + expect(result).toBe(TOOL_PROTOCOL.XML) }) it("should use native even when user preference is XML (user prefs ignored)", () => { @@ -63,7 +63,7 @@ describe("resolveToolProtocol", () => { apiProvider: "openai-native", } const result = resolveToolProtocol(settings) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) + expect(result).toBe(TOOL_PROTOCOL.XML) }) it("should use native for OpenAI compatible provider", () => { @@ -79,7 +79,7 @@ describe("resolveToolProtocol", () => { it("should handle missing provider name gracefully", () => { const settings: ProviderSettings = {} const result = resolveToolProtocol(settings) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) // Always native now + expect(result).toBe(TOOL_PROTOCOL.XML) // Always native now }) it("should handle undefined model info gracefully", () => { @@ -87,13 +87,13 @@ describe("resolveToolProtocol", () => { apiProvider: "openai-native", } const result = resolveToolProtocol(settings, undefined) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) // Always native now + expect(result).toBe(TOOL_PROTOCOL.XML) // Always native now }) it("should handle empty settings", () => { const settings: ProviderSettings = {} const result = resolveToolProtocol(settings) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) // Always native now + expect(result).toBe(TOOL_PROTOCOL.XML) // Always native now }) }) @@ -137,13 +137,13 @@ describe("resolveToolProtocol", () => { }) describe("Backward Compatibility - User Preferences Ignored", () => { - it("should ignore user preference for XML", () => { + it("should use user preference for XML", () => { const settings: ProviderSettings = { toolProtocol: "xml", // User explicitly wants XML - ignored apiProvider: "openai-native", } const result = resolveToolProtocol(settings) - expect(result).toBe(TOOL_PROTOCOL.NATIVE) // Native is always used + expect(result).toBe(TOOL_PROTOCOL.XML) // Native is always used }) it("should return native regardless of user preference", () => { diff --git a/src/utils/resolveToolProtocol.ts b/src/utils/resolveToolProtocol.ts index d30538e30a..b095d00eb2 100644 --- a/src/utils/resolveToolProtocol.ts +++ b/src/utils/resolveToolProtocol.ts @@ -39,29 +39,19 @@ export function resolveToolProtocol( return lockedProtocol } - if (["openai", "zgsm", "gemini-cli"].includes(_providerSettings.apiProvider || "")) { - // If model doesn't support native tools, return XML immediately - // 1. User Preference - Per-Profile (explicit profile setting, highest priority) - if (_providerSettings.toolProtocol) { - return _providerSettings.toolProtocol - } - // 2.Treat undefined as unsupported (only allow native when explicitly true) - if (_modelInfo?.supportsNativeTools === true) { - return TOOL_PROTOCOL.NATIVE - } + if (_providerSettings.toolProtocol) { + return _providerSettings.toolProtocol + } - // 3. Model Default - model's preferred protocol - if (_modelInfo?.defaultToolProtocol) { - return _modelInfo.defaultToolProtocol - } + if (_modelInfo?.supportsNativeTools === true) { + return TOOL_PROTOCOL.NATIVE + } - // 3. Native Fallback - return _providerSettings.apiProvider === "zgsm" ? TOOL_PROTOCOL.XML : TOOL_PROTOCOL.NATIVE + if (_modelInfo?.defaultToolProtocol) { + return _modelInfo.defaultToolProtocol } - // 2. Always return Native protocol for new tasks - // All models now support native tools; XML is deprecated - return TOOL_PROTOCOL.NATIVE + return TOOL_PROTOCOL.XML } /**