diff --git a/package.json b/package.json index d9591631..5e593367 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "homepage": "https://github.com/NousResearch/Hermes-Agent#readme", "dependencies": { - "agent-browser": "^0.7.6" + "agent-browser": "^0.13.0" }, "engines": { "node": ">=18.0.0" diff --git a/tools/browser_tool.py b/tools/browser_tool.py index 2814f3bb..e0048f3a 100644 --- a/tools/browser_tool.py +++ b/tools/browser_tool.py @@ -642,11 +642,39 @@ def _get_browserbase_config() -> Dict[str, str]: } +_stale_daemons_cleaned = False + +def _kill_stale_agent_browser_daemons(): + """Kill any orphaned agent-browser daemon processes from previous runs.""" + global _stale_daemons_cleaned + if _stale_daemons_cleaned: + return + _stale_daemons_cleaned = True + + try: + result = subprocess.run( + ["pgrep", "-f", "agent-browser.*daemon"], + capture_output=True, text=True, timeout=5 + ) + pids = result.stdout.strip().split() + if pids and pids[0]: + for pid in pids: + try: + os.kill(int(pid), signal.SIGTERM) + except (ProcessLookupError, ValueError, PermissionError): + pass + if not os.getenv("HERMES_QUIET"): + print(f"[browser_tool] Cleaned up {len(pids)} stale daemon process(es)", file=sys.stderr) + except Exception: + pass + + def _find_agent_browser() -> str: """ Find the agent-browser CLI executable. Checks in order: PATH, local node_modules/.bin/, npx fallback. + Also kills any stale daemon processes from prior runs on first call. Returns: Path to agent-browser executable @@ -654,6 +682,8 @@ def _find_agent_browser() -> str: Raises: FileNotFoundError: If agent-browser is not installed """ + _kill_stale_agent_browser_daemons() + # Check if it's in PATH (global install) which_result = shutil.which("agent-browser") if which_result: