@@ -45,6 +45,7 @@ export class V3AgentHandler {
4545 private executionModel ?: string ;
4646 private systemInstructions ?: string ;
4747 private mcpTools ?: ToolSet ;
48+ private mode : AgentToolMode ;
4849
4950 constructor (
5051 v3 : V3 ,
@@ -53,18 +54,19 @@ export class V3AgentHandler {
5354 executionModel ?: string ,
5455 systemInstructions ?: string ,
5556 mcpTools ?: ToolSet ,
57+ mode ?: AgentToolMode ,
5658 ) {
5759 this . v3 = v3 ;
5860 this . logger = logger ;
5961 this . llmClient = llmClient ;
6062 this . executionModel = executionModel ;
6163 this . systemInstructions = systemInstructions ;
6264 this . mcpTools = mcpTools ;
65+ this . mode = mode ?? "dom" ;
6366 }
6467
6568 private async prepareAgent (
6669 instructionOrOptions : string | AgentExecuteOptionsBase ,
67- effectiveMode ?: AgentToolMode ,
6870 ) : Promise < AgentContext > {
6971 try {
7072 const options =
@@ -74,22 +76,19 @@ export class V3AgentHandler {
7476
7577 const maxSteps = options . maxSteps || 20 ;
7678
77- // Use effective mode passed from execute/stream, default to "dom"
78- const mode = effectiveMode ?? "dom" ;
79-
8079 // Get the initial page URL first (needed for the system prompt)
8180 const initialPageUrl = ( await this . v3 . context . awaitActivePage ( ) ) . url ( ) ;
8281
8382 // Build the system prompt with mode-aware tool guidance
8483 const systemPrompt = buildAgentSystemPrompt ( {
8584 url : initialPageUrl ,
8685 executionInstruction : options . instruction ,
87- mode,
86+ mode : this . mode ,
8887 systemInstructions : this . systemInstructions ,
8988 isBrowserbase : this . v3 . isBrowserbase ,
9089 } ) ;
9190
92- const tools = this . createTools ( mode ) ;
91+ const tools = this . createTools ( ) ;
9392 const allTools : ToolSet = { ...tools , ...this . mcpTools } ;
9493
9594 // Use provided messages for continuation, or start fresh with the instruction
@@ -212,12 +211,9 @@ export class V3AgentHandler {
212211 typeof instructionOrOptions === "object" ? instructionOrOptions : null ;
213212 const signal = options ?. signal ;
214213
215- // Determine effective mode from execute options, default to "dom"
216- const effectiveMode = options ?. mode ?? "dom" ;
217-
218214 // Highlight cursor defaults to true for hybrid mode, can be overridden
219215 const shouldHighlightCursor =
220- options ?. highlightCursor ?? effectiveMode === "hybrid" ;
216+ options ?. highlightCursor ?? this . mode === "hybrid" ;
221217
222218 const state : AgentState = {
223219 collectedReasoning : [ ] ,
@@ -238,10 +234,10 @@ export class V3AgentHandler {
238234 messages : preparedMessages ,
239235 wrappedModel,
240236 initialPageUrl,
241- } = await this . prepareAgent ( instructionOrOptions , effectiveMode ) ;
237+ } = await this . prepareAgent ( instructionOrOptions ) ;
242238
243239 // Enable cursor overlay for hybrid mode (coordinate-based interactions)
244- if ( shouldHighlightCursor && effectiveMode === "hybrid" ) {
240+ if ( shouldHighlightCursor && this . mode === "hybrid" ) {
245241 const page = await this . v3 . context . awaitActivePage ( ) ;
246242 await page . enableCursorOverlay ( ) . catch ( ( ) => { } ) ;
247243 }
@@ -321,12 +317,9 @@ export class V3AgentHandler {
321317 const streamOptions =
322318 typeof instructionOrOptions === "object" ? instructionOrOptions : null ;
323319
324- // Determine effective mode from stream options, default to "dom"
325- const effectiveMode = streamOptions ?. mode ?? "dom" ;
326-
327320 // Highlight cursor defaults to true for hybrid mode, can be overridden
328321 const shouldHighlightCursor =
329- streamOptions ?. highlightCursor ?? effectiveMode === "hybrid" ;
322+ streamOptions ?. highlightCursor ?? this . mode === "hybrid" ;
330323
331324 const {
332325 options,
@@ -336,10 +329,10 @@ export class V3AgentHandler {
336329 messages,
337330 wrappedModel,
338331 initialPageUrl,
339- } = await this . prepareAgent ( instructionOrOptions , effectiveMode ) ;
332+ } = await this . prepareAgent ( instructionOrOptions ) ;
340333
341334 // Enable cursor overlay for hybrid mode (coordinate-based interactions)
342- if ( shouldHighlightCursor && effectiveMode === "hybrid" ) {
335+ if ( shouldHighlightCursor && this . mode === "hybrid" ) {
343336 const page = await this . v3 . context . awaitActivePage ( ) ;
344337 await page . enableCursorOverlay ( ) . catch ( ( ) => { } ) ;
345338 }
@@ -474,12 +467,12 @@ export class V3AgentHandler {
474467 } ;
475468 }
476469
477- private createTools ( mode ?: AgentToolMode ) {
470+ private createTools ( ) {
478471 const provider = this . llmClient ?. getLanguageModel ?.( ) ?. provider ;
479472 return createAgentTools ( this . v3 , {
480473 executionModel : this . executionModel ,
481474 logger : this . logger ,
482- mode : mode ?? "dom" ,
475+ mode : this . mode ,
483476 provider,
484477 } ) ;
485478 }
0 commit comments