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

# 工具

> 从插件中调用已安装工具、Workflow as Tool 和自定义工具

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

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

考虑以下场景：

* 工具类型插件实现了某个功能，但结果不及预期，需要对数据做后处理。
* 任务需要网页爬虫，而你希望灵活选择爬取服务。
* 你需要聚合多个工具的结果，而这在 Workflow 应用中难以处理。

此时，插件需要调用其他现有工具：市场中的工具、自建的 Workflow as Tool，或自定义工具。这些都可通过插件的 `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`**：传递给工具的参数。

## 调用 Workflow as Tool

有关 Workflow as Tool 的更多信息，参见 [工具插件文档](/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`。如果不存在 `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) - 了解 Workflow as Tool 等高级功能
