Please copy this prompt and paste it into your Agent. It will assist you in developing Dify plugins, providing best practices and code examples.
Exception: Multiple subclasses of Tool in /path/to/file.py
tools/encrypt.py
can only contain the EncryptTool
class, not both EncryptTool
and DecryptTool
FeatureTool
naming patternutils/
directorytools/
directoryprovider/
directoryImportError: cannot import name 'x' from 'module'. Did you mean: 'y'?
provider/your_plugin.yaml
:
Multiple subclasses of Tool
error:
class AnotherTool(Tool):
Tool
encrypt.py
contains both EncryptTool
and DecryptTool
, keep EncryptTool
and move DecryptTool
to decrypt.py
Exception: Multiple subclasses of Tool in /path/to/file.py
ImportError: cannot import name 'x' from 'module'. Did you mean: 'y'?
tools/new_feature.yaml
tools/new_feature.py
, ensuring one file has only one Tool subclassMultiple subclasses of Tool
error:
class AnotherTool(Tool):
Tool
encrypt.py
contains both EncryptTool
and DecryptTool
, keep EncryptTool
and move DecryptTool
to decrypt.py
class XxxTool(Tool):
definitionprogress.md
in the working/
directory during the first interactionrequirements.txt
open()
, read()
, write()
, etc.)dify plugin init
command to create the basic project structure:
utils/
directory to implement core functionality logic:
helpers.py
that interact with external services or handle complex logic
tools/
directory, for each functionality:
Tool
base class and overriding the _invoke
methodprovider/
directory:
provider/your_plugin.yaml
to add credential definitions_validate_credentials
method in provider/your_plugin.py
.env
file for local testing:
Multiple subclasses of Tool
: Check if tool files contain multiple Tool subclassesImportError: cannot import name
: Check if imported function names are spelled correctlyToolProviderCredentialValidationError
: Check credential validation logicutils/
directorytools/
directoryprovider/
directorycp tools/existing_tool.py tools/new_tool.py
resource
, meta
, plugins
, etc.type
and version
tools
listtools/feature_name.yaml
llm
(extracted by AI) or form
(UI configuration)FeatureTool
pattern, corresponding to the file name.get()
method and provide default values: param = tool_parameters.get("param_name", "")
yield
to return various types of messages~=
to specify dependency version rangesdify_plugin
.get()
method and provide default values: param = tool_parameters.get("param_name", "")
if not param: yield self.create_text_message("Error: Required parameter missing.")
.get()
method, allowing it to return None: optional = tool_parameters.get("optional_param")
if not required_param: return error_message
if optional_param: do_something()
open()
, read()
, write()
, or other direct file operationscat tools/problematic_file.py
cat utils/the_module.py
_validate_credentials
method implementationget()
instead of direct indexing: param = tool_parameters.get("param_name", "")
timeout=10
try/except
to catch exceptions