diff --git a/.changeset/quick-clouds-kick.md b/.changeset/quick-clouds-kick.md new file mode 100644 index 000000000..6a27d454a --- /dev/null +++ b/.changeset/quick-clouds-kick.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": patch +--- + +update cua agents key & system prompt handling diff --git a/lib/agent/GoogleCUAClient.ts b/lib/agent/GoogleCUAClient.ts index eb85de934..f1b7af225 100644 --- a/lib/agent/GoogleCUAClient.ts +++ b/lib/agent/GoogleCUAClient.ts @@ -203,14 +203,16 @@ export class GoogleCUAClient extends AgentClient { // Note: The Python implementation doesn't include the initial screenshot // Following the same pattern here + const systemPromptContent = this.userProvidedInstructions + ? this.userProvidedInstructions + : buildGoogleCUASystemPrompt().content; + this.history = [ { role: "user", parts: [ { - text: - "System prompt: " + - (buildGoogleCUASystemPrompt().content as string), + text: "System prompt: " + systemPromptContent, }, ], }, diff --git a/lib/handlers/cuaAgentHandler.ts b/lib/handlers/cuaAgentHandler.ts index 00df3cd60..c32347242 100644 --- a/lib/handlers/cuaAgentHandler.ts +++ b/lib/handlers/cuaAgentHandler.ts @@ -271,7 +271,10 @@ export class CuaAgentHandler { case "keypress": { const { keys } = action; if (Array.isArray(keys)) { - await this.page.keyboard.press(keys.join("+")); + const mappedKeys = keys.map((key) => + mapKeyToPlaywright(String(key)), + ); + await this.page.keyboard.press(mappedKeys.join("+")); } return { success: true }; }