Skip to content

Commit 3b9cbea

Browse files
authored
fix(tools): updated browser use and stagehand to use the latest models (#2319)
* fix(stagehand): incl stagehand in the standalone build * fix(stagehand): updated browser use and stagehand to use the latest models
1 parent c592e54 commit 3b9cbea

File tree

5 files changed

+55
-36
lines changed

5 files changed

+55
-36
lines changed

apps/sim/app/api/tools/stagehand/agent/route.ts

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ export async function POST(request: NextRequest) {
496496
verbose: 1,
497497
logger: (msg) => logger.info(typeof msg === 'string' ? msg : JSON.stringify(msg)),
498498
model: {
499-
modelName: 'claude-sonnet-4-20250514',
499+
modelName: 'anthropic/claude-3-7-sonnet-latest',
500500
apiKey: apiKey,
501501
},
502502
})
@@ -704,7 +704,14 @@ The system will substitute actual values when these placeholders are used, keepi
704704
`.trim()
705705

706706
const agent = stagehand.agent({
707-
model: 'anthropic/claude-sonnet-4-20250514',
707+
model: {
708+
modelName: 'anthropic/claude-3-7-sonnet-latest',
709+
apiKey: apiKey,
710+
},
711+
executionModel: {
712+
modelName: 'anthropic/claude-3-7-sonnet-latest',
713+
apiKey: apiKey,
714+
},
708715
systemPrompt: `${agentInstructions}\n\n${additionalContext}`,
709716
})
710717

@@ -795,6 +802,9 @@ The system will substitute actual values when these placeholders are used, keepi
795802
})
796803

797804
let structuredOutput = null
805+
const hasOutputSchema =
806+
outputSchema && typeof outputSchema === 'object' && outputSchema !== null
807+
798808
if (agentResult.message) {
799809
try {
800810
let jsonContent = agentResult.message
@@ -807,33 +817,31 @@ The system will substitute actual values when these placeholders are used, keepi
807817
structuredOutput = JSON.parse(jsonContent)
808818
logger.info('Successfully parsed structured output from agent response')
809819
} catch (parseError) {
810-
logger.error('Failed to parse JSON from agent message', {
811-
error: parseError,
812-
message: agentResult.message,
813-
})
814-
815-
if (
816-
outputSchema &&
817-
typeof outputSchema === 'object' &&
818-
outputSchema !== null &&
819-
stagehand
820-
) {
821-
try {
822-
logger.info('Attempting to extract structured data using Stagehand extract')
823-
const schemaObj = getSchemaObject(outputSchema)
824-
const zodSchema = ensureZodObject(logger, schemaObj)
825-
826-
structuredOutput = await stagehand.extract(
827-
'Extract the requested information from this page according to the schema',
828-
zodSchema
829-
)
830-
831-
logger.info('Successfully extracted structured data as fallback', {
832-
keys: structuredOutput ? Object.keys(structuredOutput) : [],
833-
})
834-
} catch (extractError) {
835-
logger.error('Fallback extraction also failed', { error: extractError })
820+
if (hasOutputSchema) {
821+
logger.warn('Failed to parse JSON from agent message, attempting fallback extraction', {
822+
error: parseError,
823+
})
824+
825+
if (stagehand) {
826+
try {
827+
logger.info('Attempting to extract structured data using Stagehand extract')
828+
const schemaObj = getSchemaObject(outputSchema)
829+
const zodSchema = ensureZodObject(logger, schemaObj)
830+
831+
structuredOutput = await stagehand.extract(
832+
'Extract the requested information from this page according to the schema',
833+
zodSchema
834+
)
835+
836+
logger.info('Successfully extracted structured data as fallback', {
837+
keys: structuredOutput ? Object.keys(structuredOutput) : [],
838+
})
839+
} catch (extractError) {
840+
logger.error('Fallback extraction also failed', { error: extractError })
841+
}
836842
}
843+
} else {
844+
logger.info('Agent returned plain text response (no schema provided)')
837845
}
838846
}
839847
}

apps/sim/app/api/tools/stagehand/extract/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function POST(request: NextRequest) {
8686
verbose: 1,
8787
logger: (msg) => logger.info(typeof msg === 'string' ? msg : JSON.stringify(msg)),
8888
model: {
89-
modelName: 'gpt-4o',
89+
modelName: 'openai/gpt-4o',
9090
apiKey: apiKey,
9191
},
9292
})

apps/sim/blocks/blocks/browser_use.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,23 @@ export const BrowserUseBlock: BlockConfig<BrowserUseResponse> = {
3232
title: 'Model',
3333
type: 'dropdown',
3434
options: [
35-
{ label: 'gpt-4o', id: 'gpt-4o' },
36-
{ label: 'gemini-2.0-flash', id: 'gemini-2.0-flash' },
37-
{ label: 'gemini-2.0-flash-lite', id: 'gemini-2.0-flash-lite' },
38-
{ label: 'claude-3-7-sonnet-20250219', id: 'claude-3-7-sonnet-20250219' },
39-
{ label: 'llama-4-maverick-17b-128e-instruct', id: 'llama-4-maverick-17b-128e-instruct' },
35+
{ label: 'Browser Use LLM', id: 'browser-use-llm' },
36+
{ label: 'GPT-4o', id: 'gpt-4o' },
37+
{ label: 'GPT-4o Mini', id: 'gpt-4o-mini' },
38+
{ label: 'GPT-4.1', id: 'gpt-4.1' },
39+
{ label: 'GPT-4.1 Mini', id: 'gpt-4.1-mini' },
40+
{ label: 'O3', id: 'o3' },
41+
{ label: 'O4 Mini', id: 'o4-mini' },
42+
{ label: 'Gemini 2.5 Flash', id: 'gemini-2.5-flash' },
43+
{ label: 'Gemini 2.5 Pro', id: 'gemini-2.5-pro' },
44+
{ label: 'Gemini 3 Pro Preview', id: 'gemini-3-pro-preview' },
45+
{ label: 'Gemini Flash Latest', id: 'gemini-flash-latest' },
46+
{ label: 'Gemini Flash Lite Latest', id: 'gemini-flash-lite-latest' },
47+
{ label: 'Claude 3.7 Sonnet', id: 'claude-3-7-sonnet-20250219' },
48+
{ label: 'Claude Sonnet 4', id: 'claude-sonnet-4-20250514' },
49+
{ label: 'Claude Sonnet 4.5', id: 'claude-sonnet-4-5-20250929' },
50+
{ label: 'Claude Opus 4.5', id: 'claude-opus-4-5-20251101' },
51+
{ label: 'Llama 4 Maverick', id: 'llama-4-maverick-17b-128e-instruct' },
4052
],
4153
},
4254
{

apps/sim/next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const nextConfig: NextConfig = {
7979
'pino',
8080
'pino-pretty',
8181
'thread-stream',
82+
'@browserbasehq/stagehand',
8283
],
8384
experimental: {
8485
optimizeCss: true,

apps/sim/socket-server/handlers/subblocks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ async function flushSubblockUpdate(
195195
sock.emit('operation-confirmed', { operationId: opId, serverTimestamp: Date.now() })
196196
}
197197
})
198-
199-
logger.debug(`Flushed subblock update ${workflowId}: ${blockId}.${subblockId}`)
200198
} else {
201199
pending.opToSocket.forEach((socketId, opId) => {
202200
const sock = (roomManager as any).io?.sockets?.sockets?.get(socketId)

0 commit comments

Comments
 (0)