diff --git a/packages/core/src/core/openaiContentGenerator/provider/default.test.ts b/packages/core/src/core/openaiContentGenerator/provider/default.test.ts index 3c7f9ce1b22..07032ea6806 100644 --- a/packages/core/src/core/openaiContentGenerator/provider/default.test.ts +++ b/packages/core/src/core/openaiContentGenerator/provider/default.test.ts @@ -285,6 +285,31 @@ describe('DefaultOpenAICompatibleProvider', () => { expect(result).not.toBe(originalRequest); // Should be a new object }); + it('forwards a parameterless tool without a parameters key', () => { + // Negative pin for the MiniMax-only scoping in minimax.ts: the default + // provider must not synthesize a schema for zero-argument tools. + // converter.ts deliberately omits `parameters` for them (#11431), and + // the endpoints #10080 was written for (llama.cpp, LM Studio, vLLM) + // reject the empty-object shape. Assert on the serialized body because + // a converter-shaped tool carries `parameters: undefined` present, + // which JSON.stringify drops — matching what actually ships. + const result = provider.buildRequest( + { + model: 'some-model', + messages: [{ role: 'user', content: 'Hello' }], + tools: [ + { + type: 'function', + function: { name: 'no_args', description: 'd' }, + }, + ], + }, + 'prompt-id', + ); + + expect(JSON.stringify(result.tools)).not.toContain('"parameters"'); + }); + it('should set model max_tokens default when not configured', () => { const requestWithoutMaxTokens: OpenAI.Chat.ChatCompletionCreateParams = { model: 'gpt-4', diff --git a/packages/core/src/core/openaiContentGenerator/provider/minimax.test.ts b/packages/core/src/core/openaiContentGenerator/provider/minimax.test.ts index faa4560b3f9..7646cc02005 100644 --- a/packages/core/src/core/openaiContentGenerator/provider/minimax.test.ts +++ b/packages/core/src/core/openaiContentGenerator/provider/minimax.test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import type OpenAI from 'openai'; import { describe, expect, it, vi } from 'vitest'; import type { Config } from '../../../config/config.js'; import type { ContentGeneratorConfig } from '../../contentGenerator.js'; @@ -138,4 +139,92 @@ describe('MiniMaxOpenAICompatibleProvider', () => { expect(provider).toBeInstanceOf(MiniMaxOpenAICompatibleProvider); }); + + describe('buildRequest', () => { + function buildWithTools( + tools: OpenAI.Chat.ChatCompletionTool[], + ): OpenAI.Chat.ChatCompletionCreateParams { + const provider = new MiniMaxOpenAICompatibleProvider( + createConfig('https://api.minimaxi.com/v1'), + mockCliConfig, + ); + return provider.buildRequest( + { + model: 'MiniMax-M3', + messages: [{ role: 'user', content: 'Hello' }], + tools, + }, + 'prompt-id', + ); + } + + it('injects an empty schema on zero-argument tools', () => { + const result = buildWithTools([ + { + type: 'function', + function: { name: 'cron_list', description: 'desc' }, + }, + ]); + + expect(result.tools).toEqual([ + { + type: 'function', + function: { + name: 'cron_list', + description: 'desc', + parameters: { type: 'object', properties: {} }, + }, + }, + ]); + }); + + it('injects the schema when the converter left parameters present-but-undefined', () => { + // converter.ts emits parameterless tools with `parameters: undefined` + // (key present); the injection predicate must test the value, not key + // presence, or the production shape stops receiving the fix. + const result = buildWithTools([ + { + type: 'function', + function: { + name: 'cron_status', + description: 'desc', + parameters: undefined, + }, + }, + ]); + + expect(result.tools).toEqual([ + { + type: 'function', + function: { + name: 'cron_status', + description: 'desc', + parameters: { type: 'object', properties: {} }, + }, + }, + ]); + }); + + it('passes a tool with a declared schema through unchanged', () => { + const schema = { + type: 'object', + properties: { path: { type: 'string' } }, + required: ['path'], + }; + + const result = buildWithTools([ + { + type: 'function', + function: { name: 'read_file', description: 'd', parameters: schema }, + }, + ]); + + expect(result.tools).toEqual([ + { + type: 'function', + function: { name: 'read_file', description: 'd', parameters: schema }, + }, + ]); + }); + }); }); diff --git a/packages/core/src/core/openaiContentGenerator/provider/minimax.ts b/packages/core/src/core/openaiContentGenerator/provider/minimax.ts index 49b09747924..18cc487ec30 100644 --- a/packages/core/src/core/openaiContentGenerator/provider/minimax.ts +++ b/packages/core/src/core/openaiContentGenerator/provider/minimax.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import type OpenAI from 'openai'; import type { ContentGeneratorConfig } from '../../contentGenerator.js'; import type { OpenAIResponseParsingOptions } from '../responseParsingOptions.js'; import { DefaultOpenAICompatibleProvider } from './default.js'; @@ -38,6 +39,39 @@ export class MiniMaxOpenAICompatibleProvider extends DefaultOpenAICompatibleProv } } + /** + * MiniMax rejects a function tool that carries no `parameters` at all + * (#11834: `400 invalid params, function parameters is empty (2013)`), so + * zero-argument tools get an empty object schema injected here. + * + * This deliberately reverses the converter's invariant one layer down: + * converter.ts sets `parameters = undefined` for parameterless tools + * (#11431), because the default-provider endpoints #10080 was written for + * (llama.cpp, LM Studio, vLLM) reject the empty-object shape. Keep this + * MiniMax-scoped: do not hoist it into DefaultOpenAICompatibleProvider, + * and do not move it into the converter ahead of + * `relaxSchemaForFunctionCalling`, which strips empty `properties` and + * would emit the bare `{"type":"object"}` that #11410 reports as a 400. + */ + override buildRequest( + request: OpenAI.Chat.ChatCompletionCreateParams, + userPromptId: string, + ): OpenAI.Chat.ChatCompletionCreateParams { + const baseRequest = super.buildRequest(request, userPromptId); + baseRequest.tools = baseRequest.tools?.map((tool) => + tool.function.parameters === undefined + ? { + ...tool, + function: { + ...tool.function, + parameters: { type: 'object', properties: {} }, + }, + } + : tool, + ); + return baseRequest; + } + override getResponseParsingOptions(): OpenAIResponseParsingOptions { return { taggedThinkingTags: true }; }