Files
Chenhe Gu f1f025b75d consolidate plugin dev docs into main structure (#581)
* move files & renames

* rename files and doc entries

* sync develop plugin files

* update group label translations

* some cleanups

* update configs

* update links

* add remote debug doc

* delete redundant slashes and unnecessary notes

* update ja and zh links

---------

Co-authored-by: Riskey <riskey47@dify.ai>
2025-12-04 16:28:47 +08:00

110 lines
3.7 KiB
Plaintext

---
dimensions:
type:
primary: implementation
detail: advanced
level: advanced
standard_title: Reverse Invocation Node
language: en
title: 节点
description: 本文档描述了插件如何在 Dify 平台内反向调用 Chatflow/Workflow 应用节点的功能。主要涵盖两个特定节点 ParameterExtractor 和 QuestionClassifier 的调用方法。文档详细介绍了调用这两个节点的入口、接口参数和示例代码。
---
<Note> ⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考[英文原版](/en/develop-plugin/features-and-specs/advanced-development/reverse-invocation-node)。</Note>
反向调用节点意味着插件可以访问 Dify Chatflow/工作流应用中某些节点的能力。
`Workflow` 中的 `ParameterExtractor` 和 `QuestionClassifier` 节点封装了复杂的提示词和代码逻辑,能够通过 LLM 完成难以用硬编码解决的任务。插件可以调用这两个节点。
### 调用参数提取器节点
#### **入口**
```python
self.session.workflow_node.parameter_extractor
```
#### **接口**
```python
def invoke(
self,
parameters: list[ParameterConfig],
model: ModelConfig,
query: str,
instruction: str = "",
) -> NodeResponse
pass
```
其中,`parameters` 是要提取的参数列表,`model` 符合 `LLMModelConfig` 规范,`query` 是用于参数提取的源文本,`instruction` 提供 LLM 可能需要的任何附加指令。关于 `NodeResponse` 的结构,请参阅此[文档](/zh/develop-plugin/features-and-specs/plugin-types/general-specifications.mdx#noderesponse)。
#### **使用场景**
要从对话中提取人名,可以参考以下代码:
```python
from collections.abc import Generator
from dify_plugin.entities.tool import ToolInvokeMessage
from dify_plugin import Tool
from dify_plugin.entities.workflow_node import ModelConfig, ParameterConfig, NodeResponse # Assuming NodeResponse is importable
class ParameterExtractorTool(Tool):
def _invoke(
self, tool_parameters: dict
) -> Generator[ToolInvokeMessage, None, None]:
response: NodeResponse = self.session.workflow_node.parameter_extractor.invoke(
parameters=[
ParameterConfig(
name="name",
description="name of the person",
required=True,
type="string",
)
],
model=ModelConfig(
provider="langgenius/openai/openai",
name="gpt-4o-mini",
completion_params={},
),
query="My name is John Doe",
instruction="Extract the name of the person",
)
# Assuming NodeResponse has an 'outputs' attribute which is a dictionary
extracted_name = response.outputs.get("name", "Name not found")
yield self.create_text_message(extracted_name)
```
### 调用问题分类器节点
#### **入口**
```python
self.session.workflow_node.question_classifier
```
#### **接口**
```python
def invoke(
self,
classes: list[ClassConfig], # Assuming ClassConfig is defined/imported
model: ModelConfig,
query: str,
instruction: str = "",
) -> NodeResponse:
pass
```
接口参数与 `ParameterExtractor` 一致。最终结果存储在 `NodeResponse.outputs['class_name']` 中。
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
---
[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/en/develop-plugin/features-and-specs/advanced-development/reverse-invocation-node.mdx) | [报告问题](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)