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) (#27087)

red_sun61a0fcc2eaaf
diff --git a/api/core/tools/__base/tool.py b/api/core/tools/__base/tool.py
index 82616596f86..8ca4eabb7a6 100644
--- a/api/core/tools/__base/tool.py
+++ b/api/core/tools/__base/tool.py
@@ -210,12 +210,13 @@ class Tool(ABC):
meta=meta,
)
- def create_json_message(self, object: dict) -> ToolInvokeMessage:
+ def create_json_message(self, object: dict, suppress_output: bool = False) -> ToolInvokeMessage:
"""
create a json message
"""
return ToolInvokeMessage(
- type=ToolInvokeMessage.MessageType.JSON, message=ToolInvokeMessage.JsonMessage(json_object=object)
+ type=ToolInvokeMessage.MessageType.JSON,
+ message=ToolInvokeMessage.JsonMessage(json_object=object, suppress_output=suppress_output),
)
def create_variable_message(
diff --git a/api/core/tools/entities/tool_entities.py b/api/core/tools/entities/tool_entities.py
index 15a4f0aafd2..5b385f1bb22 100644
--- a/api/core/tools/entities/tool_entities.py
+++ b/api/core/tools/entities/tool_entities.py
@@ -129,6 +129,7 @@ class ToolInvokeMessage(BaseModel):
class JsonMessage(BaseModel):
json_object: dict
+ suppress_output: bool = Field(default=False, description="Whether to suppress JSON output in result string")
class BlobMessage(BaseModel):
blob: bytes
diff --git a/api/core/tools/tool_engine.py b/api/core/tools/tool_engine.py
index 92d441b5acb..13fd579e20a 100644
--- a/api/core/tools/tool_engine.py
+++ b/api/core/tools/tool_engine.py
@@ -245,6 +245,9 @@ class ToolEngine:
+ "you do not need to create it, just tell the user to check it now."
)
elif response.type == ToolInvokeMessage.MessageType.JSON:
+ json_message = cast(ToolInvokeMessage.JsonMessage, response.message)
+ if json_message.suppress_output:
+ continue
json_parts.append(
json.dumps(
safe_json_value(cast(ToolInvokeMessage.JsonMessage, response.message).json_object),
diff --git a/api/core/tools/workflow_as_tool/tool.py b/api/core/tools/workflow_as_tool/tool.py
index 2cd46647a09..5703c19c880 100644
--- a/api/core/tools/workflow_as_tool/tool.py
+++ b/api/core/tools/workflow_as_tool/tool.py
@@ -117,7 +117,7 @@ class WorkflowTool(Tool):
self._latest_usage = self._derive_usage_from_result(data)
yield self.create_text_message(json.dumps(outputs, ensure_ascii=False))
- yield self.create_json_message(outputs)
+ yield self.create_json_message(outputs, suppress_output=True)
@property
def latest_usage(self) -> LLMUsage: