From 59040eee9ff0c0c9941eb85da36e29854b394dea Mon Sep 17 00:00:00 2001 From: STJ Date: Mon, 23 Mar 2026 16:09:46 -0700 Subject: [PATCH] feat: add feature flag for browser run tool additional refactors to pass precommit --- strix/config/config.py | 1 + strix/tools/__init__.py | 1 + strix/tools/browser/browser_actions.py | 47 ++++++++++++++------------ strix/tools/registry.py | 10 ++++++ uv.lock | 4 +-- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/strix/config/config.py b/strix/config/config.py index 782101dd..6fb1c101 100644 --- a/strix/config/config.py +++ b/strix/config/config.py @@ -38,6 +38,7 @@ class Config: # Tool & Feature Configuration perplexity_api_key = None strix_disable_browser = "false" + strix_enable_browser_agent = "false" # Runtime Configuration strix_image = "ghcr.io/usestrix/strix-sandbox:0.1.13" diff --git a/strix/tools/__init__.py b/strix/tools/__init__.py index 3c049560..9734699d 100644 --- a/strix/tools/__init__.py +++ b/strix/tools/__init__.py @@ -40,6 +40,7 @@ SANDBOX_MODE = os.getenv("STRIX_SANDBOX_MODE", "false").lower() == "true" HAS_PERPLEXITY_API = bool(Config.get("perplexity_api_key")) DISABLE_BROWSER = (Config.get("strix_disable_browser") or "false").lower() == "true" +ENABLE_BROWSER_AGENT = (Config.get("strix_enable_browser_agent") or "false").lower() == "true" if not SANDBOX_MODE: from .agents_graph import * # noqa: F403 diff --git a/strix/tools/browser/browser_actions.py b/strix/tools/browser/browser_actions.py index 7c0a9c1b..de8e06fc 100644 --- a/strix/tools/browser/browser_actions.py +++ b/strix/tools/browser/browser_actions.py @@ -295,41 +295,46 @@ async def browser_action( "ws_url": ws_url, "is_running": True, } - - return result - - if action == "close_browser": + elif action == "close_browser": await _close_session(agent_id) - return { + result = { "message": "Browser closed", "is_running": False, } + elif action == "run": + from strix.tools.registry import _is_browser_agent_enabled - session = _get_session(agent_id) - - if action == "run": - if not task: - return { + if not _is_browser_agent_enabled(): + result = { + "error": "The 'run' action (browser agent mode) is not enabled. " + "Set STRIX_ENABLE_BROWSER_AGENT=true to enable it. " + "Use granular browser actions instead.", + "is_running": False, + } + elif not task: + result = { "error": "task required for run action", "is_running": False, } - - runner = partial(_run_browser_agent, session, task, return_fields, metadata) - desc = task + else: + session = _get_session(agent_id) + runner = partial(_run_browser_agent, session, task, return_fields, metadata) + result = await _execute_task(session, runner, task) + if "error" not in result: + result = await populate_response(session, result) else: + session = _get_session(agent_id) runner = partial(_run_browser_tool, session, action, kwargs, metadata) desc = f"{action}({list(kwargs.keys())[:3]})" - - task_output = await _execute_task(session, runner, desc) - - if "error" in task_output: - return task_output - - return await populate_response(session, task_output) + result = await _execute_task(session, runner, desc) + if "error" not in result: + result = await populate_response(session, result) except Exception as error: logger.exception("browser_action error: %s", action) - return { + result = { "error": str(error), "is_running": False, } + + return result diff --git a/strix/tools/registry.py b/strix/tools/registry.py index 614197aa..09ea8563 100644 --- a/strix/tools/registry.py +++ b/strix/tools/registry.py @@ -163,6 +163,16 @@ def _is_browser_disabled() -> bool: return str(val).lower() == "true" +def _is_browser_agent_enabled() -> bool: + if os.getenv("STRIX_ENABLE_BROWSER_AGENT", "").lower() == "true": + return True + + from strix.config import Config + + val: str = Config.load().get("env", {}).get("STRIX_ENABLE_BROWSER_AGENT", "") + return str(val).lower() == "true" + + def _has_perplexity_api() -> bool: if os.getenv("PERPLEXITY_API_KEY"): return True diff --git a/uv.lock b/uv.lock index 2c100348..4e8666e8 100644 --- a/uv.lock +++ b/uv.lock @@ -8108,7 +8108,7 @@ wheels = [ [[package]] name = "strix-agent" -version = "0.8.2" +version = "0.8.3" source = { editable = "." } dependencies = [ { name = "browser-use" }, @@ -8182,7 +8182,7 @@ requires-dist = [ { name = "rich" }, { name = "scrubadub", specifier = ">=2.0.1" }, { name = "tenacity", specifier = ">=9.0.0" }, - { name = "textual", specifier = ">=4.0.0" }, + { name = "textual", specifier = ">=6.0.0" }, { name = "traceloop-sdk", specifier = ">=0.53.0" }, { name = "uvicorn", marker = "extra == 'sandbox'" }, { name = "xmltodict", specifier = ">=0.13.0" },