Skip to content

fix: detect tool calls in mixed content responses for GoogleGenAiChatModel - #5489

Closed
VedantMadane wants to merge 1 commit into
spring-projects:mainfrom
VedantMadane:fix/google-genai-mixed-tool-calls-5466
Closed

VedantMadane wants to merge 1 commit into
spring-projects:mainfrom
VedantMadane:fix/google-genai-mixed-tool-calls-5466

Conversation

@VedantMadane

Copy link
Copy Markdown

Summary

Fixes #5466

GoogleGenAiChatModel.responseCandidateToGeneration used allMatch to detect function call responses, requiring all parts to be function calls. When Gemini returns a mix of text/thinking parts and functionCall parts (e.g. with thinking enabled), the check evaluated to false and tool calls were silently dropped.

Changes:

  • Changed allMatch to anyMatch so function calls are detected even when mixed with text or thought parts
  • Text content from non-function-call parts is now preserved in the AssistantMessage alongside the tool calls (previously, mixed responses resulted in empty content)
  • Added regression tests covering: mixed text + tool calls, multiple function calls with text, pure text, and pure function call responses

Before (broken):

// ALL parts must be function calls — fails on mixed responses
candidate.content().get().parts().get().stream()
    .allMatch(part -> part.functionCall().isPresent());

After (fixed):

// ANY part being a function call triggers tool call extraction
candidate.content().get().parts().get().stream()
    .anyMatch(part -> part.functionCall().isPresent());

…Model

The allMatch check in responseCandidateToGeneration required ALL parts
to be function calls, causing tool calls to be silently dropped when
the model returned a mix of text/thinking parts and functionCall parts
(e.g. Gemini with thinking enabled).

Changed to anyMatch so function calls are detected regardless of
accompanying text or thought parts. Text content from non-function-call
parts is now preserved in the AssistantMessage alongside the tool calls.

Closes spring-projects#5466

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@VedantMadane
VedantMadane force-pushed the fix/google-genai-mixed-tool-calls-5466 branch from fb951dd to 4c6e1ab Compare February 23, 2026 11:05
@lazer-dev

Copy link
Copy Markdown

this is duplication of #5468
also your fix is wrong, concatenation of content is not correct way to fix this issue

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.

GoogleGenAiChatModel fails to recognize tool calls when combined with text or thinking parts

2 participants