Skip to content
This repository was archived by the owner on May 10, 2026. It is now read-only.

Commit d14da0b

Browse files
committed
fix(provider): include empty reasoning_content for tool-call assistant messages
OpenAI-compatible APIs (e.g. Kimi K2.5, K2.6) require reasoning_content on assistant messages that contain tool calls, even when the reasoning text is empty. Previously, normalizeMessages() only added the field when reasoning text existed or the message was after the last user turn. This caused 'thinking is enabled but reasoning_content is missing' errors for historical assistant messages with tool calls. Changes: - transform.ts: add hasToolCalls check to force reasoning_content - transform.test.ts: add test for assistant with tool calls but no reasoning Refs: AI SDK PR #12049, Vercel/ai issue #14071
1 parent fc284c0 commit d14da0b

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ function normalizeMessages(
207207
// (even if empty) to satisfy API requirements for thinking mode.
208208
const isAfterLastUser = index > lastUserIndex
209209

210-
if (reasoningText || isAfterLastUser) {
210+
// Some APIs (e.g. Kimi K2.5, K2.6 via OpenAI-compatible) require reasoning_content
211+
// on assistant messages that contain tool calls, even if the reasoning text is empty.
212+
const hasToolCalls = msg.content.some((part: any) => part.type === "tool-call")
213+
214+
if (reasoningText || isAfterLastUser || hasToolCalls) {
211215
return {
212216
...msg,
213217
content: filteredContent,

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,76 @@ describe("ProviderTransform.message - DeepSeek reasoning content", () => {
923923
expect(result[0].providerOptions?.openaiCompatible?.reasoning_content).toBe("Let me think about this...")
924924
})
925925

926+
test("assistant with tool calls but no reasoning gets empty reasoning_content", () => {
927+
const msgs = [
928+
{ role: "user", content: "Run a command" },
929+
{
930+
role: "assistant",
931+
content: [
932+
{
933+
type: "tool-call",
934+
toolCallId: "test",
935+
toolName: "bash",
936+
input: { command: "echo hello" },
937+
},
938+
],
939+
},
940+
] as any[]
941+
942+
const result = ProviderTransform.message(
943+
msgs,
944+
{
945+
id: ModelID.make("deepseek/deepseek-chat"),
946+
providerID: ProviderID.make("deepseek"),
947+
api: {
948+
id: "deepseek-chat",
949+
url: "https://api.deepseek.com",
950+
npm: "@ai-sdk/openai-compatible",
951+
},
952+
name: "DeepSeek Chat",
953+
capabilities: {
954+
temperature: true,
955+
reasoning: true,
956+
attachment: false,
957+
toolcall: true,
958+
input: { text: true, audio: false, image: false, video: false, pdf: false },
959+
output: { text: true, audio: false, image: false, video: false, pdf: false },
960+
interleaved: {
961+
field: "reasoning_content",
962+
},
963+
},
964+
cost: {
965+
input: 0.001,
966+
output: 0.002,
967+
cache: { read: 0.0001, write: 0.0002 },
968+
},
969+
limit: {
970+
context: 128000,
971+
output: 8192,
972+
},
973+
status: "active",
974+
options: {},
975+
headers: {},
976+
release_date: "2023-04-01",
977+
},
978+
{},
979+
)
980+
981+
expect(result).toHaveLength(2)
982+
// user message unchanged
983+
expect(result[0].content).toBe("Run a command")
984+
// assistant message before last user should still get empty reasoning_content if it has tool calls
985+
expect(result[1].content).toEqual([
986+
{
987+
type: "tool-call",
988+
toolCallId: "test",
989+
toolName: "bash",
990+
input: { command: "echo hello" },
991+
},
992+
])
993+
expect(result[1].providerOptions?.openaiCompatible?.reasoning_content).toBe("")
994+
})
995+
926996
test("Non-DeepSeek providers leave reasoning content unchanged", () => {
927997
const msgs = [
928998
{

0 commit comments

Comments
 (0)