fix(agent): include name field on every role:tool message for Gemini compatibility#16482
Closed
0xsir0000 wants to merge 1 commit into
Closed
fix(agent): include name field on every role:tool message for Gemini compatibility#164820xsir0000 wants to merge 1 commit into
0xsir0000 wants to merge 1 commit into
Conversation
…compatibility (NousResearch#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 NousResearch#16478
Contributor
|
Salvaged via #19728 onto current main - your commit authorship was preserved. Thanks! |
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?
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-result turn and the user routes it through Gemini (direct API or via ollama-cloud proxy).
This PR adds a `_get_tool_call_name_static()` helper alongside the existing `_get_tool_call_id_static()`, and populates `name` at every site in `run_agent.py` that constructs a `role: tool` message:
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.
Related Issue
Fixes #16478
Type of Change
Changes Made
How to Test
Automated:
```bash
pytest tests/run_agent/test_agent_guardrails.py tests/run_agent/test_tool_call_args_sanitizer.py
42 passed
```
`tests/run_agent/` overall: 555 passed (one pre-existing flaky thread-timing failure unrelated to this change).
Notes
The helper docstring spells out that `name` is best-effort: when the upstream tool_call genuinely has no `function.name` (corrupt history, dict without function key), the helper returns `""` and OpenAI/Anthropic/ollama still accept it. Gemini will only reject when both the field is empty and the conversation is being replayed there — which is the same failure mode as today.
A future cleanup could push `name` injection into a single `_make_tool_message()` constructor, but the spread-out call sites were left alone here to keep the diff a one-line addition per site.