Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/wicked-ducks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

Add support for new Gemini Computer Use models
9 changes: 5 additions & 4 deletions examples/cua-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ async function main() {

// Create a computer use agent
const agent = stagehand.agent({
provider: "openai",
// For Anthropic, use claude-sonnet-4-20250514 or claude-3-7-sonnet-latest
model: "computer-use-preview",
provider: "google",
// For Anthropic, use claude-sonnet-4-20250514 or claude-sonnet-4-5-20250929
// For OpenAI, use computer-use-preview-03-11
model: "gemini-2.5-computer-use-preview-10-2025",
instructions: `You are a helpful assistant that can use a web browser.
You are currently on the following page: ${page.url()}.
Do not ask follow up questions, the user will trust your judgement.`,
options: {
apiKey: process.env.OPENAI_API_KEY,
apiKey: process.env.GOOGLE_API_KEY,
},
});

Expand Down
11 changes: 10 additions & 1 deletion lib/agent/AgentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ToolSet } from "ai/dist";
import { AgentClient } from "./AgentClient";
import { AnthropicCUAClient } from "./AnthropicCUAClient";
import { OpenAICUAClient } from "./OpenAICUAClient";
import { GoogleCUAClient } from "./GoogleCUAClient";

// Map model names to their provider types
export const modelToAgentProviderMap: Record<string, AgentType> = {
Expand All @@ -16,6 +17,7 @@ export const modelToAgentProviderMap: Record<string, AgentType> = {
"claude-3-7-sonnet-latest": "anthropic",
"claude-sonnet-4-20250514": "anthropic",
"claude-sonnet-4-5-20250929": "anthropic",
"gemini-2.5-computer-use-preview-10-2025": "google",
};

/**
Expand Down Expand Up @@ -64,9 +66,16 @@ export class AgentProvider {
clientOptions,
tools,
);
case "google":
return new GoogleCUAClient(
type,
modelName,
userProvidedInstructions,
clientOptions,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: GoogleCUAClient constructor is missing the tools parameter that OpenAI and Anthropic clients receive

Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/agent/AgentProvider.ts
Line: 75:75

Comment:
**logic:** GoogleCUAClient constructor is missing the `tools` parameter that OpenAI and Anthropic clients receive

How can I resolve this? If you propose a fix, please make it concise.

default:
throw new UnsupportedModelProviderError(
["openai", "anthropic"],
["openai", "anthropic", "google"],
"Computer Use Agent",
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/agent/AnthropicCUAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AnthropicCUAClient extends AgentClient {
private baseURL?: string;
private client: Anthropic;
public lastMessageId?: string;
private currentViewport = { width: 1024, height: 768 };
private currentViewport = { width: 1288, height: 711 };
private currentUrl?: string;
private screenshotProvider?: () => Promise<string>;
private actionHandler?: (action: AgentAction) => Promise<void>;
Expand Down Expand Up @@ -290,7 +290,7 @@ export class AnthropicCUAClient extends AgentClient {

logger({
category: "agent",
message: `Found text block: ${textBlock.text.substring(0, 50)}...`,
message: `Found text block: ${textBlock.text}`,
level: 2,
});
} else {
Expand Down
Loading