Fix Gemini tool calling on 3.6+ by using documented function response role (#24013)

Gemini 3.6 and newer reject role="function" on the function response
Content with 400 INVALID_ARGUMENT, breaking any chat query that triggers
a tool call. The tool call itself succeeds; only the hand-back to the
model fails, and because the error surfaces mid-stream the request still
returns HTTP 200, so it is easy to miss.

Google's function calling documentation specifies role="user" for
returning function results:

    contents.append(response.candidates[0].content)
    contents.append(types.Content(role="user", parts=[function_response_part]))

https://ai.google.dev/gemini-api/docs/generate-content/function-calling

Verified with my local setup.
This commit is contained in:
dtighe 2026-08-18 07:16:47 -07:00 committed by GitHub
parent 77fc2ce174
commit 8384a8c5b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -245,7 +245,7 @@ class GeminiClient(GenAIClient):
)
gemini_messages.append(
types.Content(
role="function",
role="user",
parts=[
types.Part.from_function_response(
name=msg.get("name")
@ -501,7 +501,7 @@ class GeminiClient(GenAIClient):
)
gemini_messages.append(
types.Content(
role="function",
role="user",
parts=[
types.Part.from_function_response(
name=msg.get("name")