本文档由 AI 自动翻译。如有任何不准确之处,请参考 英文原版。
插件可反向调用 Dify Chatflow/工作流应用中某些节点的能力。
插件可调用 ParameterExtractor 和 QuestionClassifier 节点。这两个节点封装了复杂的提示词和代码逻辑,借助 LLM 完成难以用硬编码规则解决的任务。
调用参数提取器节点
self.session.workflow_node.parameter_extractor
def invoke(
self,
parameters: list[ParameterConfig],
model: ModelConfig,
query: str,
instruction: str = "",
) -> NodeResponse
pass
parameters:要提取的参数列表。
model:符合 LLMModelConfig 规范。
query:参数提取的源文本。
instruction:LLM 可能需要的附加指令。
关于 NodeResponse 的结构,详见 通用规范定义。
使用场景
以下示例从对话中提取人名:
from collections.abc import Generator
from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage
from dify_plugin.entities.workflow_node import ModelConfig, NodeResponse, ParameterConfig
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",
)
extracted_name = response.outputs.get("name", "Name not found")
yield self.create_text_message(extracted_name)
NodeResponse 是定义在 dify_plugin.entities.workflow_node 中的 Pydantic 模型,包含 process_data、inputs 和 outputs 三个字典字段。提取出的值存放在 response.outputs 中。
调用问题分类器节点
self.session.workflow_node.question_classifier
def invoke(
self,
classes: list[ClassConfig],
model: ModelConfig,
query: str,
instruction: str = "",
) -> NodeResponse:
pass
ClassConfig 同样从 dify_plugin.entities.workflow_node 导出。接口参数与 ParameterExtractor 一致,最终结果存放在 response.outputs["class_name"] 中。Last modified on June 25, 2026