-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix(gemini): Add role="user" to function_response content #20694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(gemini): Add role="user" to function_response content #20694
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryThis PR updates the Gemini/Vertex message transformation so that accumulated tool/function responses are wrapped in a The change is localized to Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/gemini/transformation.py | Adds explicit role="user" on ContentType entries created for accumulated tool/function responses to satisfy Gemini/Vertex multi-turn function-calling requirements. |
Sequence Diagram
sequenceDiagram
participant Client as LiteLLM Client
participant Tx as gemini/transformation.py
participant Gemini as Vertex/Gemini API
Client->>Tx: _transform_request_body(messages, model,...)
Tx->>Tx: _gemini_convert_messages_with_history(messages)
loop iterate messages
Tx->>Tx: convert_to_gemini_tool_call_invoke(assistant_msg)
Tx->>Tx: convert_to_gemini_tool_call_result(tool/function msg)
Tx->>Tx: contents.append(ContentType(role="user", parts=tool_call_responses))
end
Tx->>Gemini: POST /generateContent { contents: [...] }
Gemini-->>Client: 200 response (no INVALID_ARGUMENT on missing role)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, no comments
|
@Mr-Neutr0n please add a unit test for this |
|
I]recheck |
|
recheck |
Add missing role="user" when constructing ContentType for function responses in Gemini/Vertex AI. Without this role, multi-turn function calling fails with INVALID_ARGUMENT (400) from the Google API. Fixes BerriAI#20690 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add two tests to verify that function_response ContentType entries have role='user' as required by the Gemini API: - test_function_response_has_user_role: Tests single tool response - test_multiple_function_responses_have_user_role: Tests parallel tool calls Relates to BerriAI#20690
8dcb8b6 to
f3dcc25
Compare
|
recheck |
|
@krrishdholakia Added unit tests in the second commit (f3dcc25). The tests verify that:
All CI checks pass (lint, unit-test, MCP tests, Helm tests). The mock test suite is running. |
|
recheck |
|
@krrishdholakia Are we safe to merge? |
Summary
role="user"when constructingContentTypefor function responses in Gemini/Vertex AI transformationINVALID_ARGUMENT(400) from the Google APIThe Bug
When using Gemini models with multi-turn function calling, LiteLLM fails to include
role="user"when constructing thefunction_responsepart of the payload.Error: 400 INVALID_ARGUMENT from Google API
Changes
File:
litellm/llms/vertex_ai/gemini/transformation.pyTwo locations where
tool_call_responsesare appended without role:Test plan
Fixes #20690
🤖 Generated with Claude Code