mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
119 lines
5.0 KiB
Plaintext
119 lines
5.0 KiB
Plaintext
---
|
|
dimensions:
|
|
type:
|
|
primary: implementation
|
|
detail: advanced
|
|
level: intermediate
|
|
standard_title: Reverse Invocation Tool
|
|
language: en
|
|
title: Tool
|
|
description: This document details how plugins can reverse invoke Tool services within
|
|
the Dify platform. It covers three types of tool invocation methods calling installed
|
|
tools (Built-in Tool), calling Workflow as Tool, and calling custom tools (Custom
|
|
Tool). Each method includes corresponding entry points and interface parameter descriptions.
|
|
---
|
|
|
|
Reverse invoking a Tool means that a plugin can call other tool-type plugins within the Dify platform. If you are unfamiliar with the basic concepts of reverse invocation, please first read [Reverse Invocation of Dify Services](/plugin-dev-en/9241-reverse-invocation.mdx).
|
|
|
|
Consider the following scenarios:
|
|
|
|
* A tool-type plugin has implemented a function, but the result is not as expected, requiring post-processing of the data.
|
|
* A task requires a web scraper, and you want the flexibility to choose the scraping service.
|
|
* You need to aggregate results from multiple tools, but it's difficult to handle using a Workflow application.
|
|
|
|
In these cases, you need to call other existing tools within your plugin. These tools might be from the marketplace, a self-built Workflow as a Tool, or a custom tool.
|
|
|
|
These requirements can be met by calling the `self.session.tool` field of the plugin.
|
|
|
|
### Calling Installed Tools
|
|
|
|
Allows the plugin to call various tools installed in the current Workspace, including other tool-type plugins.
|
|
|
|
**Entry Point**
|
|
|
|
```python
|
|
self.session.tool
|
|
```
|
|
|
|
**Interface**
|
|
|
|
```python
|
|
def invoke_builtin_tool(
|
|
self, provider: str, tool_name: str, parameters: dict[str, Any]
|
|
) -> Generator[ToolInvokeMessage, None, None]:
|
|
pass
|
|
```
|
|
|
|
Here, `provider` is the plugin ID plus the tool provider name, formatted like `langgenius/google/google`. `tool_name` is the specific tool name, and `parameters` are the arguments passed to the tool.
|
|
|
|
### Calling Workflow as Tool
|
|
|
|
For more information on Workflow as Tool, please refer to the [Tool Plugin documentation](/plugin-dev-en/0222-tool-plugin.mdx). (Note: Original link `/plugin-dev-zh/9223-tool` does not exist in English list, linked to closest match).
|
|
|
|
**Entry Point**
|
|
|
|
```python
|
|
self.session.tool
|
|
```
|
|
|
|
**Interface**
|
|
|
|
```python
|
|
def invoke_workflow_tool(
|
|
self, provider: str, tool_name: str, parameters: dict[str, Any]
|
|
) -> Generator[ToolInvokeMessage, None, None]:
|
|
pass
|
|
```
|
|
|
|
In this case, `provider` is the ID of this tool, and `tool_name` is specified during the creation of the tool.
|
|
|
|
### Calling Custom Tool
|
|
|
|
**Entry Point**
|
|
|
|
```python
|
|
self.session.tool
|
|
```
|
|
|
|
**Interface**
|
|
|
|
```python
|
|
def invoke_api_tool(
|
|
self, provider: str, tool_name: str, parameters: dict[str, Any]
|
|
) -> Generator[ToolInvokeMessage, None, None]:
|
|
pass
|
|
```
|
|
|
|
Here, `provider` is the ID of this tool, and `tool_name` is the `operation_id` from the OpenAPI specification. If it doesn't exist, it's the `tool_name` automatically generated by Dify, which can be found on the tool management page.
|
|
|
|
## Related Resources
|
|
|
|
- [Reverse Invocation of Dify Services](/plugin-dev-en/9241-reverse-invocation.mdx) - Understand the fundamental concepts of reverse invocation
|
|
- [Reverse Invocation App](/plugin-dev-en/9242-reverse-invocation-app.mdx) - Learn how to call Apps within the platform
|
|
- [Reverse Invocation Model](/plugin-dev-en/9242-reverse-invocation-model.mdx) - Learn how to call model capabilities within the platform
|
|
- [Tool Plugin Development Guide](/plugin-dev-en/0211-getting-started-dify-tool.mdx) - Learn how to develop tool plugins
|
|
- [Advanced Tool Plugins](/plugin-dev-en/0222-tool-plugin.mdx) - Learn about advanced features like Workflow as Tool (Note: Original link `/plugin-dev-zh/9223-tool` does not exist in English list, linked to closest match)
|
|
|
|
{/*
|
|
Contributing Section
|
|
DO NOT edit this section!
|
|
It will be automatically generated by the script.
|
|
*/}
|
|
|
|
<CardGroup cols="2">
|
|
<Card
|
|
title="Edit this page"
|
|
icon="pen-to-square"
|
|
href="https://github.com/langgenius/dify-docs-mintlify/edit/main/plugin-dev-en/9242-reverse-invocation-tool.mdx"
|
|
>
|
|
Help improve our documentation by contributing directly
|
|
</Card>
|
|
<Card
|
|
title="Report an issue"
|
|
icon="github"
|
|
href="https://github.com/langgenius/dify-docs-mintlify/issues/new?title=Documentation%20Issue%3A%20reverse-invocation-t&body=%23%23%20Issue%20Description%0A%3C%21--%20Please%20briefly%20describe%20the%20issue%20you%20found%20--%3E%0A%0A%23%23%20Page%20Link%0Ahttps%3A%2F%2Fgithub.com%2Flanggenius%2Fdify-docs-mintlify%2Fblob%2Fmain%2Fplugin-dev-en%2F9242-reverse-invocation-tool.mdx%0A%0A%23%23%20Suggested%20Changes%0A%3C%21--%20If%20you%20have%20specific%20suggestions%20for%20changes%2C%20please%20describe%20them%20here%20--%3E%0A%0A%3C%21--%20Thank%20you%20for%20helping%20improve%20our%20documentation%21%20--%3E"
|
|
>
|
|
Found an error or have suggestions? Let us know
|
|
</Card>
|
|
</CardGroup>
|