Skip to content

fix(browser-use-demo): bound screenshots by only_n_most_recent_images (#415) - #458

Open
AbhiPra24 wants to merge 1 commit into
anthropics:mainfrom
AbhiPra24:fix/browser-use-recent-images-bound
Open

AbhiPra24 wants to merge 1 commit into
anthropics:mainfrom
AbhiPra24:fix/browser-use-recent-images-bound

Conversation

@AbhiPra24

Copy link
Copy Markdown

Description

Fixes #415

Currently in browser-use-demo, only_n_most_recent_images was defined as a parameter in sampling_loop and passed from streamlit.py, but it was never invoked inside the sampling loop, and the stub _maybe_filter_to_n_most_recent_images did not inspect tool_result content blocks where screenshots are stored. As a result, screenshots accumulated unbounded in the message history, significantly inflating token usage over multi-step interactions.

Changes

  • Filtering inside sampling_loop: Invoke _maybe_filter_to_n_most_recent_images(messages, only_n_most_recent_images) on each turn in the sampling loop before API calls.
  • Inspect tool_result and top-level image blocks: Updated _maybe_filter_to_n_most_recent_images to inspect and filter images within both tool_result content lists (preserving textual tool outputs) and direct message blocks.
  • Streamlit Configuration: Added only_n_most_recent_images (defaulting to 3) in session state defaults and added a sidebar number input for user customization.
  • Unit Tests: Added test suite (TestRecentImagesFiltering) in tests/test_sampling_loop.py verifying image bounding, preservation of non-image tool results, and integration with sampling_loop.

Verification

Ran test suite:

pytest browser-use-demo/tests/test_sampling_loop.py -k "TestRecentImagesFiltering" -v

All tests passed.

… config (anthropics#415)

- Call _maybe_filter_to_n_most_recent_images in sampling_loop prior to API call
- Support filtering images from tool_result content and user messages
- Add only_n_most_recent_images to session state defaults and sidebar config
- Add unit tests for image filtering and bound application in sampling_loop
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.

[browser-use-demo] only_n_most_recent_images is ignored — screenshots accumulate unbounded

1 participant