diff --git a/internal/models/api/openaicompletions/golden_test.go b/internal/models/api/openaicompletions/golden_test.go index 663ad332..a37ea012 100644 --- a/internal/models/api/openaicompletions/golden_test.go +++ b/internal/models/api/openaicompletions/golden_test.go @@ -364,7 +364,11 @@ func TestMessages_RolesToolsAndReasoningReplay(t *testing.T) { assistant := msgs[2].(map[string]any) assert.Equal(t, "thinking...", assistant["reasoning_content"]) _, hasContent := assistant["content"] - assert.False(t, hasContent, "empty content omitted next to tool_calls") + // Issue #1487: assistant tool-call turns must carry an explicit + // `"content": ""` — vLLM/Xinference Qwen-family Jinja templates crash on + // a missing (undefined/null) content field when replaying history. + assert.True(t, hasContent, "empty content must be emitted next to tool_calls") + assert.Equal(t, "", assistant["content"], "emitted content must be empty string") tc := assistant["tool_calls"].([]any)[0].(map[string]any) assert.Equal(t, "call_1", tc["id"]) assert.Equal(t, `{"q":"x"}`, tc["function"].(map[string]any)["arguments"]) diff --git a/internal/models/api/openaicompletions/request.go b/internal/models/api/openaicompletions/request.go index 7e57ca21..f941ff59 100644 --- a/internal/models/api/openaicompletions/request.go +++ b/internal/models/api/openaicompletions/request.go @@ -121,6 +121,17 @@ func (c *Client) convertMessages(messages []api.Message) []wireMessage { default: if msg.Content != "" || len(msg.ToolCalls) == 0 { wm.Content = msg.Content + } else { + // Assistant tool-call turn with empty content: emit an + // explicit `"content": ""` instead of omitting the field. + // Strict local engines (vLLM / Xinference serving Qwen-family + // Jinja chat templates) treat a missing content field as + // undefined/null and crash when rendering the assistant turn + // for the next round. Issue #1487. The *string keeps + // `omitempty` from dropping the field: a non-nil interface + // holding a pointer serializes as "". + empty := "" + wm.Content = &empty } }