fix(core): map ROLE.TOOL to "user" for Google, Gemini 3.x rejects role "tool" - #145
Open
andrewbiolo wants to merge 1 commit into
Open
fix(core): map ROLE.TOOL to "user" for Google, Gemini 3.x rejects role "tool"#145andrewbiolo wants to merge 1 commit into
andrewbiolo wants to merge 1 commit into
Conversation
…e "tool" Gemini 3.x models reject tool-result turns sent with role "tool" (400 INVALID_ARGUMENT: "Role 'tool' is not supported"), while 2.x tolerated it. Function responses must be sent as "user" turns, which both generations accept, and this matches the convention already used by anthropic_role. Tested with a multi-step tool-calling Agent on gemini-3.6-flash (previously failing at the first tool round-trip) and verified gemini-2.5-flash keeps working. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
The problem
Running an Agent with tools against the new Gemini 3.x models (tested on
gemini-3.6-flashandgemini-3.7-flash) fails on the second step, as soon as a tool result is sent back to the model:Gemini 2.5 tolerated the "tool" role, so everything looked fine until the 3.x generation. The failure comes from
ROLE.google_roleindatapizza-ai-core/datapizza/type/type.py, which mapsROLE.TOOLto "tool"; the memory adapter of the Google client then builds the tool-result turn with that role.This is basically the second half of #101:
thought_signaturegot fixed there, but the role mapping still blocks any tool loop on Gemini 3.x.The fix
Map
ROLE.TOOLto "user" for Google, which is the convention for functionResponse turns and works on both the 2.x and 3.x generations. It is also consistent with what the library already does for Anthropic (anthropic_rolemaps TOOL to "user").How I tested it
Real-world RAG agent (GoogleClient + 7 tools, multi-step runs) on
gemini-3.6-flash: before the patch every run died with the 400 above; after the patch the full tool loop works, tool results are consumed correctly and answers come back grounded as expected. Also verified thatgemini-2.5-flashkeeps working with the new mapping.Let me know if you want any change, happy to adjust.
🤖 Generated with Claude Code