From 8de2f8d58845a13aa7c8df290a9da37705fd4160 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Tue, 24 Feb 2026 04:21:55 +0800 Subject: [PATCH] fix: preserve reasoning_content in message sanitization for thinking models _sanitize_messages strips all non-standard keys from messages, including reasoning_content. Thinking-enabled models like Moonshot Kimi k2.5 require reasoning_content to be present in assistant tool call messages when thinking mode is on, causing a BadRequestError (#1014). Add reasoning_content to _ALLOWED_MSG_KEYS so it passes through sanitization when present. Fixes #1014 --- nanobot/providers/litellm_provider.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nanobot/providers/litellm_provider.py b/nanobot/providers/litellm_provider.py index 7402a2b..0918954 100644 --- a/nanobot/providers/litellm_provider.py +++ b/nanobot/providers/litellm_provider.py @@ -12,8 +12,9 @@ from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest from nanobot.providers.registry import find_by_model, find_gateway -# Standard OpenAI chat-completion message keys; extras (e.g. reasoning_content) are stripped for strict providers. -_ALLOWED_MSG_KEYS = frozenset({"role", "content", "tool_calls", "tool_call_id", "name"}) +# Standard OpenAI chat-completion message keys plus reasoning_content for +# thinking-enabled models (Kimi k2.5, DeepSeek-R1, etc.). +_ALLOWED_MSG_KEYS = frozenset({"role", "content", "tool_calls", "tool_call_id", "name", "reasoning_content"}) class LiteLLMProvider(LLMProvider):