fix(agent): include name field on every role:tool message for Gemini compatibility#19728
Merged
Conversation
…compatibility (#16478) Gemini's OpenAI-compatibility endpoint strictly requires the `name` field on `role: tool` messages — it returns HTTP 400 ("Request contains an invalid argument") when the function name is missing. OpenAI/Anthropic/ ollama tolerate the absence, so the gap stays invisible until the conversation accumulates a tool turn and the user routes it through Gemini (direct API or via ollama-cloud proxy). Fix: add a `_get_tool_call_name_static()` helper alongside the existing `_get_tool_call_id_static()`, and populate `name` at every site that constructs a `role: tool` message — the pre-call sanitizer stub, the tool-call args repair marker, both interrupt-skip paths, both result-append paths (parallel + sequential), the invalid-tool-name recovery, the invalid-JSON-args recovery, and the exception fallback. Each call site was already in scope of the function name (`function_name`, `skipped_name`, `name`, or a dict tool_call), so the change is local — no new lookups, no behavior change for providers that already worked. Fixes #16478
1 task
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.
Salvage of #16482 onto current main.
Summary
Gemini's OpenAI-compatibility endpoint strictly requires the
namefield onrole: toolmessages — HTTP 400 (Request contains an invalid argument) when missing. OpenAI/Anthropic/Ollama tolerate the absence. Add a_get_tool_call_name_statichelper and includenameon tool messages during all message rebuild paths.Validation
scripts/run_tests.sh tests/run_agent/ -k tool_name -> passed
Original PR: #16482