Skip to content

[bug] workflow as tool files field return is empty #26431

@CrabSAMA

Description

@CrabSAMA

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.9.0

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. create a new workflow, add one generate file plugin, I use md_exporter
Image

md_exporter tool files field have correct return

  1. publish this workflow to tool
  2. add this tool at another workflow and run it, watch the common tool field files, and it will found nothing
Image

log here:

[on_tool_execution]
Tool: md_to_pdf
Outputs: {"type":"blob","message":{"blob":"JVBERi0xLjQKJZOMi54gUmVwb3J0TGFiIEdlbmVyYXRlZCBQREYgZG9jdW1lbnQgaHR0cDovL3d3dy5yZXBvcnRsYWIuY29tCjEgMCBvYmoKPDwKL0YxIDIgMCBSIC9GMiAzIDAgUgo+PgplbmRvYmoKMiAwIG9iago8PAovQmFzZUZvbnQgL0hlbHZldGljYSAvRW5jb2RpbmcgL1dpbkFuc2lFbmNvZGluZyAvTmFtZSAvRjEgL1N1YnR5cGUgL1R5cGUxIC9UeXBlIC9Gb250Cj4+CmVuZG9iagozIDAgb2JqCjw8Ci9CYXNlRm9udCAvSGVsdmV0aWNhLUJvbGQgL0VuY29kaW5nIC9XaW5BbnNpRW5jb2RpbmcgL05hbWUgL0YyIC9TdWJ0eXBlIC9UeXBlMSAvVHlwZSAvRm9udAo+PgplbmRvYmoKNCAwIG9iago8PAovQ29udGVudHMgMTEgMCBSIC9NZWRpYUJveCBbIDAgMCA1OTUuMjc1NiA4NDEuODg5OCBdIC9QYXJlbnQgMTAgMCBSIC9SZXNvdXJjZXMgPDwKL0ZvbnQgMSAwIFIgL1Byb2NTZXQgWyAvUERGIC9UZXh0IC9JbWFnZUIgL0ltYWdlQyAvSW1hZ2VJIF0KPj4gL1JvdGF0ZSAwIC9UcmFucyA8PAoKPj4gCiAgL1R5cGUgL1BhZ2UKPj4KZW5kb2JqCjUgMCBvYmoKPDwKL091dGxpbmVzIDcgMCBSIC9QYWdlTW9kZSAvVXNlTm9uZSAvUGFnZXMgMTAgMCBSIC9UeXBlIC9DYXRhbG9nCj4+CmVuZG9iago2IDAgb2JqCjw8Ci9BdXRob3IgKCkgL0NyZWF0aW9uRGF0ZSAoRDoyMDI1MDkyOTA2NDM1NiswMCcwMCcpIC9DcmVhdG9yIChcKHVuc3BlY2lmaWVkXCkpIC9LZXl3b3JkcyAoKS


[on_tool_execution]
Tool: test
Outputs: {"type":"file","message":{},"meta":{"file":{"dify_model_identity":"__dify__file__","id":null,"tenant_id":"b7df5634-8029-4c6d-969f-c39e9f7ae646","type":"document","transfer_method":"tool_file","remote_url":null,"related_id":"daa5807b-bf1b-429b-a0c4-c792c2b43d45","filename":"15af481b86264b548b1a9e59a5248406.pdf","extension":".pdf","mime_type":"application/pdf","size":1954}}}

[on_tool_execution]
Tool: test
Outputs: {"type":"text","message":{"text":"{\"files1\": [{\"dify_model_identity\": \"__dify__file__\", \"id\": null, \"tenant_id\": \"b7df5634-8029-4c6d-969f-c39e9f7ae646\", \"type\": \"document\", \"transfer_method\": \"tool_file\", \"remote_url\": null, \"related_id\": \"daa5807b-bf1b-429b-a0c4-c792c2b43d45\", \"filename\": \"15af481b86264b548b1a9e59a5248406.pdf\", \"extension\": \".pdf\", \"mime_type\": \"application/pdf\", \"size\": 1954, \"url\": \"http://127.0.0.1:5001/files/tools/daa5807b-bf1b-429b-a0c4-c792c2b43d45.pdf?timestamp=1759128236&nonce=8b229fa50d6df2eb787765a40f502d99&sign=ymEk1BfpL3dDGOZPmtPYY0zYTUb_MJ-co3ZOcFclRs0=\", \"tool_file_id\": \"daa5807b-bf1b-429b-a0c4-c792c2b43d45\"}]}"},"meta":null}


[on_tool_execution]
Tool: test
Outputs: {"type":"json","message":{"json_object":{"files1":[{"dify_model_identity":"__dify__file__","id":null,"tenant_id":"b7df5634-8029-4c6d-969f-c39e9f7ae646","type":"document","transfer_method":"tool_file","remote_url":null,"related_id":"daa5807b-bf1b-429b-a0c4-c792c2b43d45","filename":"15af481b86264b548b1a9e59a5248406.pdf","extension":".pdf","mime_type":"application/pdf","size":1954,"url":"http://127.0.0.1:5001/files/tools/daa5807b-bf1b-429b-a0c4-c792c2b43d45.pdf?timestamp=1759128236&nonce=8b229fa50d6df2eb787765a40f502d99&sign=ymEk1BfpL3dDGOZPmtPYY0zYTUb_MJ-co3ZOcFclRs0=","tool_file_id":"daa5807b-bf1b-429b-a0c4-c792c2b43d45"}]}},"meta":null}

Actually, the tool of workflow as tool create file message correctly, but at last we got nothing at files field.

✔️ Expected Behavior

Workflow as tool files field return all files which this tool generated.

❌ Actual Behavior

Workflow as tool files field return empty.

Here is relative issue: #18375

This issue mentioned pr #18427 is revertd by this pr #24061, because it introduce some new bug, but this behavior actually not correct, we need to fix it.

Thanks copilot agent, I found the problem maybe about this code:

elif message.type == ToolInvokeMessage.MessageType.FILE:
meta = message.meta or {}
file = meta.get("file", None)
if isinstance(file, File):
if file.transfer_method == FileTransferMethod.TOOL_FILE:
assert file.related_id is not None
url = cls.get_tool_file_url(tool_file_id=file.related_id, extension=file.extension)
if file.type == FileType.IMAGE:
yield ToolInvokeMessage(
type=ToolInvokeMessage.MessageType.IMAGE_LINK,
message=ToolInvokeMessage.TextMessage(text=url),
meta=meta.copy() if meta is not None else {},
)
else:
yield ToolInvokeMessage(
type=ToolInvokeMessage.MessageType.LINK,
message=ToolInvokeMessage.TextMessage(text=url),
meta=meta.copy() if meta is not None else {},
)
else:
yield message

The tool of workflow as tool return content relate message, and all workflow message will transform by message_transformer.py, at here it will transform file to link, and then when tool_node.py to handle message stream, it will goto message.type == ToolInvokeMessage.MessageType.LINK case, so that this tool files field return nothing.

Metadata

Metadata

Assignees

Labels

🐞 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions