> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-add-new-agent.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 工具

> 本文档详细介绍了插件如何在 Dify 平台内反向调用工具服务。涵盖三种工具调用方式：调用已安装工具（Built-in Tool）、调用工作流作为工具（Workflow as Tool）以及调用自定义工具（Custom Tool）。每种方式都包含相应的入口点和接口参数说明。

<Note> ⚠️ 本文档由 AI 自动翻译。如有任何不准确之处，请参考[英文原版](/en/develop-plugin/features-and-specs/advanced-development/reverse-invocation-tool)。</Note>

反向调用工具意味着插件可以调用 Dify 平台内的其他工具类型插件。如果您不熟悉反向调用的基本概念，请先阅读[反向调用 Dify 服务](/zh/develop-plugin/features-and-specs/advanced-development/reverse-invocation)。

考虑以下场景：

* 一个工具类型插件实现了某个功能，但结果不如预期，需要对数据进行后处理。
* 某个任务需要网页爬虫，而您希望灵活选择爬取服务。
* 您需要聚合多个工具的结果，但使用工作流应用难以处理。

在这些情况下，您需要在插件中调用其他现有工具。这些工具可能来自市场、自建的工作流作为工具，或自定义工具。

这些需求可以通过调用插件的 `self.session.tool` 字段来满足。

### 调用已安装工具

允许插件调用当前工作区中安装的各种工具，包括其他工具类型插件。

**入口点**

```python theme={null}
    self.session.tool
```

**接口**

```python theme={null}
    def invoke_builtin_tool(
        self, provider: str, tool_name: str, parameters: dict[str, Any]
    ) -> Generator[ToolInvokeMessage, None, None]:
        pass
```

这里，`provider` 是插件 ID 加上工具提供者名称，格式如 `langgenius/google/google`。`tool_name` 是具体的工具名称，`parameters` 是传递给工具的参数。

### 调用工作流作为工具

有关工作流作为工具的更多信息，请参阅[工具插件文档](/zh/develop-plugin/dev-guides-and-walkthroughs/tool-plugin)。

**入口点**

```python theme={null}
    self.session.tool
```

**接口**

```python theme={null}
    def invoke_workflow_tool(
        self, provider: str, tool_name: str, parameters: dict[str, Any]
    ) -> Generator[ToolInvokeMessage, None, None]:
        pass
```

在这种情况下，`provider` 是该工具的 ID，`tool_name` 在创建工具时指定。

### 调用自定义工具

**入口点**

```python theme={null}
    self.session.tool
```

**接口**

```python theme={null}
    def invoke_api_tool(
        self, provider: str, tool_name: str, parameters: dict[str, Any]
    ) -> Generator[ToolInvokeMessage, None, None]:
        pass
```

这里，`provider` 是该工具的 ID，`tool_name` 是 OpenAPI 规范中的 `operation_id`。如果不存在，则是 Dify 自动生成的 `tool_name`，可在工具管理页面找到。

## 相关资源

* [反向调用 Dify 服务](/zh/develop-plugin/features-and-specs/advanced-development/reverse-invocation) - 了解反向调用的基本概念
* [反向调用应用](/zh/develop-plugin/features-and-specs/advanced-development/reverse-invocation-app) - 了解如何调用平台内的应用
* [反向调用模型](/zh/develop-plugin/features-and-specs/advanced-development/reverse-invocation-model) - 了解如何调用平台内的模型能力
* [工具插件开发指南](/zh/develop-plugin/dev-guides-and-walkthroughs/tool-plugin) - 了解如何开发工具插件
* [高级工具插件](/zh/develop-plugin/dev-guides-and-walkthroughs/tool-plugin) - 了解工作流作为工具等高级功能

***

[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/en/develop-plugin/features-and-specs/advanced-development/reverse-invocation-tool.mdx) | [报告问题](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)
