Skip to content

fix(core): honor maxImages in Anthropic CUA#2044

Open
BABTUNA wants to merge 1 commit intobrowserbase:mainfrom
BABTUNA:fix-cua-anthropic-max-images
Open

fix(core): honor maxImages in Anthropic CUA#2044
BABTUNA wants to merge 1 commit intobrowserbase:mainfrom
BABTUNA:fix-cua-anthropic-max-images

Conversation

@BABTUNA
Copy link
Copy Markdown
Contributor

@BABTUNA BABTUNA commented Apr 24, 2026

why

ClientOptions.maxImages was not honored by AnthropicCUAClient, so Anthropic CUA always kept the default image retention behavior instead of using caller-configured limits.

Closes #2043.

what changed

  • Added maxImages handling in AnthropicCUAClient constructor
  • Applied maxImages to compressConversationImages(...) in step processing
  • Preserved existing default behavior (2) when option is unset
  • Updated ClientOptions.maxImages comment to reflect CUA support beyond Microsoft
  • Added unit tests for:
    • default keep-2 behavior
    • keep-1 override
    • maxImages=0 (no compression)

test plan

  • node node_modules/vitest/vitest.mjs run --config .tmp-vitest-anthropic-max-images.mjs
    • tests/unit/anthropic-cua-max-images.test.ts
  • npm.cmd exec prettier -- --write on touched files

Summary by cubic

Honors maxImages in AnthropicCUAClient so Anthropic CUA keeps the caller-configured number of screenshots (default 2). This fixes screenshot retention limits not being applied.

  • Bug Fixes
    • Read maxImages from ClientOptions and pass it to compressConversationImages during step processing.
    • Keep default 2 when unset; maxImages=0 disables compression.
    • Update ClientOptions.maxImages docs for CUA support and add unit tests for default, 1, and 0 cases.

Written for commit fdc6133. Summary will update on new commits. Review in cubic

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: fdc6133

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Apr 24, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant User as Caller
    participant CUA as AnthropicCUAClient
    participant Utils as compressConversationImages()
    participant API as Anthropic API

    User->>CUA: constructor(clientOptions)
    Note over CUA: CHANGED: Store maxImages from options<br/>(Defaults to 2 if unset)

    User->>CUA: executeStep(inputItems)
    
    rect rgb(240, 240, 240)
        Note over CUA, Utils: Image Retention Logic
        alt NEW: maxImages > 0
            CUA->>Utils: CHANGED: Pass user-defined maxImages limit
            Utils-->>CUA: inputItems with images > limit converted to text
        else NEW: maxImages == 0
            Note over CUA: Skip compression (retain all images)
        end
    end

    CUA->>CUA: internal: getAction(nextInputItems)
    CUA->>API: POST /messages (with processed history)
    API-->>CUA: assistant response / tool_use
    
    CUA-->>User: StepResult (action + nextInputItems)
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): honor maxImages in Anthropic CUA screenshot compression

1 participant