This document provides detailed instructions on how to develop tool plugins for Dify, using Google Search as an example to demonstrate a complete tool plugin development process. The content includes plugin initialization, template selection, tool provider configuration file definition, adding third-party service credentials, tool functionality code implementation, debugging, and packaging for release.
Google Search
as an example to demonstrate how to quickly develop a tool plugin.
dify
and copied it to the /usr/local/bin
path, you can run the following command to create a new plugin project:
In the following text,dify
will be used as a command line example. If you encounter any issues, please replace thedify
command with the path to the command line tool.
Tool
plugin.
If you are already familiar with plugin development and do not need to rely on templates, you can refer to the General Specifications guide to complete the development of different types of plugins.
Use the arrow keys in the terminal to select permissions, and use the “Tab” button to grant permissions.After checking all permission items, press Enter to complete the plugin creation. The system will automatically generate the plugin project code.
/provider
path in the plugin template project and rename the yaml file to google.yaml
. This yaml
file will contain information about the tool provider, including the provider’s name, icon, author, and other details. This information will be displayed when installing the plugin.
Example Code
/tools
directory, with the complete path as follows:
google.yaml
needs to use its absolute path in the plugin project. In this example, it is located in the project root directory. The identity field in the YAML file is explained as follows: identity
contains basic information about the tool provider, including author, name, label, description, icon, etc.
_assets
folder in the project root directory.SerpApi
. SerpApi
requires an API Key for use, so we need to add the credentials_for_provider
field in the yaml
file.
The complete code is as follows:
credentials_for_provider
needs to meet the requirements of General Specifications.tools/google_search.yaml
file.google.py
, but we won’t implement it yet, but instead write the code for google_search
first.yaml
file for description, including basic information about the tool function, parameters, output, etc.
Still using the GoogleSearch
tool as an example, create a new google_search.yaml
file in the /tools
folder.
identity
contains basic information about the tool, including name, author, label, description, etc.parameters
parameter list
name
(required) parameter name, unique, cannot have the same name as other parameters.type
(required) parameter type, currently supports string
, number
, boolean
, select
, secret-input
five types, corresponding to string, number, boolean, dropdown, encrypted input box. For sensitive information, please use the secret-input
type.label
(required) parameter label, for frontend display.form
(required) form type, currently supports llm
, form
two types.
llm
means that the parameter is inferred by the LLM itself, form
means that parameters can be preset in advance to use this tool.llm
and form
need to be filled in by the frontend, but llm
parameters will be used as input variables for the tool node.required
whether required
llm
mode, if the parameter is required, the Agent will be required to infer this parameter.form
mode, if the parameter is required, the user will be required to fill in this parameter on the frontend before the conversation begins.options
parameter options
llm
mode, Dify will pass all options to the LLM, and the LLM can infer based on these options.form
mode, when type
is select
, the frontend will display these options.default
default value.min
minimum value, can be set when the parameter type is number
.max
maximum value, can be set when the parameter type is number
.human_description
introduction for frontend display, supports multiple languages.placeholder
prompt text for the input field, can be set when the form type is form
and the parameter type is string
, number
, secret-input
, supports multiple languages.llm_description
introduction passed to the LLM. To make the LLM better understand this parameter, please write as detailed information as possible about this parameter here, so that the LLM can understand the parameter.google_search.py
in the /tools
directory with the following content:
serpapi
and using self.create_json_message
to return a formatted json
data string. If you want to learn more about return data types, you can refer to the Remote Debugging Plugins and Persistent Storage KV documents.
ToolProviderCredentialValidationError
exception will be thrown. After validation succeeds, the google_search
tool service will be correctly requested.
Create a google.py
file in the /provider
directory with the following content:
.env.example
file and rename it to .env
, then fill in the remote server address and debugging Key information you obtained.
.env
file:
python -m main
command to start the plugin. On the plugins page, you can see that the plugin has been installed in the Workspace, and other members of the team can also access the plugin.
google.difypkg
file in the current folder, which is the final plugin package.