fix(chat_completions): strip tool_name from messages for strict providers#28958
Closed
savanne-kham wants to merge 1 commit into
Closed
fix(chat_completions): strip tool_name from messages for strict providers#28958savanne-kham wants to merge 1 commit into
savanne-kham wants to merge 1 commit into
Conversation
…ders The 'tool_name' key on role=tool messages is an internal Hermes field (stored in the messages.tool_name SQLite column for FTS indexing) that is not part of the OpenAI Chat Completions schema. Strict OpenAI-compatible providers — notably Moonshot AI (Kimi) — reject it with HTTP 400: Error from provider: Extra inputs are not permitted, field: 'messages[N].tool_name', value: 'execute_code' Add 'tool_name' to the sanitize block in ChatCompletionsTransport.convert_messages alongside the existing Codex Responses API fields (codex_reasoning_items, codex_message_items) so it is popped before the request is sent. Reproducer: hermes chat --model kimi-k2.6 > list the top 5 Hacker News stories -> assistant emits tool_call(execute_code) -> tool result message gets tool_name='execute_code' -> next turn's payload includes messages[N].tool_name -> 400 Permissive backends (MiniMax, OpenRouter on most routes) ignore the extra field and were masking the bug.
teknium1
added a commit
that referenced
this pull request
May 20, 2026
Salvage follow-up to PR #28958 (savanne-kham): - convert_messages() docstring now explicitly documents the tool_name strip alongside Codex fields, names which providers reject it (Fireworks, Moonshot/Kimi), and why permissive providers (OpenRouter, MiniMax) masked the bug. - AUTHOR_MAP entry for savanne.kham@protonmail.com -> savanne-kham.
Contributor
This was referenced May 20, 2026
This was referenced May 21, 2026
Lillard01
pushed a commit
to Lillard01/hermes-agent
that referenced
this pull request
May 21, 2026
Salvage follow-up to PR NousResearch#28958 (savanne-kham): - convert_messages() docstring now explicitly documents the tool_name strip alongside Codex fields, names which providers reject it (Fireworks, Moonshot/Kimi), and why permissive providers (OpenRouter, MiniMax) masked the bug. - AUTHOR_MAP entry for savanne.kham@protonmail.com -> savanne-kham.
Gpapas
pushed a commit
to Gpapas/hermes-agent
that referenced
this pull request
May 23, 2026
Salvage follow-up to PR NousResearch#28958 (savanne-kham): - convert_messages() docstring now explicitly documents the tool_name strip alongside Codex fields, names which providers reject it (Fireworks, Moonshot/Kimi), and why permissive providers (OpenRouter, MiniMax) masked the bug. - AUTHOR_MAP entry for savanne.kham@protonmail.com -> savanne-kham.
Mucky010
pushed a commit
to Mucky010/hermes-agent
that referenced
this pull request
May 24, 2026
Salvage follow-up to PR NousResearch#28958 (savanne-kham): - convert_messages() docstring now explicitly documents the tool_name strip alongside Codex fields, names which providers reject it (Fireworks, Moonshot/Kimi), and why permissive providers (OpenRouter, MiniMax) masked the bug. - AUTHOR_MAP entry for savanne.kham@protonmail.com -> savanne-kham.
Bryce-huang
pushed a commit
to wbkunlun/hermes-agent
that referenced
this pull request
May 29, 2026
Salvage follow-up to PR NousResearch#28958 (savanne-kham): - convert_messages() docstring now explicitly documents the tool_name strip alongside Codex fields, names which providers reject it (Fireworks, Moonshot/Kimi), and why permissive providers (OpenRouter, MiniMax) masked the bug. - AUTHOR_MAP entry for savanne.kham@protonmail.com -> savanne-kham. #AI commit#
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
Salvage follow-up to PR NousResearch#28958 (savanne-kham): - convert_messages() docstring now explicitly documents the tool_name strip alongside Codex fields, names which providers reject it (Fireworks, Moonshot/Kimi), and why permissive providers (OpenRouter, MiniMax) masked the bug. - AUTHOR_MAP entry for savanne.kham@protonmail.com -> savanne-kham.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The internal
tool_namekey onrole=toolmessages — stored in themessages.tool_nameSQLite column for FTS indexing — is not part of theOpenAI Chat Completions schema. Strict OpenAI-compatible providers, notably
Moonshot AI (Kimi), reject any request containing it with HTTP 400:
This PR adds
tool_nameto the sanitize block inChatCompletionsTransport.convert_messages, alongside the existingCodex Responses API fields (
codex_reasoning_items,codex_message_items),so it is popped before the request is sent.
The strip is unconditional (matches the existing Codex-strip pattern):
tool_nameis never part of any documented OpenAI Chat Completions payload,so removing it before send is safe for every provider while fixing the
strict ones. Permissive backends (MiniMax, OpenRouter on most routes) were
ignoring the extra field and masking the bug.
Related Issue
Fixes #
Type of Change
Changes Made
agent/transports/chat_completions.py— extend theneeds_sanitizedetection and the per-message
popstep inconvert_messagesto coverthe
tool_namekey.tests/agent/transports/test_chat_completions.py— addtest_convert_messages_strips_tool_namecovering both the strip on thereturned list and the deepcopy-on-demand contract (original input
untouched).
How to Test
Reproducer:
Before the fix:
tool_call(execute_code)tool_name='execute_code'messages[N].tool_nameExtra inputs are not permitted, field: 'messages[N].tool_name')After the fix:
convert_messagesstripstool_namebefore send.on
kimi-k2.6(verified end-to-end on macOS 15.x, Hermes Agent v0.14.0).Automated:
The new test (
test_convert_messages_strips_tool_name) asserts:tool_nameis removed from the returned messagetool_call_idandcontentare preservedChecklist
Code
fix(chat_completions): …)pytest tests/agent/transports/test_chat_completions.py -qand all tests passDocumentation & Housekeeping
tool_namefield