fix(core): honor maxImages in Anthropic CUA#2044
fix(core): honor maxImages in Anthropic CUA#2044BABTUNA wants to merge 1 commit intobrowserbase:mainfrom
Conversation
|
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
There was a problem hiding this comment.
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)
why
ClientOptions.maxImageswas not honored byAnthropicCUAClient, so Anthropic CUA always kept the default image retention behavior instead of using caller-configured limits.Closes #2043.
what changed
maxImageshandling inAnthropicCUAClientconstructormaxImagestocompressConversationImages(...)in step processing2) when option is unsetClientOptions.maxImagescomment to reflect CUA support beyond MicrosoftmaxImages=0(no compression)test plan
node node_modules/vitest/vitest.mjs run --config .tmp-vitest-anthropic-max-images.mjstests/unit/anthropic-cua-max-images.test.tsnpm.cmd exec prettier -- --writeon touched filesSummary by cubic
Honors
maxImagesinAnthropicCUAClientso Anthropic CUA keeps the caller-configured number of screenshots (default 2). This fixes screenshot retention limits not being applied.maxImagesfromClientOptionsand pass it tocompressConversationImagesduring step processing.maxImages=0disables compression.ClientOptions.maxImagesdocs 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