fix(prompt): preserve Google assistant text alongside tool calls#1940
Open
zxuhan wants to merge 1 commit intoJetBrains:developfrom
Open
fix(prompt): preserve Google assistant text alongside tool calls#1940zxuhan wants to merge 1 commit intoJetBrains:developfrom
zxuhan wants to merge 1 commit intoJetBrains:developfrom
Conversation
GoogleLLMClient was filtering out Message.Assistant whenever any Tool.Call was present in the same response, silently dropping model output. The encoder also wrote assistant text and the tool call as two separate "model" turns, which Gemini does not expect when they came from a single response. Keep all decoded responses, and merge buffered assistant text into the same GoogleContent as the following Tool.Calls. Close the model turn explicitly when a Tool.Result starts a user turn so the resulting contents alternate user/model correctly. Fixes JetBrains#1152
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
Fixes #1152.
GoogleLLMClientwas filtering outMessage.Assistantwhenever the same response contained anyTool.Call, silently discarding model-generated text the user had already paid for. The encoder also wrote that assistant text and the tool call as two separate"model"turns, which is not how Gemini emitted them.This change:
responses.filter { ... }inprocessGoogleCandidatethat dropped assistant text when tool calls were present.pendingTextPartsbuffer increateGoogleRequestso assistant text is sent in the sameGoogleContentas the followingTool.Call(s).Tool.Resultcloses any pending model turn and a followingAssistantcloses any pending user (results) turn. This keepsuser/modelalternation correct across tool round-trips.Existing tests around parallel tool calls and thought signatures continue to pass; the helper rename from
flushCallstoflushModeldoes not change observable behavior for those cases.Test plan
./gradlew :prompt:prompt-executor:prompt-executor-clients:prompt-executor-google-client:jvmTest(43 tests, 0 failures)processGoogleCandidate keeps Assistant text alongside Tool CallprocessGoogleCandidate keeps Reasoning, Assistant text, and Tool Call togethercreateGoogleRequest merges Assistant text with following Tool Call into single model contentcreateGoogleRequest preserves model-user-model order across tool round-tripcreateGoogleRequest carries thought signature from Reasoning between Assistant text and Tool Call