Agent Zero AI framework
browser-use upgrade patch test
frdel439f2216ffc4
diff --git a/models.py b/models.pyindex 9fe322eae..a02d3d0ae 100644--- a/models.py+++ b/models.py@@ -435,6 +435,52 @@ class BrowserCompatibleChatWrapper(ChatOpenRouter):def get_client(self, *args, **kwargs): # type: ignorereturn AsyncAIChatReplacement(self, *args, **kwargs)+ # -- Gemini helper -----------------------------------------+ def _gemini_clean_and_conform(self, text: str):+ obj = None+ try:+ # dirty_json parser is robust enough to handle markdown fences+ obj = dirty_json.parse(text)+ except Exception:+ return None # return None if parsing fails++ if not isinstance(obj, dict):+ return None++ # Conform actions to browser-use expectations+ if isinstance(obj.get("action"), list):+ normalized_actions = []+ for item in obj["action"]:+ if not isinstance(item, dict):+ continue # Skip non-dict items++ action_key, action_value = next(iter(item.items()), (None, None))+ if not action_key:+ continue++ # Create a mutable copy of the value+ v = (action_value or {}).copy()++ if action_key in ("scroll_down", "scroll_up", "scroll"):+ is_down = action_key != "scroll_up"+ v.setdefault("down", is_down)+ v.setdefault("num_pages", 1.0)+ normalized_actions.append({"scroll": v})+ elif action_key == "go_to_url":+ v.setdefault("new_tab", False)+ normalized_actions.append({action_key: v})+ elif action_key == "done":+ if "text" in v and "data" not in v:+ t = v.pop("text", "")+ v["data"] = {"title": "Task result", "response": t, "page_summary": t}+ v.setdefault("success", True)+ normalized_actions.append({action_key: v})+ else:+ normalized_actions.append(item)+ obj["action"] = normalized_actions++ return dirty_json.stringify(obj)+async def _acall(self,messages: List[BaseMessage],@@ -450,7 +496,7 @@ class BrowserCompatibleChatWrapper(ChatOpenRouter):model = kwargs.pop("model", None)kwrgs = {**self._wrapper.kwargs, **kwargs}- # hack from browser-use to fix json schema for gemini+ # hack from browser-use to fix json schema for gemini (additionalProperties, $defs, $ref)if "response_format" in kwrgs and "json_schema" in kwrgs["response_format"] and model.startswith("gemini/"):kwrgs["response_format"]["json_schema"] = ChatGoogle("")._fix_gemini_schema(self._wrapper.kwargs)@@ -460,6 +506,17 @@ class BrowserCompatibleChatWrapper(ChatOpenRouter):stop=stop,**kwrgs,)++ # Gemini: strip triple backticks and conform schema+ try:+ msg = resp.choices[0].message # type: ignore+ if self.provider == "gemini" and isinstance(getattr(msg, "content", None), str):+ cleaned = self._gemini_clean_and_conform(msg.content) # type: ignore+ if cleaned:+ msg.content = cleaned+ except Exception:+ pass+except Exception as e:raise ediff --git a/python/tools/browser_agent.py b/python/tools/browser_agent.pyindex d040c9aa1..763c31197 100644--- a/python/tools/browser_agent.py+++ b/python/tools/browser_agent.py@@ -32,6 +32,16 @@ class State:def __del__(self):self.kill_task()+ files.delete_dir(self.get_user_data_dir()) # cleanup user data dir++ def get_user_data_dir(self):+ return str(+ Path.home()+ / ".config"+ / "browseruse"+ / "profiles"+ / f"agent_{self.agent.context.id}"+ )async def _initialize(self):if self.browser_session:@@ -46,7 +56,6 @@ class State:disable_security=True,chromium_sandbox=False,accept_downloads=True,- downloads_dir=files.get_abs_path("tmp/downloads"),downloads_path=files.get_abs_path("tmp/downloads"),allowed_domains=["*"],executable_path=pw_binary,@@ -54,17 +63,12 @@ class State:minimum_wait_page_load_time=1.0,wait_for_network_idle_page_load_time=2.0,maximum_wait_page_load_time=10.0,+ window_size={"width": 1024, "height": 2048},screen={"width": 1024, "height": 2048},viewport={"width": 1024, "height": 2048},args=["--headless=new"],# Use a unique user data directory to avoid conflicts- user_data_dir=str(- Path.home()- / ".config"- / "browseruse"- / "profiles"- / f"agent_{self.agent.context.id}"- ),+ user_data_dir=self.get_user_data_dir(),extra_http_headers=self.agent.config.browser_http_headers or {},))