Skip to content

Commit e038f5e

Browse files
committed
refactor: improve browser session management in admin control
- Updated the admin control function to discard browser-use agents and overlays while retaining the browser window for user inspection. - Enhanced error handling during cleanup of browser-use agents and sessions. - Removed unnecessary dependency on `get_agent_extra_body` in the BrowserUseAdapter class, streamlining the configuration process.
1 parent b67232e commit e038f5e

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

agent_server.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,18 @@ async def admin_control(payload: Dict[str, Any]):
13501350
await Modules.computer_use_queue.get()
13511351
except Exception:
13521352
pass
1353-
# Close active browser-use sessions so the browser agent stops
1353+
# Discard browser-use agents/overlay but keep the browser window for user inspection
13541354
try:
13551355
if Modules.browser_use:
1356-
await Modules.browser_use._close_browser()
1356+
Modules.browser_use._stop_overlay()
1357+
Modules.browser_use._agents.clear()
1358+
try:
1359+
if Modules.browser_use._browser_session is not None:
1360+
await Modules.browser_use._remove_overlay(Modules.browser_use._browser_session)
1361+
except Exception:
1362+
pass
13571363
except Exception as e:
1358-
logger.warning(f"[Agent] Error closing browser-use session during end_all: {e}")
1364+
logger.warning(f"[Agent] Error cleaning browser-use agents during end_all: {e}")
13591365
# Reset computer-use step history so stale context is cleared
13601366
try:
13611367
if Modules.computer_use:

brain/browser_use_adapter.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pathlib import Path
77
from typing import Any, Dict, List, Optional
88

9-
from config import get_agent_extra_body
109
from utils.config_manager import get_config_manager
1110

1211
logger = logging.getLogger(__name__)
@@ -310,7 +309,6 @@ def _build_llm(self, mode: str = "schema") -> Any:
310309
api_cfg = self._config_manager.get_model_api_config("agent")
311310
base_url = api_cfg.get("base_url", "") or ""
312311
model = api_cfg.get("model", "") or ""
313-
extra_body = get_agent_extra_body(model)
314312
kwargs: Dict[str, Any] = dict(
315313
model=model,
316314
api_key=api_cfg.get("api_key"),
@@ -321,8 +319,6 @@ def _build_llm(self, mode: str = "schema") -> Any:
321319
remove_min_items_from_schema=False,
322320
remove_defaults_from_schema=False,
323321
)
324-
if extra_body:
325-
kwargs["extra_body"] = extra_body
326322
if mode == "text":
327323
kwargs["dont_force_structured_output"] = True
328324
kwargs["add_schema_to_system_prompt"] = True

0 commit comments

Comments
 (0)