Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(browser): let Reset finish when a Browser AI Agent has no single Browser tool
trohitgaf7eb44a253a
diff --git a/server/nodes/agent/browser_agent/__init__.py b/server/nodes/agent/browser_agent/__init__.pyindex 25cc3847..dae5e26e 100644--- a/server/nodes/agent/browser_agent/__init__.py+++ b/server/nodes/agent/browser_agent/__init__.py@@ -3,7 +3,7 @@ from typing import Any, Optionalfrom pydantic import Field-from services.browser_agent_recipe import BROWSER_AGENT_ROLE, browser_tool_id+from services.browser_agent_recipe import BROWSER_AGENT_ROLE, browser_tool_id, connected_browser_toolsfrom services.plugin import NodeContext, Operationfrom .._specialized import SpecializedAgentBase, SpecializedAgentParams@@ -48,9 +48,12 @@ class BrowserAgentNode(SpecializedAgentBase):generation: int, graph: dict, database: Any) -> dict:from services.browser_owners import routing_for_node, cleanup_browser_task- if not execution_id:+ # Without exactly one Browser tool execute_op refused before claiming,+ # so there is nothing to release and Reset must not fail on the graph.+ tools = connected_browser_tools(graph, node_id)+ if not execution_id or len(tools) != 1:return {"reset": False}- tool = browser_tool_id(graph, node_id)+ tool = next(iter(tools))principal = str(graph.get("owner_id") or "owner")binding = await routing_for_node(database, workflow_id, tool, principal)return await cleanup_browser_task(database, binding, f"{execution_id}:{node_id}")diff --git a/server/services/browser_agent_recipe.py b/server/services/browser_agent_recipe.pyindex dfd79add..83ad3f35 100644--- a/server/services/browser_agent_recipe.py+++ b/server/services/browser_agent_recipe.py@@ -17,11 +17,15 @@ BROWSER_AGENT_ROLE = ()-def browser_tool_id(graph: Mapping[str, Any], agent_id: str) -> str:+def connected_browser_tools(graph: Mapping[str, Any], agent_id: str) -> set[str]:nodes = {node["id"]: node for node in graph.get("nodes", []) if node.get("id")}- tools = {edge.get("source") for edge in graph.get("edges", [])- if edge.get("target") == agent_id and edge.get("targetHandle") == "input-tools"- and nodes.get(edge.get("source"), {}).get("type") == "browser"}+ return {edge.get("source") for edge in graph.get("edges", [])+ if edge.get("target") == agent_id and edge.get("targetHandle") == "input-tools"+ and nodes.get(edge.get("source"), {}).get("type") == "browser"}+++def browser_tool_id(graph: Mapping[str, Any], agent_id: str) -> str:+ tools = connected_browser_tools(graph, agent_id)if len(tools) != 1:raise NodeUserError("Browser AI Agent needs exactly one connected, saved Browser tool.")return str(next(iter(tools)))diff --git a/server/tests/nodes/browser/test_browser_owners.py b/server/tests/nodes/browser/test_browser_owners.pyindex 7bd557d5..f28e3575 100644--- a/server/tests/nodes/browser/test_browser_owners.py+++ b/server/tests/nodes/browser/test_browser_owners.py@@ -407,6 +407,18 @@ async def test_inprocess_delegated_claim_survives_stale_reset_and_cleans_up_withawait child[email protected]("browsers", [[], ["browser", "browser-2"]])+async def test_reset_of_browser_agent_without_exactly_one_browser_tool_is_a_noop(database, browsers):+ from nodes.agent.browser_agent import BrowserAgentNode++ db, _ = database+ graph = {"owner_id": "owner",+ "nodes": [{"id": "agent", "type": "browser_agent"}, *({"id": b, "type": "browser"} for b in browsers)],+ "edges": [{"source": b, "target": "agent", "targetHandle": "input-tools"} for b in browsers]}+ assert await BrowserAgentNode.reset_execution_state(node_id="agent", workflow_id="wf",+ execution_id="2:execution:5", generation=5, graph=graph, database=db) == {"reset": False}++async def test_ambiguous_active_browser_bindings_fail_closed(database):db, _ = databasedb.get_node_parameters = AsyncMock(return_value={})