Skip to content

Self-improving AI Employees for everyone

feat(validator): let a plugin state the wiring its node needs

trohitg40e383c69f70
diff --git a/server/nodes/agent/browser_agent/__init__.py b/server/nodes/agent/browser_agent/__init__.py
index dae5e26e..4b3d1f7f 100644
--- a/server/nodes/agent/browser_agent/__init__.py
+++ b/server/nodes/agent/browser_agent/__init__.py
@@ -3,7 +3,9 @@ from typing import Any, Optional
from pydantic import Field
-from services.browser_agent_recipe import BROWSER_AGENT_ROLE, browser_tool_id, connected_browser_tools
+from services.browser_agent_recipe import (
+ BROWSER_AGENT_ROLE, BROWSER_TOOL_REQUIRED, browser_tool_id, connected_browser_tools,
+)
from services.plugin import NodeContext, Operation
from .._specialized import SpecializedAgentBase, SpecializedAgentParams
@@ -43,6 +45,12 @@ class BrowserAgentNode(SpecializedAgentBase):
finally:
await cleanup_browser_task(database, binding, task_id)
+ @classmethod
+ def validate_graph(cls, node_id: str, graph: dict) -> list[dict]:
+ if len(connected_browser_tools(graph, node_id)) == 1:
+ return []
+ return [{"code": "BROWSER_TOOL_REQUIRED", "node_id": node_id, "message": BROWSER_TOOL_REQUIRED}]
+
@classmethod
async def reset_execution_state(cls, *, node_id: str, workflow_id: str, execution_id: str,
generation: int, graph: dict, database: Any) -> dict:
diff --git a/server/services/browser_agent_recipe.py b/server/services/browser_agent_recipe.py
index 83ad3f35..d8b6b835 100644
--- a/server/services/browser_agent_recipe.py
+++ b/server/services/browser_agent_recipe.py
@@ -17,6 +17,9 @@ BROWSER_AGENT_ROLE = (
)
+BROWSER_TOOL_REQUIRED = "Browser AI Agent needs exactly one connected, saved Browser tool."
+
+
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")}
return {edge.get("source") for edge in graph.get("edges", [])
@@ -27,7 +30,7 @@ def connected_browser_tools(graph: Mapping[str, Any], agent_id: str) -> set[str]
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.")
+ raise NodeUserError(BROWSER_TOOL_REQUIRED)
return str(next(iter(tools)))
diff --git a/server/services/plugin/base.py b/server/services/plugin/base.py
index 3e6e289a..423cc785 100644
--- a/server/services/plugin/base.py
+++ b/server/services/plugin/base.py
@@ -236,6 +236,13 @@ class BaseNode:
) -> Dict[str, Any]:
return {"reset": False}
+ # Wiring this node needs to run, checked before Start and import
+ # (services/workflow_validator.py). Returns validator errors,
+ # ``{"code", "node_id", "message"}``; none by default.
+ @classmethod
+ def validate_graph(cls, node_id: str, graph: Dict[str, Any]) -> Sequence[Dict[str, Any]]:
+ return ()
+
# ---- declaration (override in subclass) -------------------------------
type: ClassVar[str] = ""
version: ClassVar[int] = 1
diff --git a/server/services/workflow_validator.py b/server/services/workflow_validator.py
index 84e05880..788a9ccc 100644
--- a/server/services/workflow_validator.py
+++ b/server/services/workflow_validator.py
@@ -295,6 +295,7 @@ async def validate_workflow(
# 4. Missing credentials. Warnings (a workflow can be saved with missing
# credentials and configured later — only at force=True execute does
# it become a runtime error).
+ graph = {"nodes": nodes, "edges": edges}
for n in nodes:
node_id = n.get("id")
node_type = n.get("type", "")
@@ -313,6 +314,11 @@ async def validate_workflow(
)
continue
+ # Wiring the plugin states its node needs (BaseNode.validate_graph).
+ validate_graph = getattr(cls, "validate_graph", None)
+ if validate_graph is not None:
+ errors.extend(validate_graph(node_id, graph))
+
# Param validation — prefer caller-supplied params, fall back to
# node.data.parameters (rarely populated since params live in DB).
params = parameters_by_id.get(node_id)
diff --git a/server/tests/test_workflow_validator.py b/server/tests/test_workflow_validator.py
index 95dd5832..aabfaff6 100644
--- a/server/tests/test_workflow_validator.py
+++ b/server/tests/test_workflow_validator.py
@@ -242,6 +242,28 @@ async def test_valid_workflow_returns_empty_report(monkeypatch):
assert report == {"errors": [], "warnings": []}
[email protected]("browsers", [[], ["browser"], ["browser", "browser-2"]])
+async def test_a_browser_ai_agent_needs_exactly_one_browser_tool(browsers):
+ """A plugin's own wiring rule (BaseNode.validate_graph) blocks Start and
+ import: a Browser AI Agent without exactly one Browser tool fails as soon
+ as it runs."""
+ import nodes # noqa: F401 -- populate plugin registry
+ from services.browser_agent_recipe import BROWSER_TOOL_REQUIRED
+ from services.workflow_validator import validate_workflow
+
+ report = await validate_workflow(
+ nodes=[{"id": "agent", "type": "browser_agent", "data": {}},
+ *({"id": browser, "type": "browser", "data": {}} for browser in browsers)],
+ edges=[{"id": f"e-{browser}", "source": browser, "target": "agent",
+ "sourceHandle": "output-tool", "targetHandle": "input-tools"} for browser in browsers],
+ auth_service=_fake_auth(),
+ )
+ issues = [issue for issue in report["errors"] if issue["code"] == "BROWSER_TOOL_REQUIRED"]
+ expected = [] if len(browsers) == 1 else [
+ {"code": "BROWSER_TOOL_REQUIRED", "node_id": "agent", "message": BROWSER_TOOL_REQUIRED}]
+ assert issues == expected
+
+
async def test_parameters_by_id_overrides_node_data(monkeypatch):
"""When parameters_by_id is supplied, it wins over node.data.parameters.
Used by the WS execute handler (hydrating from DB) and the