fix: return tool_calls finish_reason for Gemini function calls#1534
Open
fix: return tool_calls finish_reason for Gemini function calls#1534
Conversation
Gemini API returns finishReason: "STOP" even when the response contains function calls. This fix detects tool calls in the response content and returns finish_reason: "tool_calls" for OpenAI compatibility. Affects both streaming and non-streaming responses for Google and Google Vertex AI providers. Co-authored-by: Cursor <cursoragent@cursor.com>
narengogi
requested changes
Feb 23, 2026
Member
narengogi
left a comment
There was a problem hiding this comment.
would recommend extracting this to google-vertex-ai/utils.ts and also making use of FINISH_REASON.tool_calls instead of hard coding the string
- Add hasToolCalls helper function to google-vertex-ai/utils.ts - Use FINISH_REASON.tool_calls instead of hardcoded string - Import and reuse helper in both Google and Vertex AI providers Co-authored-by: Cursor <cursoragent@cursor.com>
narengogi
requested changes
Mar 10, 2026
| provider: GOOGLE_VERTEX_AI, | ||
| choices: | ||
| parsedChunk.candidates?.map((generation, index) => { | ||
| const containsToolCalls = hasToolCalls(generation.content?.parts); |
Member
There was a problem hiding this comment.
you'd want to store this variable in streamState and make use of it because the last chunk might not have the tool call in the chunk
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.
Summary
finish_reason: "stop"instead of"tool_calls"when function calls are presentfinishReason: "STOP"even when the response contains function calls (there is noFUNCTION_CALLfinish reason in Gemini's API)finish_reason: "tool_calls"for OpenAI compatibilityChanges
GoogleChatCompleteResponseTransform(non-streaming) for both Google and Vertex AIGoogleChatCompleteStreamChunkTransform(streaming) for both Google and Vertex AITest plan
finish_reason: "tool_calls"in non-streaming modefinish_reason: "tool_calls"in streaming modeMade with Cursor