Skip to main content

Overview

Before diving into the detailed interface documentation, make sure you have a general understanding of the tool integration process for Dify plugins.

Message Types

Return different types of messages such as text, links, images, and JSON

Variables

Create and manipulate variables for workflow integration

Output Schema

Define custom output variables for workflow references

Data Structure

Message Return

Dify supports various message types such as text, links, images, file BLOBs, and JSON. These messages can be returned through specialized interfaces.
By default, a tool’s output in a workflow includes three fixed variables: files, text, and json. The methods below help you populate these variables with appropriate content.
While you can use methods like create_image_message to return an image, tools also support custom output variables, making it more convenient to reference specific data in a workflow.

Message Types

string
required
URL to an image that will be downloaded and displayed
URL to be displayed as a clickable link
string
required
Text content to be displayed
bytes
required
Raw file data in bytes format
dict
File metadata including:
  • mime_type: The MIME type of the file (e.g., “image/png”)
  • Other metadata relevant to the file
dict
required
Python dictionary to be serialized as JSON
When working with file blobs, always specify the mime_type in the meta dictionary to ensure proper handling of the file. For example: {"mime_type": "image/png"}.

Variables

string
required
Name of the variable to be created or updated
Any/string
required
Value to assign to the variable:
  • For standard variables: Any Python data type
  • For streaming variables: String data only
The streaming variable method (create_stream_variable_message) currently only supports string data. Complex data types cannot be streamed with the typewriter effect.

Custom Output Variables

To reference a tool’s output variables in a workflow application, you need to define which variables might be output. This is done using the JSON Schema format in your tool’s manifest.

Define Output Schema

object
required
The root object defining your tool’s output schema
string
required
Must be “object” for tool output schemas
object
required
Dictionary of all possible output variables
object
Definition for each output variable, including its type and description
Even with an output schema defined, you still need to actually return a variable using create_variable_message() in your implementation code. Otherwise, the workflow will receive None for that variable.

Example Implementation

For complex workflows, you can define multiple output variables and return them all. This gives workflow designers more flexibility when using your tool.

Examples

Complete Tool Implementation

When designing tools, consider both the direct output (what the user sees) and the variable output (what other workflow nodes can use). This separation provides flexibility in how your tool is used.

Edit this page | Report an issue