fix(anthropic_adapter): preserve reasoning_content on assistant tool-call messages for Kimi /coding

Fixes NousResearch/hermes-agent#13848

Kimi's /coding endpoint speaks the Anthropic Messages protocol but has its
own thinking semantics: when thinking is enabled, Kimi validates message
history and requires every prior assistant tool-call message to carry
OpenAI-style reasoning_content.

The Anthropic path never populated that field, and
convert_messages_to_anthropic strips all Anthropic thinking blocks on
third-party endpoints — so the request failed with HTTP 400:
  "thinking is enabled but reasoning_content is missing in assistant
tool call message at index N"

Now, when an assistant message contains tool_calls and a
reasoning_content string, we append a {"type": "thinking", ...} block
to the Anthropic content so Kimi can validate the history.  This only
affects assistant messages with tool_calls + reasoning_content; plain
text assistant messages are unchanged.
This commit is contained in:
Jerome 2026-04-22 15:18:49 +08:00 committed by kshitij
parent 77e04a29d5
commit 2efb0eea21

View file

@ -1083,6 +1083,13 @@ def convert_messages_to_anthropic(
"name": fn.get("name", ""),
"input": parsed_args,
})
# Kimi's /coding endpoint (Anthropic protocol) requires assistant
# tool-call messages to carry reasoning_content when thinking is
# enabled. Preserve it as a thinking block so Kimi can validate
# the message history. See hermes-agent#13848.
reasoning_content = m.get("reasoning_content")
if reasoning_content and isinstance(reasoning_content, str):
blocks.append({"type": "thinking", "thinking": reasoning_content})
# Anthropic rejects empty assistant content
effective = blocks or content
if not effective or effective == "":