Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(workflow): preserve historical Agent node compatibility (#40859)
zyssyz12364587eae4328
diff --git a/api/core/workflow/node_factory.py b/api/core/workflow/node_factory.pyindex d0dcde5b0c1..bedbb5765c4 100644--- a/api/core/workflow/node_factory.py+++ b/api/core/workflow/node_factory.py@@ -47,6 +47,7 @@ from core.workflow.nodes.agent.plugin_strategy_adapter import (from core.workflow.nodes.agent.runtime_support import AgentRuntimeSupportfrom core.workflow.nodes.agent_v2 import DifyAgentNodefrom core.workflow.nodes.agent_v2.binding_resolver import WorkflowAgentBindingResolver+from core.workflow.nodes.agent_v2.discriminator import is_dify_agent_node_datafrom core.workflow.nodes.agent_v2.output_adapter import WorkflowAgentOutputAdapterfrom core.workflow.nodes.agent_v2.runtime_request_builder import WorkflowAgentRuntimeRequestBuilderfrom core.workflow.nodes.human_input.callback import DifyHITLCallback@@ -134,12 +135,27 @@ def get_node_type_classes_mapping() -> Mapping[NodeType, Mapping[str, type[Node]return Node.get_node_type_classes_mapping()-def resolve_workflow_node_class(*, node_type: NodeType, node_version: str) -> type[Node]:+def resolve_workflow_node_class(+ *,+ node_type: NodeType,+ node_version: str,+ node_data: Mapping[str, Any] | BaseNodeData | None = None,+) -> type[Node]:"""Resolve the production node class for the requested type/version."""node_mapping = get_node_type_classes_mapping().get(node_type)if not node_mapping:raise ValueError(f"No class mapping found for node type: {node_type}")+ # Historical Agent nodes used version=2 for their tool-parameter format.+ # Only the explicit kind marker identifies the newer Dify Agent node.+ if (+ node_data is not None+ and node_type == BuiltinNodeTypes.AGENT+ and node_version == "2"+ and not is_dify_agent_node_data(node_data)+ ):+ node_version = "1"+latest_node_class = node_mapping.get(LATEST_VERSION)matched_node_class = node_mapping.get(node_version)node_class = matched_node_class or latest_node_class@@ -400,7 +416,11 @@ class DifyNodeFactory(NodeFactory):typed_node_config = NodeConfigDictAdapter.validate_python(adapted_node_config)node_id = typed_node_config["id"]node_data = typed_node_config["data"]- node_class = self._resolve_node_class(node_type=node_data.type, node_version=str(node_data.version))+ node_class = self._resolve_node_class(+ node_type=node_data.type,+ node_version=str(node_data.version),+ node_data=node_data,+ )# Graph configs are initially validated against permissive shared node data.# Re-validate using the resolved node class so workflow-local node schemas# stay explicit and constructors receive the concrete typed payload.@@ -493,10 +513,19 @@ class DifyNodeFactory(NodeFactory):return node_data@staticmethod- def _resolve_node_class(*, node_type: NodeType, node_version: str) -> type[Node]:+ def _resolve_node_class(+ *,+ node_type: NodeType,+ node_version: str,+ node_data: Mapping[str, Any] | BaseNodeData | None = None,+ ) -> type[Node]:if node_type == BuiltinNodeTypes.LLM:return DifyLLMNode- return resolve_workflow_node_class(node_type=node_type, node_version=node_version)+ return resolve_workflow_node_class(+ node_type=node_type,+ node_version=node_version,+ node_data=node_data,+ )def _resolve_llm_model_reference(self, node_data: LLMNodeData) -> LLMNodeData:"""Resolve an optional shared model selector from the workflow variable pool."""diff --git a/api/core/workflow/nodes/agent_v2/discriminator.py b/api/core/workflow/nodes/agent_v2/discriminator.pynew file mode 100644index 00000000000..8df480ca5e7--- /dev/null+++ b/api/core/workflow/nodes/agent_v2/discriminator.py@@ -0,0 +1,28 @@+from collections.abc import Mapping+from typing import Any++from graphon.entities.base_node_data import BaseNodeData+from graphon.enums import BuiltinNodeTypes++AGENT_NODE_KIND = "dify_agent"+AGENT_NODE_VERSION = "2"+++def is_dify_agent_node_data(node_data: Mapping[str, Any] | BaseNodeData) -> bool:+ """Return whether node data explicitly identifies the new Dify Agent node."""++ if isinstance(node_data, Mapping):+ node_type = node_data.get("type")+ node_version = node_data.get("version")+ agent_node_kind = node_data.get("agent_node_kind")+ else:+ serialized_node_data = node_data.model_dump(mode="python")+ node_type = serialized_node_data.get("type")+ node_version = serialized_node_data.get("version")+ agent_node_kind = serialized_node_data.get("agent_node_kind")++ return (+ node_type == BuiltinNodeTypes.AGENT+ and str(node_version) == AGENT_NODE_VERSION+ and agent_node_kind == AGENT_NODE_KIND+ )diff --git a/api/core/workflow/nodes/agent_v2/entities.py b/api/core/workflow/nodes/agent_v2/entities.pyindex eb36b9cf1ed..a9fba739985 100644--- a/api/core/workflow/nodes/agent_v2/entities.py+++ b/api/core/workflow/nodes/agent_v2/entities.py@@ -8,7 +8,7 @@ from graphon.enums import BuiltinNodeTypes, NodeTypeclass DifyAgentNodeData(BaseNodeData):type: NodeType = BuiltinNodeTypes.AGENT- agent_node_kind: Literal["dify_agent"] = "dify_agent"+ agent_node_kind: Literal["dify_agent"]@model_validator(mode="after")def validate_version(self) -> "DifyAgentNodeData":diff --git a/api/core/workflow/nodes/agent_v2/validators.py b/api/core/workflow/nodes/agent_v2/validators.pyindex 6e56e28f829..03cdf70b78a 100644--- a/api/core/workflow/nodes/agent_v2/validators.py+++ b/api/core/workflow/nodes/agent_v2/validators.py@@ -28,6 +28,7 @@ from models.model import UploadFilefrom models.workflow import Workflowfrom services.agent.knowledge_datasets import list_missing_tenant_knowledge_dataset_ids+from .discriminator import is_dify_agent_node_datafrom .entities import DifyAgentNodeData@@ -258,7 +259,7 @@ class WorkflowAgentNodeValidator:node_data = node.get("data")if not isinstance(node_id, str) or not isinstance(node_data, Mapping):continue- if node_data.get("type") == BuiltinNodeTypes.AGENT and str(node_data.get("version")) == "2":+ if is_dify_agent_node_data(node_data):yield node_id, node_data@staticmethoddiff --git a/api/core/workflow/workflow_entry.py b/api/core/workflow/workflow_entry.pyindex 866bc73fcf6..372bbd4e7f8 100644--- a/api/core/workflow/workflow_entry.py+++ b/api/core/workflow/workflow_entry.py@@ -215,7 +215,11 @@ class WorkflowEntry:if node_type in {BuiltinNodeTypes.LOOP, BuiltinNodeTypes.ITERATION}:raise ValueError("Loop and Iteration nodes must use their engine-backed debug endpoints")node_version = str(node_config_data.version)- node_cls = resolve_workflow_node_class(node_type=node_type, node_version=node_version)+ node_cls = resolve_workflow_node_class(+ node_type=node_type,+ node_version=node_version,+ node_data=node_config_data,+ )# init graph context and runtime staterun_context = build_dify_run_context(diff --git a/api/services/agent/composer_candidates.py b/api/services/agent/composer_candidates.pyindex a650b16e9bc..efa0e422324 100644--- a/api/services/agent/composer_candidates.py+++ b/api/services/agent/composer_candidates.py@@ -21,6 +21,7 @@ from __future__ import annotationsfrom collections.abc import Callable, Mappingfrom typing import Any+from core.workflow.nodes.agent_v2.discriminator import is_dify_agent_node_datafrom models.agent_config_entities import (AgentSoulConfig,DeclaredOutputConfig,@@ -97,7 +98,7 @@ def previous_node_output_candidates(continuedeclared: list[DeclaredOutputConfig] | None = None- if kind == "agent" and str(data.get("version", "")) == "2":+ if is_dify_agent_node_data(data):declared = declared_outputs_loader(nid)if declared is not None:for output in declared:diff --git a/api/services/agent/dsl_service.py b/api/services/agent/dsl_service.pyindex e1f9afd0142..1b7a09cf493 100644--- a/api/services/agent/dsl_service.py+++ b/api/services/agent/dsl_service.py@@ -18,8 +18,8 @@ from pydantic import BaseModel, ConfigDict, Fieldfrom sqlalchemy import func, selectfrom sqlalchemy.orm import Session+from core.workflow.nodes.agent_v2.discriminator import is_dify_agent_node_datafrom core.workflow.nodes.agent_v2.validators import WorkflowAgentNodeValidator-from graphon.enums import BuiltinNodeTypesfrom models import Accountfrom models.agent import (APP_BACKED_AGENT_SOURCES,@@ -636,7 +636,7 @@ class AgentDslService:def is_agent_v2_graph(graph: Mapping[str, Any]) -> bool:return any(- node.get("data", {}).get("type") == BuiltinNodeTypes.AGENT and node.get("data", {}).get("version") == "2"+ isinstance(node.get("data"), Mapping) and is_dify_agent_node_data(node["data"])for node in graph.get("nodes", [])if isinstance(node, Mapping))diff --git a/api/services/workflow/node_output_inspector_service.py b/api/services/workflow/node_output_inspector_service.pyindex 5d6a8f1c675..dee806c9464 100644--- a/api/services/workflow/node_output_inspector_service.py+++ b/api/services/workflow/node_output_inspector_service.py@@ -59,15 +59,12 @@ from core.workflow.nodes.agent_v2.binding_resolver import (WorkflowAgentBindingError,WorkflowAgentBindingResolver,)+from core.workflow.nodes.agent_v2.discriminator import is_dify_agent_node_datafrom core.workflow.nodes.agent_v2.runtime_request_builder import (WorkflowAgentRuntimeRequestBuilder,)from factories.file_factory.builders import build_from_mapping-from graphon.enums import (- BuiltinNodeTypes,- WorkflowExecutionStatus,- WorkflowNodeExecutionStatus,-)+from graphon.enums import WorkflowExecutionStatus, WorkflowNodeExecutionStatusfrom graphon.file import helpers as file_helpersfrom models import Appfrom models.agent_config_entities import DeclaredOutputConfig, DeclaredOutputType@@ -182,18 +179,12 @@ class _ResolvedDeclaration:def _is_agent_v2_node(node: Mapping[str, Any]) -> bool:- """A graph node is Agent v2 iff its ``data.type`` is the AGENT builtin- AND its ``data.version`` is ``"2"``.+ """Return whether a graph node explicitly identifies the new Dify Agent node."""- ``BuiltinNodeTypes.AGENT`` is a ``ClassVar[NodeType]`` (plain string), not- a StrEnum, so we compare against it directly without ``.value``.- """data = node.get("data") or {}if not isinstance(data, Mapping):return False- if data.get("type") != BuiltinNodeTypes.AGENT:- return False- return str(data.get("version", "")) == "2"+ return is_dify_agent_node_data(data)def _graph_nodes(workflow_run: WorkflowRun) -> list[Mapping[str, Any]]:diff --git a/api/tests/integration_tests/services/test_node_output_inspector_service.py b/api/tests/integration_tests/services/test_node_output_inspector_service.pyindex c2253a20c15..889ee56dfc4 100644--- a/api/tests/integration_tests/services/test_node_output_inspector_service.py+++ b/api/tests/integration_tests/services/test_node_output_inspector_service.py@@ -133,7 +133,12 @@ def seeded_run("nodes": [{"id": "agent-node-1",- "data": {"type": "agent", "version": "2", "title": "My Agent"},+ "data": {+ "type": "agent",+ "version": "2",+ "agent_node_kind": "dify_agent",+ "title": "My Agent",+ },},{"id": "tool-node-1",@@ -328,7 +333,14 @@ def test_snapshot_404s_for_published_run_per_decision_d1(flask_req_ctx, fake_appdef test_snapshot_surfaces_type_check_failure_from_metadata(flask_req_ctx, fake_app_model):"""Per-output ``TYPE_CHECK_FAILED`` derived from the metadata blob theStage 4 §5 stack records on the execution row."""- graph = {"nodes": [{"id": "agent-1", "data": {"type": "agent", "version": "2"}}]}+ graph = {+ "nodes": [+ {+ "id": "agent-1",+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ }+ ]+ }workflow_run = _make_workflow_run(app_id=fake_app_model.id, tenant_id=fake_app_model.tenant_id, graph=graph)execution = _make_execution(app_id=fake_app_model.id,@@ -375,7 +387,14 @@ def test_snapshot_surfaces_type_check_failure_from_metadata(flask_req_ctx, fake_def test_snapshot_surfaces_output_check_failure_from_metadata(flask_req_ctx, fake_app_model):"""When ``output_type_check.passed`` but ``output_check.passed=False``, theoutput is flagged ``OUTPUT_CHECK_FAILED``."""- graph = {"nodes": [{"id": "agent-1", "data": {"type": "agent", "version": "2"}}]}+ graph = {+ "nodes": [+ {+ "id": "agent-1",+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ }+ ]+ }workflow_run = _make_workflow_run(app_id=fake_app_model.id, tenant_id=fake_app_model.tenant_id, graph=graph)execution = _make_execution(app_id=fake_app_model.id,@@ -470,7 +489,14 @@ def test_keeps_latest_execution_per_node_by_index(flask_req_ctx, fake_app_model)"""Multiple executions for the same node_id → service keeps the highest``index`` (matches the agent_v2 retry pattern that re-emits nodeexecutions)."""- graph = {"nodes": [{"id": "agent-1", "data": {"type": "agent", "version": "2"}}]}+ graph = {+ "nodes": [+ {+ "id": "agent-1",+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ }+ ]+ }workflow_run = _make_workflow_run(app_id=fake_app_model.id, tenant_id=fake_app_model.tenant_id, graph=graph)older = _make_execution(app_id=fake_app_model.id,diff --git a/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py b/api/tests/test_containers_integration_tests/services/test_app_dsl_service.pyindex 8ea3a7b8c81..e61b22e611a 100644--- a/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py+++ b/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py@@ -1010,6 +1010,7 @@ class TestAppDslService:"data": {"type": BuiltinNodeTypes.AGENT,"version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": WorkflowAgentBindingType.ROSTER_AGENT.value,AGENT_PACKAGE_REF_KEY: "agent_1",@@ -1021,6 +1022,7 @@ class TestAppDslService:"data": {"type": BuiltinNodeTypes.AGENT,"version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": WorkflowAgentBindingType.INLINE_AGENT.value,AGENT_PACKAGE_REF_KEY: "agent_1",diff --git a/api/tests/unit_tests/controllers/console/app/test_workflow.py b/api/tests/unit_tests/controllers/console/app/test_workflow.pyindex 82d6add152b..3677b0cbb80 100644--- a/api/tests/unit_tests/controllers/console/app/test_workflow.py+++ b/api/tests/unit_tests/controllers/console/app/test_workflow.py@@ -650,6 +650,7 @@ def test_draft_workflow_get_projects_agent_node_job_to_graph(monkeypatch: pytest"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent",},}],@@ -663,6 +664,7 @@ def test_draft_workflow_get_projects_agent_node_job_to_graph(monkeypatch: pytest"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_task": "Summarize it.","agent_declared_outputs": [{"name": "summary", "type": "string"}],},diff --git a/api/tests/unit_tests/core/app/apps/test_pause_resume.py b/api/tests/unit_tests/core/app/apps/test_pause_resume.pyindex 6bfda02eb4c..2b1690c2f5e 100644--- a/api/tests/unit_tests/core/app/apps/test_pause_resume.py+++ b/api/tests/unit_tests/core/app/apps/test_pause_resume.py@@ -1,5 +1,6 @@import sysimport time+from collections.abc import Mappingfrom types import ModuleType, SimpleNamespacefrom typing import Any@@ -106,10 +107,19 @@ class _StubToolNode(Node[_StubToolNodeData]):def _patch_tool_node(mocker: MockerFixture):original_resolve_node_class = node_factory_module.resolve_workflow_node_class- def _patched_resolve_node_class(*, node_type: NodeType, node_version: str) -> type[Node]:+ def _patched_resolve_node_class(+ *,+ node_type: NodeType,+ node_version: str,+ node_data: Mapping[str, Any] | BaseNodeData | None = None,+ ) -> type[Node]:if node_type == BuiltinNodeTypes.TOOL:return _StubToolNode- return original_resolve_node_class(node_type=node_type, node_version=node_version)+ return original_resolve_node_class(+ node_type=node_type,+ node_version=node_version,+ node_data=node_data,+ )mocker.patch.object(node_factory_module, "resolve_workflow_node_class", side_effect=_patched_resolve_node_class)diff --git a/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py b/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.pyindex 915cdaa8ec1..ffd7bbb8f0d 100644--- a/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py+++ b/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py@@ -343,7 +343,9 @@ def _node(node = DifyAgentNode(node_id="agent-node",- data=DifyAgentNodeData.model_validate({"type": BuiltinNodeTypes.AGENT, "version": "2"}),+ data=DifyAgentNodeData.model_validate(+ {"type": BuiltinNodeTypes.AGENT, "version": "2", "agent_node_kind": "dify_agent"}+ ),graph_init_params=graph_init_params,graph_runtime_state=cast(GraphRuntimeState,diff --git a/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_discriminator.py b/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_discriminator.pynew file mode 100644index 00000000000..1476764d37f--- /dev/null+++ b/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_discriminator.py@@ -0,0 +1,31 @@+import pytest+from pydantic import ValidationError++from core.workflow.nodes.agent_v2.discriminator import is_dify_agent_node_data+from core.workflow.nodes.agent_v2.entities import DifyAgentNodeData+from graphon.entities.base_node_data import BaseNodeData+++ ("node_data", "expected"),+ [+ ({"type": "agent", "version": "2", "agent_node_kind": "dify_agent"}, True),+ ({"type": "agent", "version": 2, "agent_node_kind": "dify_agent"}, True),+ ({"type": "agent", "version": "2"}, False),+ ({"type": "agent", "version": "1", "agent_node_kind": "dify_agent"}, False),+ ({"type": "llm", "version": "2", "agent_node_kind": "dify_agent"}, False),+ ],+)+def test_is_dify_agent_node_data_mapping(node_data: dict[str, object], expected: bool) -> None:+ assert is_dify_agent_node_data(node_data) is expected+++def test_is_dify_agent_node_data_supports_base_node_data() -> None:+ node_data = BaseNodeData.model_validate({"type": "agent", "version": "2", "agent_node_kind": "dify_agent"})++ assert is_dify_agent_node_data(node_data) is True+++def test_dify_agent_node_data_requires_explicit_kind_marker() -> None:+ with pytest.raises(ValidationError, match="agent_node_kind"):+ DifyAgentNodeData.model_validate({"type": "agent", "version": "2"})diff --git a/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_validators.py b/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_validators.pyindex c95f30b81c7..c59b455c96a 100644--- a/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_validators.py+++ b/api/tests/unit_tests/core/workflow/nodes/agent_v2/test_validators.py@@ -87,7 +87,10 @@ def _graph(edges: list[dict]) -> dict:"nodes": [{"id": "start", "data": {"type": "start"}},{"id": "previous-node", "data": {"type": "llm"}},- {"id": "agent-node", "data": {"type": "agent", "version": "2"}},+ {+ "id": "agent-node",+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ },{"id": "later-node", "data": {"type": "llm"}},],"edges": edges,@@ -118,6 +121,18 @@ def _tool_graph(tool_data: dict) -> dict:}+def test_historical_agent_version_two_is_not_validated_as_dify_agent() -> None:+ graph = {+ "nodes": [{"id": "legacy-agent", "data": {"type": "agent", "version": "2"}}],+ "edges": [],+ }+ session = Mock()++ WorkflowAgentNodeValidator.validate_published_workflow(session=session, workflow=_workflow(graph))++ session.scalar.assert_not_called()++def test_publish_validation_accepts_upstream_previous_output_ref():node_job = WorkflowNodeJobConfig.model_validate({"previous_node_output_refs": [{"node_id": "previous-node", "output": "text"}]}diff --git a/api/tests/unit_tests/core/workflow/test_node_mapping_bootstrap.py b/api/tests/unit_tests/core/workflow/test_node_mapping_bootstrap.pyindex c7ff7e5a340..c512eb04637 100644--- a/api/tests/unit_tests/core/workflow/test_node_mapping_bootstrap.py+++ b/api/tests/unit_tests/core/workflow/test_node_mapping_bootstrap.py@@ -23,7 +23,12 @@ def test_moved_core_nodes_resolve_after_importing_production_entrypoints():from core.app.apps import workflow_app_runnerfrom core.workflow import workflow_entryfrom core.workflow.nodes.knowledge_index import KNOWLEDGE_INDEX_NODE_TYPE- from core.workflow.node_factory import DifyNodeFactory, NODE_TYPE_CLASSES_MAPPING+ from core.workflow.node_factory import (+ DifyNodeFactory,+ NODE_TYPE_CLASSES_MAPPING,+ resolve_workflow_node_class,+ )+ from core.workflow.nodes.agent import AgentNodefrom core.workflow.nodes.agent_v2 import DifyAgentNodefrom graphon.enums import BuiltinNodeTypesfrom services import workflow_service@@ -46,6 +51,16 @@ def test_moved_core_nodes_resolve_after_importing_production_entrypoints():node_type=BuiltinNodeTypes.AGENT,node_version="2",) is DifyAgentNode+ assert resolve_workflow_node_class(+ node_type=BuiltinNodeTypes.AGENT,+ node_version="2",+ node_data={"type": "agent", "version": "2"},+ ) is AgentNode+ assert resolve_workflow_node_class(+ node_type=BuiltinNodeTypes.AGENT,+ node_version="2",+ node_data={"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ ) is DifyAgentNode""")completed = subprocess.run(diff --git a/api/tests/unit_tests/services/agent/test_agent_dsl_service.py b/api/tests/unit_tests/services/agent/test_agent_dsl_service.pyindex 4ebf30c25ad..fa188ecb8f8 100644--- a/api/tests/unit_tests/services/agent/test_agent_dsl_service.py+++ b/api/tests/unit_tests/services/agent/test_agent_dsl_service.py@@ -60,7 +60,7 @@ def _snapshot(*, snapshot_id: str = "snapshot-1", soul: AgentSoulConfig | None =def _agent_node(node_id: str, binding: object | None = None) -> dict:- data = {"type": BuiltinNodeTypes.AGENT, "version": "2"}+ data = {"type": BuiltinNodeTypes.AGENT, "version": "2", "agent_node_kind": "dify_agent"}if binding is not None:data["agent_binding"] = bindingreturn {"id": node_id, "data": data}@@ -734,4 +734,17 @@ def test_require_helpers_and_graph_detection() -> None:assert AgentDslService._agent_icon_type(AgentIconType.EMOJI.value) == AgentIconType.EMOJIassert AgentDslService._agent_icon_type(None) is Noneassert is_agent_v2_graph({"nodes": [_agent_node("agent")]}) is True+ assert is_agent_v2_graph({"nodes": [{"id": "legacy-agent", "data": {"type": "agent", "version": "2"}}]}) is Falseassert is_agent_v2_graph({"nodes": ["invalid", {"data": {"type": "start"}}]}) is False+++def test_export_workflow_packages_ignores_historical_agent_version_two() -> None:+ session = Mock()+ service = AgentDslService(session)+ graph = {"nodes": [{"id": "legacy-agent", "data": {"type": "agent", "version": "2"}}]}++ portable_graph, packages = service.export_workflow_packages(workflow=Mock(), graph=graph)++ assert portable_graph == graph+ assert packages == {}+ session.scalars.assert_not_called()diff --git a/api/tests/unit_tests/services/agent/test_agent_services.py b/api/tests/unit_tests/services/agent/test_agent_services.pyindex 479324c3167..459361f744d 100644--- a/api/tests/unit_tests/services/agent/test_agent_services.py+++ b/api/tests/unit_tests/services/agent/test_agent_services.py@@ -5671,7 +5671,12 @@ class TestWorkflowAgentDraftBindingSync:workflow = _workflow()workflow.graph = json.dumps({- "nodes": [{"id": "agent-node", "data": {"type": "agent", "version": "2"}}],+ "nodes": [+ {+ "id": "agent-node",+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ }+ ],"edges": [],})@@ -5739,6 +5744,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_task": agent_task,"agent_binding": {"binding_type": "roster_agent",@@ -5882,6 +5888,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "roster_agent","agent_id": "agent-1",@@ -5963,6 +5970,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent",},@@ -6017,6 +6025,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent",},@@ -6066,6 +6075,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_task": "Summarize the upstream result.","agent_declared_outputs": [{@@ -6165,6 +6175,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_task": "Use the current node context.","agent_binding": {"binding_type": "inline_agent",@@ -6232,6 +6243,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent",},@@ -6280,6 +6292,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent","agent_id": "inline-agent-1",@@ -6338,6 +6351,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "unknown","agent_id": "agent-1",@@ -6371,6 +6385,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent","agent_id": "inline-agent-1",@@ -6405,6 +6420,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent","agent_id": "inline-agent-1",@@ -6454,6 +6470,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_task": "Use the latest tender context.","agent_binding": {"binding_type": "roster_agent",@@ -6521,6 +6538,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_task": "Keep the prompt.","agent_declared_outputs": [],"agent_binding": {@@ -6601,6 +6619,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent","agent_id": "inline-kept",@@ -6613,6 +6632,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "roster_agent","agent_id": "roster-new",@@ -6624,6 +6644,7 @@ class TestWorkflowAgentDraftBindingSync:"data": {"type": "agent","version": "2",+ "agent_node_kind": "dify_agent","agent_binding": {"binding_type": "inline_agent","agent_id": "inline-new",diff --git a/api/tests/unit_tests/services/agent/test_composer_candidates.py b/api/tests/unit_tests/services/agent/test_composer_candidates.pyindex d1edf2cfa60..990302e9f91 100644--- a/api/tests/unit_tests/services/agent/test_composer_candidates.py+++ b/api/tests/unit_tests/services/agent/test_composer_candidates.py@@ -2,6 +2,8 @@from __future__ import annotations+from unittest.mock import Mock+from fields.agent_fields import AgentComposerCandidatesResponsefrom models.agent_config_entities import AgentSoulConfig, DeclaredOutputConfig, DeclaredOutputTypefrom models.dataset import Dataset@@ -22,8 +24,24 @@ _GRAPH = {},},{"id": "llm-1", "data": {"type": "llm", "title": "LLM"}},- {"id": "agent-up", "data": {"type": "agent", "version": "2", "title": "Upstream Agent"}},- {"id": "agent-target", "data": {"type": "agent", "version": "2", "title": "Target Agent"}},+ {+ "id": "agent-up",+ "data": {+ "type": "agent",+ "version": "2",+ "agent_node_kind": "dify_agent",+ "title": "Upstream Agent",+ },+ },+ {+ "id": "agent-target",+ "data": {+ "type": "agent",+ "version": "2",+ "agent_node_kind": "dify_agent",+ "title": "Target Agent",+ },+ },{"id": "end", "data": {"type": "end", "title": "END"}},],"edges": [@@ -97,6 +115,31 @@ def test_results_differ_per_node_id():assert {e["node_id"] for e in entries_llm} == {"start-1"}+def test_historical_agent_version_two_uses_inferred_outputs() -> None:+ graph = {+ "nodes": [+ {"id": "legacy", "data": {"type": "agent", "version": "2", "title": "Legacy"}},+ {+ "id": "target",+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent"},+ },+ ],+ "edges": [{"source": "legacy", "target": "target"}],+ }+ declared_loader = Mock(return_value=[DeclaredOutputConfig(name="declared", type=DeclaredOutputType.STRING)])++ entries, _ = previous_node_output_candidates(+ graph=graph,+ node_id="target",+ declared_outputs_loader=declared_loader,+ draft_variables_loader=lambda node_id: [("legacy_output", "string")] if node_id == "legacy" else [],+ system_variables_loader=lambda: [],+ )++ assert [entry["output"] for entry in entries] == ["legacy_output"]+ declared_loader.assert_not_called()++def test_previous_outputs_capped_and_flagged():graph = {"nodes": [{"id": "start-1", "data": {"type": "start", "title": "S", "variables": []}}, {"id": "t"}],diff --git a/api/tests/unit_tests/services/agent/test_workflow_publish_service.py b/api/tests/unit_tests/services/agent/test_workflow_publish_service.pyindex cb577eed287..70cd220877a 100644--- a/api/tests/unit_tests/services/agent/test_workflow_publish_service.py+++ b/api/tests/unit_tests/services/agent/test_workflow_publish_service.py@@ -140,7 +140,10 @@ def test_publish_binding_replacement_returns_only_previous_inline_agent(sqlite_session: Session,) -> None:draft_workflow = _workflow()- draft_workflow.graph = '{"nodes":[{"id":"agent-node","data":{"type":"agent","version":"2"}}],"edges":[]}'+ draft_workflow.graph = (+ '{"nodes":[{"id":"agent-node","data":{"type":"agent","version":"2",'+ '"agent_node_kind":"dify_agent"}}],"edges":[]}'+ )published_workflow = _workflow(workflow_id="published-new", version="published-new")app = App(id="app-1",diff --git a/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py b/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.pyindex 8cd907ed705..6a52ebe5002 100644--- a/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py+++ b/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py@@ -138,7 +138,7 @@ def _execution(def _agent_v2_node(*, node_id: str = "agent-node-1", title: str = "My Agent") -> dict[str, Any]:return {"id": node_id,- "data": {"type": "agent", "version": "2", "title": title},+ "data": {"type": "agent", "version": "2", "agent_node_kind": "dify_agent", "title": title},}@@ -243,6 +243,19 @@ def test_snapshot_accepts_published_run_d1_lifted(session_for: SessionFor) -> Noassert [n.node_id for n in snapshot.node_outputs] == ["agent-1"]+def test_historical_agent_version_two_uses_inferred_outputs(session_for: SessionFor) -> None:+ resolver = MagicMock()+ service = NodeOutputInspectorService(binding_resolver=resolver)+ run = _workflow_run(nodes=[{"id": "legacy-agent", "data": {"type": "agent", "version": "2", "title": "Legacy"}}])+ execution = _execution(node_id="legacy-agent", outputs={"text": "legacy output"})+ session = session_for(workflow_run=run, executions=[execution])++ snapshot = service.snapshot_workflow_run(app_model=_app_model(), workflow_run_id="run-1", session=session)++ assert [(output.name, output.type) for output in snapshot.node_outputs[0].outputs] == [("text", None)]+ resolver.resolve.assert_not_called()++def test_snapshot_accepts_webhook_triggered_run(session_for: SessionFor) -> None:"""Webhook / schedule / plugin triggers are also published-side."""service = _make_service()