Skip to content

fix(core): map ROLE.TOOL to "user" for Google, Gemini 3.x rejects role "tool" - #145

Open
andrewbiolo wants to merge 1 commit into
datapizza-labs:mainfrom
andrewbiolo:fix/gemini-3-tool-role
Open

fix(core): map ROLE.TOOL to "user" for Google, Gemini 3.x rejects role "tool"#145
andrewbiolo wants to merge 1 commit into
datapizza-labs:mainfrom
andrewbiolo:fix/gemini-3-tool-role

Conversation

@andrewbiolo

Copy link
Copy Markdown

The problem

Running an Agent with tools against the new Gemini 3.x models (tested on gemini-3.6-flash and gemini-3.7-flash) fails on the second step, as soon as a tool result is sent back to the model:

google.genai.errors.ClientError: 400 INVALID_ARGUMENT.
{'error': {'code': 400, 'message': "Role 'tool' is not supported. Please use a valid role: SYSTEM, SYSTEM_1, USER, ASSISTANT, DEVELOPER, CONTEXT, USER_CONTEXT, MODEL, USER.", 'status': 'INVALID_ARGUMENT'}}

Gemini 2.5 tolerated the "tool" role, so everything looked fine until the 3.x generation. The failure comes from ROLE.google_role in datapizza-ai-core/datapizza/type/type.py, which maps ROLE.TOOL to "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_signature got fixed there, but the role mapping still blocks any tool loop on Gemini 3.x.

The fix

Map ROLE.TOOL to "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_role maps 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 that gemini-2.5-flash keeps working with the new mapping.

Let me know if you want any change, happy to adjust.

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant