MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / ScriptBrowserEnv

Class ScriptBrowserEnv

eval_heldout/webarena/browser_env/envs.py:67–278  ·  view source on GitHub ↗

The goal of this environment is to produce a prototype of a browser environment. In the end, we want to support a fully configurable browser environment with wide range of action spaces and observation spaces, both structured and unstructured. But in this prototype, we just support

Source from the content-addressed store, hash-verified

65
66
67class ScriptBrowserEnv(Env[dict[str, Observation], Action]):
68 """
69 The goal of this environment is to produce a prototype of a browser environment.
70 In the end, we want to support a fully configurable browser environment with wide
71 range of action spaces and observation spaces, both structured and unstructured.
72 But in this prototype, we just support action space specified by Playwright script,
73 and observation space is the html content of the page.
74 """
75
76 @beartype
77 def __init__(
78 self,
79 max_page_length: int = 8192,
80 headless: bool = True,
81 slow_mo: int = 0,
82 observation_type: str = "html",
83 current_viewport_only: bool = False,
84 viewport_size: ViewportSize = {"width": 1280, "height": 720},
85 save_trace_enabled: bool = False,
86 sleep_after_execution: float = 0.0,
87 ):
88 # TODO: make Space[Action] = ActionSpace
89 self.action_space = get_action_space() # type: ignore[assignment]
90 self.headless = headless
91 self.slow_mo = slow_mo
92 self.current_viewport_only = current_viewport_only
93 self.reset_finished = False
94 self.viewport_size = viewport_size
95 self.save_trace_enabled = save_trace_enabled
96 self.sleep_after_execution = sleep_after_execution
97
98 match observation_type:
99 case "html" | "accessibility_tree":
100 self.text_observation_type = observation_type
101 self.image_observation_type = ""
102 self.main_observation_type = "text"
103 case "image":
104 self.image_observation_type = observation_type
105 self.text_observation_type = "" # type: ignore[assignment]
106 self.main_observation_type = "image"
107 case _:
108 raise ValueError(
109 f"Unsupported observation type: {observation_type}"
110 )
111
112 self.observation_handler = ObservationHandler(
113 self.main_observation_type,
114 self.text_observation_type,
115 self.image_observation_type,
116 self.current_viewport_only,
117 self.viewport_size,
118 )
119
120 self.observation_space = (
121 self.observation_handler.get_observation_space()
122 )
123
124 @beartype

Callers 1

testFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected