diff --git a/run_agent.py b/run_agent.py index 43c367e460f..b567b965458 100644 --- a/run_agent.py +++ b/run_agent.py @@ -7868,7 +7868,17 @@ class AIAgent: api_msg["reasoning_content"] = existing return - # 2. DeepSeek / Kimi thinking mode: tool-call turns that lack + # 2. Healthy session: promote 'reasoning' field to 'reasoning_content' + # for providers that use the internal 'reasoning' key. + # This must happen BEFORE the DeepSeek/Kimi tool-call check so that + # genuine reasoning content is not overwritten by the empty-string + # fallback (#15812 regression in PR #15478). + normalized_reasoning = source_msg.get("reasoning") + if isinstance(normalized_reasoning, str) and normalized_reasoning: + api_msg["reasoning_content"] = normalized_reasoning + return + + # 3. DeepSeek / Kimi thinking mode: tool-call turns that lack # reasoning_content are "poisoned history" — a prior provider (MiniMax, # etc.) left them empty. DeepSeek returns HTTP 400 if reasoning_content # is absent on replay; inject "" to satisfy the provider's requirement @@ -7884,13 +7894,6 @@ class AIAgent: api_msg["reasoning_content"] = "" return - # 3. Healthy session: promote 'reasoning' field to 'reasoning_content' - # for providers that use the internal 'reasoning' key. - normalized_reasoning = source_msg.get("reasoning") - if isinstance(normalized_reasoning, str) and normalized_reasoning: - api_msg["reasoning_content"] = normalized_reasoning - return - # 4. DeepSeek / Kimi thinking mode: all assistant messages need # reasoning_content. Inject "" to satisfy the provider's requirement # when no explicit reasoning content is present.