Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(models): emit explicit empty content for assistant tool-call turns (#3605)

LuckVdea7cf8d5d77c
diff --git a/internal/models/api/openaicompletions/golden_test.go b/internal/models/api/openaicompletions/golden_test.go
index 663ad3328..a37ea0125 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 7e57ca21b..f941ff595 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
}
}