From 6775dd4699024bd93e2f086ba24801608c56615f Mon Sep 17 00:00:00 2001 From: Andrea Biolo Date: Fri, 14 Aug 2026 14:13:07 +0200 Subject: [PATCH] fix(core): map ROLE.TOOL to "user" for Google, Gemini 3.x rejects role "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 --- datapizza-ai-core/datapizza/type/type.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datapizza-ai-core/datapizza/type/type.py b/datapizza-ai-core/datapizza/type/type.py index 268d76ea..d86facaf 100644 --- a/datapizza-ai-core/datapizza/type/type.py +++ b/datapizza-ai-core/datapizza/type/type.py @@ -29,7 +29,10 @@ def google_role(self) -> str: elif self == ROLE.ASSISTANT or self == ROLE.SYSTEM: return "model" elif self == ROLE.TOOL: - return "tool" + # Gemini 3.x rejects the "tool" role with 400 INVALID_ARGUMENT + # ("Role 'tool' is not supported"); function responses must be + # sent as "user" turns, which older models accept as well. + return "user" else: raise ValueError(f"Unknown role: {self}")