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 agent putout the output of workflow-tool twice (#26835) (#27706)

Cursxf9c67621ca22
diff --git a/api/core/tools/tool_engine.py b/api/core/tools/tool_engine.py
index 9fb6062770b..92d441b5acb 100644
--- a/api/core/tools/tool_engine.py
+++ b/api/core/tools/tool_engine.py
@@ -228,29 +228,38 @@ class ToolEngine:
"""
Handle tool response
"""
- result = ""
+ parts: list[str] = []
+ json_parts: list[str] = []
+
for response in tool_response:
if response.type == ToolInvokeMessage.MessageType.TEXT:
- result += cast(ToolInvokeMessage.TextMessage, response.message).text
+ parts.append(cast(ToolInvokeMessage.TextMessage, response.message).text)
elif response.type == ToolInvokeMessage.MessageType.LINK:
- result += (
+ parts.append(
f"result link: {cast(ToolInvokeMessage.TextMessage, response.message).text}."
+ " please tell user to check it."
)
elif response.type in {ToolInvokeMessage.MessageType.IMAGE_LINK, ToolInvokeMessage.MessageType.IMAGE}:
- result += (
+ parts.append(
"image has been created and sent to user already, "
+ "you do not need to create it, just tell the user to check it now."
)
elif response.type == ToolInvokeMessage.MessageType.JSON:
- result += json.dumps(
- safe_json_value(cast(ToolInvokeMessage.JsonMessage, response.message).json_object),
- ensure_ascii=False,
+ json_parts.append(
+ json.dumps(
+ safe_json_value(cast(ToolInvokeMessage.JsonMessage, response.message).json_object),
+ ensure_ascii=False,
+ )
)
else:
- result += str(response.message)
+ parts.append(str(response.message))
- return result
+ # Add JSON parts, avoiding duplicates from text parts.
+ if json_parts:
+ existing_parts = set(parts)
+ parts.extend(p for p in json_parts if p not in existing_parts)
+
+ return "".join(parts)
@staticmethod
def _extract_tool_response_binary_and_text(