fix: preserve reasoning_content in sanitized messages for Moonshot/Kimi (#3152)

Providers like Moonshot (Kimi K2.5/K2.6) require the reasoning_content
field to be present on assistant tool-call messages in multi-turn
conversations.  The sanitizer's allow-list was missing this field,
causing HTTP 400: 'thinking is enabled but reasoning_content is missing
in assistant tool call message at index N'.

Add reasoning_content to the allowed field set in
_sanitize_llm_messages and cover with regression tests.

Fixes #3118

Co-authored-by: michaelxer <michaelxer@users.noreply.github.com>
Co-authored-by: Alexandre Teixeira <111787685+alteixeira20@users.noreply.github.com>
This commit is contained in:
Michael
2026-06-10 03:44:38 +07:00
committed by GitHub
parent 8878443426
commit 2e6fff2212
2 changed files with 92 additions and 1 deletions
+1 -1
View File
@@ -832,7 +832,7 @@ def _sanitize_llm_messages(messages: List[Dict]) -> List[Dict]:
(content=None, since Gemini/Ollama reject tool_calls alongside ""). Dropping
it leaves the tool result dangling and breaks the next round.
"""
allowed = {"role", "content", "name", "tool_call_id", "tool_calls", "function_call"}
allowed = {"role", "content", "name", "tool_call_id", "tool_calls", "function_call", "reasoning_content"}
cleaned = []
for msg in messages or []:
if not isinstance(msg, dict):