Repository navigation
fix(llm/google): keep the first user message when include_system_in_user is set - #5597
Merged
MagMueller merged 2 commits intoAug 30, 2026
Conversation
This was referenced Sep 1, 2026
Closed
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.
Fixes #5596
ChatGoogle(include_system_in_user=True)is meant to prepend the system text to the first user message. When that message has list content it replaced it instead: the system text became the only part sent, and the user's text and images were dropped.That is the shape an agent run always produces.
use_visiondefaults toTrue,AgentMessagePrompt.get_user_message()returns list content as soon as there is a screenshot, andMessageHistory.get_messages()puts the state message first among the user messages. So with this flag on, every step sent Gemini the system prompt and nothing else, with no error anywhere.The cause was structural: the content-part conversion lived in the
elsearm of the prepend branch, so taking the prepend branch skipped it. The fix computes the system text first and then always runs the conversion, folding the system text into the leading text only forstrcontent, which is what it already did.Before, on
main:After:
Tests
Three tests in
tests/ci/models/test_llm_google.py, real objects only:test_include_system_in_user_keeps_list_content_parts: text part and image survive alongside the prepended system text.test_include_system_in_user_string_content_is_merged_into_one_part: parity guard for thestrpath, which was already correct and must stay a single merged part. This one passes onmaintoo.test_include_system_in_user_keeps_the_agent_state_message: builds the message through the realAgentMessagePromptwithuse_vision=Trueand asserts the task and screenshot reach the serialized contents.Reverting the change in
browser_use/llm/google/serializer.pyand rerunning:With the fix,
pytest tests/ci/models/test_llm_google.pygives 8 passed, 1 skipped (the skip is the livegemini-3-flash-previewtest, no API key here).Checks
pre-commit run --files browser_use/llm/google/serializer.py tests/ci/models/test_llm_google.pypasses every hook, including ruff check, ruff format and pyright at the versions pinned in.pre-commit-config.yaml.Full suite,
pytest tests/ci -q -o addopts="" --timeout=120: 2 failed, 1108 passed, 34 skipped on this branch, against 2 failed, 1105 passed, 34 skipped onmain(the +3 are the new tests). The two failures are the sametests/ci/test_beta_agent.pyisinstance checks in both runs; they are order-dependent and pass on their own, and they are unrelated to this change.Summary by cubic
Fixes #5596 by keeping the first user message's content when
include_system_in_user=Trueis set onChatGoogle. Previously, when the message had list content (text plus images, as the agent always produces with vision on), the system text replaced it and the user's text and screenshot were dropped; now the system text is prepended and the user's parts are preserved.Written for commit 6a2b0f4. Summary will update on new commits.