@@ -343,6 +343,7 @@ def __init__(
343343 enable_proxy : bool ,
344344 max_steps : int ,
345345 exp_dir : Path ,
346+ record_video : bool = True ,
346347 ):
347348 self .task = task
348349 self .env_info = {
@@ -375,13 +376,18 @@ def __init__(
375376 self ._step_count = 0
376377 self .max_steps = max_steps
377378 self .exp_dir = exp_dir
379+ self .record_video = record_video
378380
379381 def reset (self , seed : int | None = None ) -> tuple [dict [str , Any ], dict [str , Any ]]:
380382 self .env .reset (task_config = self .task , seed = seed )
381383 logging .info (f"Start solving task: { self .task ['instruction' ]} " )
382- time .sleep (60 ) # Wait for the environment to be ready, as in https://github.com/xlang-ai/OSWorld/blob/main/lib_run_single.py#L15
383- raw_obs = self .env ._get_obs () # Get the initial observation
384- self .env .controller .start_recording ()
384+ time .sleep (
385+ 60
386+ ) # Wait for the environment to be ready, as in https://github.com/xlang-ai/OSWorld/blob/main/lib_run_single.py#L15
387+ raw_obs = self .env ._get_obs () # Get the initial observation
388+ if self .record_video :
389+ self .env .controller .start_recording ()
390+ logging .info ("Started recording the environment video" )
385391 obs = self .to_agentlab_observation (raw_obs )
386392 self ._step_count = 0
387393 return obs , self .env_info
@@ -520,9 +526,10 @@ def parse_agentlab_action_str_to_func_args(action: str):
520526 return None , None , None
521527
522528 def close (self ):
523- video_name = str (self .exp_dir / "recording.mp4" )
524- self .env .controller .end_recording (video_name )
525- logger .info (f"Recorded video saved to { video_name } " )
529+ if self .record_video :
530+ video_name = str (self .exp_dir / "recording.mp4" )
531+ self .env .controller .end_recording (video_name )
532+ logger .info (f"Recorded video saved to { video_name } " )
526533 return self .env .close ()
527534
528535
@@ -671,10 +678,8 @@ def fix_settings_file_path_in_config(self, task) -> str:
671678 osworld_repo = os .getenv ("OSWORLD_REPO" , "OSWorld" )
672679 updated_task = deepcopy (task ) # Avoid modifying the original task
673680 for config in updated_task ["config" ]:
674- if config .get ("parameters" , False ) and config ["parameters" ].get (
675- "settings_file" , False
676- ):
677- config ["parameters" ]["settings_file" ] = os .path .join (
678- osworld_repo , config ["parameters" ]["settings_file" ]
679- )
681+ if config .get ("parameters" , False ) and config ["parameters" ].get ("settings_file" , False ):
682+ config ["parameters" ]["settings_file" ] = os .path .join (
683+ osworld_repo , config ["parameters" ]["settings_file" ]
684+ )
680685 return updated_task
0 commit comments