@@ -131,7 +131,7 @@ async def run_browser_agent(
131
131
if new_videos - existing_videos :
132
132
latest_video = list (new_videos - existing_videos )[0 ] # Get the first new video
133
133
134
- return final_result , errors , model_actions , model_thoughts , latest_video , trace_file
134
+ return final_result , errors , model_actions , model_thoughts , latest_video
135
135
136
136
async def run_org_agent (
137
137
llm ,
@@ -204,7 +204,7 @@ async def run_org_agent(
204
204
import traceback
205
205
traceback .print_exc ()
206
206
errors = str (e ) + "\n " + traceback .format_exc ()
207
- return '' , errors , '' , ''
207
+ return '' , errors , '' , '' , None , None
208
208
finally :
209
209
# Handle cleanup based on persistence configuration
210
210
if not keep_browser_open :
@@ -288,17 +288,16 @@ async def run_custom_agent(
288
288
errors = history .errors ()
289
289
model_actions = history .model_actions ()
290
290
model_thoughts = history .model_thoughts ()
291
+
291
292
recorded_files = get_latest_files (save_recording_path )
292
293
trace_file = get_latest_files (save_trace_path )
293
294
295
+ return final_result , errors , model_actions , model_thoughts , trace_file .get ('.webm' ), recorded_files .get ('.zip' )
294
296
except Exception as e :
295
297
import traceback
296
298
traceback .print_exc ()
297
299
errors = str (e ) + "\n " + traceback .format_exc ()
298
- model_actions = ""
299
- model_thoughts = ""
300
- recorded_files = {}
301
- trace_file = {}
300
+ return '' , errors , '' , '' , None , None
302
301
finally :
303
302
# Handle cleanup based on persistence configuration
304
303
if not keep_browser_open :
@@ -309,17 +308,16 @@ async def run_custom_agent(
309
308
if _global_browser :
310
309
await _global_browser .close ()
311
310
_global_browser = None
312
- return final_result , errors , model_actions , model_thoughts , trace_file .get ('.webm' ), recorded_files .get ('.zip' )
313
311
314
312
async def run_with_stream (
315
313
agent_type ,
316
314
llm_provider ,
317
- keep_browser_open ,
318
315
llm_model_name ,
319
316
llm_temperature ,
320
317
llm_base_url ,
321
318
llm_api_key ,
322
319
use_own_browser ,
320
+ keep_browser_open ,
323
321
headless ,
324
322
disable_security ,
325
323
window_w ,
@@ -335,7 +333,7 @@ async def run_with_stream(
335
333
tool_call_in_content
336
334
):
337
335
"""Wrapper to run the agent and handle streaming."""
338
- global _global_browser , _global_browser_context , _global_playwright
336
+ global _global_browser , _global_browser_context
339
337
340
338
try :
341
339
# Initialize the global browser if it doesn't exist
@@ -367,11 +365,11 @@ async def run_with_stream(
367
365
agent_type = agent_type ,
368
366
llm_provider = llm_provider ,
369
367
llm_model_name = llm_model_name ,
370
- keep_browser_open = keep_browser_open ,
371
368
llm_temperature = llm_temperature ,
372
369
llm_base_url = llm_base_url ,
373
370
llm_api_key = llm_api_key ,
374
371
use_own_browser = use_own_browser ,
372
+ keep_browser_open = keep_browser_open ,
375
373
headless = headless ,
376
374
disable_security = disable_security ,
377
375
window_w = window_w ,
@@ -385,8 +383,7 @@ async def run_with_stream(
385
383
use_vision = use_vision ,
386
384
max_actions_per_step = max_actions_per_step ,
387
385
tool_call_in_content = tool_call_in_content
388
- )
389
- )
386
+ ))
390
387
391
388
# Initialize values for streaming
392
389
html_content = "<div style='width:80vw; height:90vh'>Using browser...</div>"
@@ -396,10 +393,7 @@ async def run_with_stream(
396
393
# Periodically update the stream while the agent task is running
397
394
while not agent_task .done ():
398
395
try :
399
- if isinstance (_global_browser_context , CustomBrowserContext ):
400
- html_content = await capture_screenshot (_global_browser_context )
401
- else :
402
- html_content = "<div class='error' style='width:80vw; height:90vh'>Invalid browser context type</div>"
396
+ html_content = await capture_screenshot (_global_browser_context )
403
397
except Exception as e :
404
398
html_content = f"<div class='error' style='width:80vw; height:90vh'>Screenshot error: { str (e )} </div>"
405
399
0 commit comments