Skip to content

armgit / dify

Public Imported from GitHub
0

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.

fix: fix tool output duplicate (#34962)

wangxiaolei65d66768c14a
diff --git a/api/core/tools/tool_engine.py b/api/core/tools/tool_engine.py
index 685d687d8c4..d1e333f5022 100644
--- a/api/core/tools/tool_engine.py
+++ b/api/core/tools/tool_engine.py
@@ -262,6 +262,8 @@ class ToolEngine:
ensure_ascii=False,
)
)
+ elif response.type == ToolInvokeMessage.MessageType.VARIABLE:
+ continue
else:
parts.append(str(response.message))
diff --git a/api/core/tools/utils/workflow_configuration_sync.py b/api/core/tools/utils/workflow_configuration_sync.py
index c4b7d574493..2159eb8638f 100644
--- a/api/core/tools/utils/workflow_configuration_sync.py
+++ b/api/core/tools/utils/workflow_configuration_sync.py
@@ -17,10 +17,8 @@ class WorkflowToolConfigurationUtils:
"""
nodes = graph.get("nodes", [])
start_node = next(filter(lambda x: x.get("data", {}).get("type") == "start", nodes), None)
-
if not start_node:
return []
-
return [VariableEntity.model_validate(variable) for variable in start_node.get("data", {}).get("variables", [])]
@classmethod
diff --git a/api/services/tools/workflow_tools_manage_service.py b/api/services/tools/workflow_tools_manage_service.py
index 8f5144c8667..ef17dbd2885 100644
--- a/api/services/tools/workflow_tools_manage_service.py
+++ b/api/services/tools/workflow_tools_manage_service.py
@@ -84,6 +84,7 @@ class WorkflowToolManageService:
try:
WorkflowToolProviderController.from_db(workflow_tool_provider)
except Exception as e:
+ logger.warning(e, exc_info=True)
raise ValueError(str(e))
with Session(db.engine, expire_on_commit=False) as session, session.begin():
diff --git a/api/tests/unit_tests/core/tools/test_tool_engine.py b/api/tests/unit_tests/core/tools/test_tool_engine.py
index 40c107667cb..cd16557ef64 100644
--- a/api/tests/unit_tests/core/tools/test_tool_engine.py
+++ b/api/tests/unit_tests/core/tools/test_tool_engine.py
@@ -260,6 +260,28 @@ def test_agent_invoke_engine_meta_error():
assert error_meta.error == "meta failure"
+def test_convert_tool_response_excludes_variable_messages():
+ """Regression test for issue #34723.
+
+ WorkflowTool._invoke yields VARIABLE, TEXT, and suppressed-JSON messages.
+ _convert_tool_response_to_str must skip VARIABLE messages so that the
+ returned string contains only the TEXT representation and not a
+ duplicated, garbled Pydantic repr of the same data.
+ """
+ tool = _build_tool()
+ outputs = {"reports": "hello"}
+ messages = [
+ tool.create_variable_message(variable_name="reports", variable_value="hello"),
+ tool.create_text_message('{"reports": "hello"}'),
+ tool.create_json_message(outputs, suppress_output=True),
+ ]
+
+ result = ToolEngine._convert_tool_response_to_str(messages)
+
+ assert result == '{"reports": "hello"}'
+ assert "variable_name" not in result
+
+
def test_agent_invoke_tool_invoke_error():
tool = _build_tool(with_llm_parameter=True)
callback = Mock()