From 520795fdd24eda01fc410b4d780e051caece4c2e Mon Sep 17 00:00:00 2001 From: MrFant Date: Thu, 14 May 2026 02:04:59 +0800 Subject: [PATCH] fix: preserve reasoning_content in API message whitelist Providers like Xiaomi MiMo, DeepSeek, and Kimi require reasoning_content to be echoed back on every assistant message in multi-turn conversations with tool calls. Omitting it causes HTTP 400: 'The reasoning_content in the thinking mode must be passed back to the API.' The WebUI's _sanitize_messages_for_api() strips all fields not in _API_SAFE_MSG_KEYS before sending conversation history to the LLM API. reasoning_content was not in this whitelist, so it was silently dropped. The CLI path (run_agent.py) is unaffected because it has its own _copy_reasoning_content_for_api() logic that operates on raw message dicts without going through this filter. This is why the same session works from CLI but fails from WebUI with HTTP 400. The fix adds 'reasoning_content' to _API_SAFE_MSG_KEYS so the field passes through sanitization intact. --- api/streaming.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/streaming.py b/api/streaming.py index c596f2bf..3781cb0b 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -266,7 +266,7 @@ from api.workspace import set_last_workspace # Fields that are safe to send to LLM provider APIs. # Everything else (attachments, timestamp, _ts, etc.) is display-only # metadata added by the webui and must be stripped before the API call. -_API_SAFE_MSG_KEYS = {'role', 'content', 'tool_calls', 'tool_call_id', 'name', 'refusal'} +_API_SAFE_MSG_KEYS = {'role', 'content', 'tool_calls', 'tool_call_id', 'name', 'refusal', 'reasoning_content'} _NATIVE_IMAGE_MAX_BYTES = 20 * 1024 * 1024