Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions apps/sim/app/api/tools/stagehand/agent/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export async function POST(request: NextRequest) {
verbose: 1,
logger: (msg) => logger.info(typeof msg === 'string' ? msg : JSON.stringify(msg)),
model: {
modelName: 'claude-sonnet-4-20250514',
modelName: 'anthropic/claude-3-7-sonnet-latest',
apiKey: apiKey,
},
})
Expand Down Expand Up @@ -704,7 +704,14 @@ The system will substitute actual values when these placeholders are used, keepi
`.trim()

const agent = stagehand.agent({
model: 'anthropic/claude-sonnet-4-20250514',
model: {
modelName: 'anthropic/claude-3-7-sonnet-latest',
apiKey: apiKey,
},
executionModel: {
modelName: 'anthropic/claude-3-7-sonnet-latest',
apiKey: apiKey,
},
systemPrompt: `${agentInstructions}\n\n${additionalContext}`,
})

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

let structuredOutput = null
const hasOutputSchema =
outputSchema && typeof outputSchema === 'object' && outputSchema !== null

if (agentResult.message) {
try {
let jsonContent = agentResult.message
Expand All @@ -807,33 +817,31 @@ The system will substitute actual values when these placeholders are used, keepi
structuredOutput = JSON.parse(jsonContent)
logger.info('Successfully parsed structured output from agent response')
} catch (parseError) {
logger.error('Failed to parse JSON from agent message', {
error: parseError,
message: agentResult.message,
})

if (
outputSchema &&
typeof outputSchema === 'object' &&
outputSchema !== null &&
stagehand
) {
try {
logger.info('Attempting to extract structured data using Stagehand extract')
const schemaObj = getSchemaObject(outputSchema)
const zodSchema = ensureZodObject(logger, schemaObj)

structuredOutput = await stagehand.extract(
'Extract the requested information from this page according to the schema',
zodSchema
)

logger.info('Successfully extracted structured data as fallback', {
keys: structuredOutput ? Object.keys(structuredOutput) : [],
})
} catch (extractError) {
logger.error('Fallback extraction also failed', { error: extractError })
if (hasOutputSchema) {
logger.warn('Failed to parse JSON from agent message, attempting fallback extraction', {
error: parseError,
})

if (stagehand) {
try {
logger.info('Attempting to extract structured data using Stagehand extract')
const schemaObj = getSchemaObject(outputSchema)
const zodSchema = ensureZodObject(logger, schemaObj)

structuredOutput = await stagehand.extract(
'Extract the requested information from this page according to the schema',
zodSchema
)

logger.info('Successfully extracted structured data as fallback', {
keys: structuredOutput ? Object.keys(structuredOutput) : [],
})
} catch (extractError) {
logger.error('Fallback extraction also failed', { error: extractError })
}
}
} else {
logger.info('Agent returned plain text response (no schema provided)')
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/tools/stagehand/extract/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function POST(request: NextRequest) {
verbose: 1,
logger: (msg) => logger.info(typeof msg === 'string' ? msg : JSON.stringify(msg)),
model: {
modelName: 'gpt-4o',
modelName: 'openai/gpt-4o',
apiKey: apiKey,
},
})
Expand Down
22 changes: 17 additions & 5 deletions apps/sim/blocks/blocks/browser_use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ export const BrowserUseBlock: BlockConfig<BrowserUseResponse> = {
title: 'Model',
type: 'dropdown',
options: [
{ label: 'gpt-4o', id: 'gpt-4o' },
{ label: 'gemini-2.0-flash', id: 'gemini-2.0-flash' },
{ label: 'gemini-2.0-flash-lite', id: 'gemini-2.0-flash-lite' },
{ label: 'claude-3-7-sonnet-20250219', id: 'claude-3-7-sonnet-20250219' },
{ label: 'llama-4-maverick-17b-128e-instruct', id: 'llama-4-maverick-17b-128e-instruct' },
{ label: 'Browser Use LLM', id: 'browser-use-llm' },
{ label: 'GPT-4o', id: 'gpt-4o' },
{ label: 'GPT-4o Mini', id: 'gpt-4o-mini' },
{ label: 'GPT-4.1', id: 'gpt-4.1' },
{ label: 'GPT-4.1 Mini', id: 'gpt-4.1-mini' },
{ label: 'O3', id: 'o3' },
{ label: 'O4 Mini', id: 'o4-mini' },
{ label: 'Gemini 2.5 Flash', id: 'gemini-2.5-flash' },
{ label: 'Gemini 2.5 Pro', id: 'gemini-2.5-pro' },
{ label: 'Gemini 3 Pro Preview', id: 'gemini-3-pro-preview' },
{ label: 'Gemini Flash Latest', id: 'gemini-flash-latest' },
{ label: 'Gemini Flash Lite Latest', id: 'gemini-flash-lite-latest' },
{ label: 'Claude 3.7 Sonnet', id: 'claude-3-7-sonnet-20250219' },
{ label: 'Claude Sonnet 4', id: 'claude-sonnet-4-20250514' },
{ label: 'Claude Sonnet 4.5', id: 'claude-sonnet-4-5-20250929' },
{ label: 'Claude Opus 4.5', id: 'claude-opus-4-5-20251101' },
{ label: 'Llama 4 Maverick', id: 'llama-4-maverick-17b-128e-instruct' },
],
},
{
Expand Down
1 change: 1 addition & 0 deletions apps/sim/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const nextConfig: NextConfig = {
'pino',
'pino-pretty',
'thread-stream',
'@browserbasehq/stagehand',
],
experimental: {
optimizeCss: true,
Expand Down
2 changes: 0 additions & 2 deletions apps/sim/socket-server/handlers/subblocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ async function flushSubblockUpdate(
sock.emit('operation-confirmed', { operationId: opId, serverTimestamp: Date.now() })
}
})

logger.debug(`Flushed subblock update ${workflowId}: ${blockId}.${subblockId}`)
} else {
pending.opToSocket.forEach((socketId, opId) => {
const sock = (roomManager as any).io?.sockets?.sockets?.get(socketId)
Expand Down