Data Structure
Message Return
Dify supports various message types such astext, links, images, file BLOBs, and JSON. You can return different types of messages through the following interfaces.
By default, a tool’s output in a workflow includes three fixed variables: files, text, and json. You can use the methods below to return data for these three variables.
For example, you can use create_image_message to return an image, but tools also support custom output variables, making it more convenient to reference these variables in a workflow.
Image URL
Simply pass the image URL, and Dify will automatically download the image through the link and return it to the user.Link
If you need to return a link, use the following interface.Text
If you need to return a text message, use the following interface.blobThe raw data of the file, in bytes type.metaThe metadata of the file. If developers need a specific file type, please specifymime_type, otherwise Dify will useoctet/streamas the default type.
JSON
If you need to return a formatted JSON, you can use the following interface. This is typically used for data transmission between nodes in a workflow. In agent mode, most large models can also read and understand JSON.objectA Python dictionary object that will be automatically serialized to JSON.
Variable
For non-streaming output variables, you can use the following interface to return them. If you create multiple instances, the latter will override the former.Streaming Variable
If you want to output text with a “typewriter” effect, you can use streaming variables to output text. If you use ananswer node in a chatflow application and reference this variable, the text will be output with a “typewriter” effect. However, currently this method only supports string type data.
Returning Custom Variables
If you want to reference a tool’s output variables in aworkflow application, it’s necessary to define in advance which variables might be output. Dify plugins support output variable definitions in json_schema format. Here’s a simple example:
output_schema for it, which includes a name field that can be referenced in a workflow. However, please note that you still need to return a variable in the tool’s implementation code to actually use it, otherwise you will get a None return result.
Edit this page | Report an issue