Repository navigation
fix(agent): declare read_file GIF/WEBP images with their real media type - #5847
Open
Lesereingrape wants to merge 7 commits into
Open
Lesereingrape wants to merge 7 commits into
Lesereingrape wants to merge 7 commits into
Conversation
read_file returns image bytes unchanged, but the prompt builder labelled every non-.png file image/jpeg, so GIF and WEBP payloads reached providers that trust the declared format. Add the two suffixes the supported media-type literal already allows and keep image/jpeg as the fallback for names it does not recognise.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
sun04222
added a commit
to sun04222/browser-use
that referenced
this pull request
Oct 23, 2026
… prompts.py taken from PR head)
This branch has not been deployed
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.
Closes #5846
Problem
read_fileaccepts.jpg,.jpeg,.png,.gifand.webp, andFileSystem.read_file_structured(browser_use/filesystem/file_system.py:817-827) base64-encodes the bytes without converting them. The prompt builder that turns those images into message content parts, however, recognised exactly one suffix and assumed JPEG for everything else:so
chart.gifleft the agent asdata:image/jpeg;base64,R0lGODdh...withImageURL.media_type='image/jpeg'. The declaration is honoured downstream rather than re-derived:llm/anthropic/serializer.py:56acceptsimage/gifandimage/webpamong the types it parses from the data URL, andllm/google/serializer.py:107-109usespart.image_url.media_typedirectly under the comment "which correctly identifies the image format". Both are told the payload is a JPEG when it is not.Change
Two added branches in
browser_use/agent/prompts.py, using the two media typesSupportedImageMediaType(llm/messages.py:51) already allows..jpg/.jpegand unrecognised names keep the existingimage/jpegresult, so the only behaviour that changes is GIF and WEBP:No re-encoding and no magic-byte sniffing is introduced: the payload stays exactly what it was, only the label it is announced with changes.
Measurements
Local,
d8110c5f(main) as the base, one test added totests/ci/test_file_system_llm_integration.py:pytest tests/ci/test_file_system_llm_integration.py -o addopts=""1 failed, 11 passed—data:image/jpeg;base64,R0lGODdh…forchart.gif6b821f1d, same module12 passed6b821f1d, 6 related modules (file_system images/docx/llm, prompt_step_meta, message_manager_state_isolation, anthropic_serialized_tool_input)pytest … -o addopts="" -q -p no:randomly59 passedThe two pre-existing tests that assert
data:image/pnganddata:image/jpegfor a PNG and a JPG pass identically on both sides, so they are the control for "nothing else moved".A standalone script (the one in the linked issue) printed the declared type per file name:
chart.gifimage/jpegimage/gifsticker.webpimage/jpegimage/webpplot.pngimage/pngimage/pngphoto.jpgimage/jpegimage/jpegTooling on the diff:
ruff checkandruff format --checkclean (measured on LF-normalised copies — this clone hascore.autocrlf=true, so the working files are CRLF and a raw format check reports a whole-file rewrite).pyright 1.1.414reports0 errorsonbrowser_use/agent/prompts.py. An earlier revision of this fix used adict+next()lookup and pyright rejected the assignment (Type "str" is not assignable to declared type "SupportedImageMediaType"), which is why the final diff is the plain if/elif chain.Not measured / scope
tests/cidirectory locally, and I sent no request to a real provider — the verified claim stops at what the agent puts into the message. That the mislabelled declaration then reaches Anthropic/Bedrock/Google as-is is read from the serializer code cited above, not from an API round-trip..webphere means the file the user put on disk; this change does not add validation that the bytes match the extension, and does not touch the screenshot path, which really is PNG.CLA / provenance
I have signed the CLA as prompted by the bot. This contribution was prepared autonomously by my coding agent and the diff has not been reviewed line-by-line by a human, so the human-only checkboxes are left unticked deliberately; I am the accountable author and will answer review questions and re-verify anything a maintainer asks about.
Summary by cubic
Fixes #5846 so
read_fileGIF and WEBP images are declared with their real media type instead of being labeledimage/jpeg. The prompt builder now adds.gifand.webpbranches; PNG, JPEG, and unrecognized names keep existing behavior, and image bytes are unchanged. Adds a test verifying GIF and WEBP data URLs and media types are declared correctly.Written for commit 1ebfc95. Summary will update on new commits.