Skip to content

Commit

Permalink
save browser traces per task
Browse files Browse the repository at this point in the history
  • Loading branch information
ollmer committed Jan 6, 2025
1 parent b89c4d7 commit 7fccda1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tapeagents/tools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class Browser(Multitool):
_traces_dir: str | None = None
_record_video_dir: str | None = None
_screenshots_dir: str | None = None
_task_id: str = ""

def model_post_init(self, __context: Any):
self._current_page = ""
Expand Down Expand Up @@ -231,6 +232,7 @@ def execute_action(self, action: Action) -> PageObservation:
raise ValueError(f"Unknown action: {action_type}")

def start_task(self, task_id: str, seed: int = 1, **kwargs) -> dict:
self._task_id = task_id
self._env = gym.make(
task_id,
headless=self.headless,
Expand All @@ -253,8 +255,9 @@ def start_task(self, task_id: str, seed: int = 1, **kwargs) -> dict:
sleep(self.page_load_time_sec) # wait for the page to load
return info

def close(self, task_name: str):
self._env.context.tracing.stop(path=os.path.join(self._traces_dir, f"{task_name}.zip"))
def close(self):
assert self._traces_dir is not None
self._env.context.tracing.stop(path=os.path.join(self._traces_dir, f"{self._task_id}.zip"))
self._env.close()

def _screenshot_to_img_file(self, image) -> str:
Expand Down

0 comments on commit 7fccda1

Please sign in to comment.