ヒント:ターミナルで dify version コマンドを実行し、バージョン番号が表示されることを確認することで、足場ツールが正常にインストールされたことを確認できます。
1. プラグインテンプレートの初期化
以下のコマンドを実行して、Agentプラグイン開発テンプレートを初期化します。
dify plugin init
表示される指示に従い、必要な情報を入力します。以下のコードのコメントを参考に設定してください。
➜./dify-plugin-darwin-arm64plugininit─╯EditprofileofthepluginPluginname (press Entertonextstep): # プラグイン名を入力Author (press Entertonextstep): # プラグイン作者を入力Description (press Entertonextstep): # プラグインの説明を入力---Selectthelanguageyouwanttouseforplugindevelopment,andpressEntertocontinue,BTW,youneedPython3.12+todevelopthePluginifyouchoosePython.-> python# Python環境を選択go (not supportedyet)---Basedontheabilityyouwanttoextend,wehavedividedthePluginintofourtypes:Tool,Model,Extension,andAgentStrategy.-Tool:It's a tool provider, but not only limited to tools, you can implement an endpoint there, for example, you need both Sending Message and Receiving Message if you are- Model: Just a model provider, extending others is not allowed.- Extension: Other times, you may only need a simple http service to extend the functionalities, Extension is the right choice for you.- Agent Strategy: Implement your own logics here, just by focusing on Agent itselfWhat'smore,wehaveprovidedthetemplateforyou,youcanchooseoneofthembelow:tool-> agent-strategy# Agent戦略テンプレートを選択llmtext-embedding---Configurethepermissionsoftheplugin,useupanddowntonavigate,tabtoselect,afterselection,pressentertofinishBackwardsInvocation:Tools:Enabled: [✔] You can invoke tools inside Dify ifit's enabled # デフォルトで有効Models: Enabled: [✔] You can invoke models inside Dify if it'senabled# デフォルトで有効LLM: [✔] You can invoke LLM models inside Dify ifit's enabled # デフォルトで有効 → Text Embedding: [✘] You can invoke text embedding models inside Dify if it'senabledRerank: [✘] You can invoke rerank models inside Dify ifit's enabled TTS: [✘] You can invoke TTS models inside Dify if it'senabledSpeech2Text: [✘] You can invoke speech2text models inside Dify ifit's enabled Moderation: [✘] You can invoke moderation models inside Dify if it'senabledApps:Enabled: [✘] Ability to invoke apps like BasicChat/ChatFlow/Agent/Workflow etc.Resources:Storage:Enabled: [✘] Persistence storage for the pluginSize:N/AThemaximumsizeofthestorageEndpoints:Enabled: [✘] Ability to register endpoints
プラグインの設定ファイルと機能コードを記述したら、プラグインのディレクトリ内で python -m main コマンドを実行してプラグインを再起動します。次に、プラグインが正常に動作するかどうかをテストする必要があります。Difyのリモートデバッグ機能を利用するには、「プラグイン管理」にアクセスしてデバッグキーとリモートサーバーのアドレスを取得してください。
from dify_plugin.entities.agent import AgentInvokeMessage
from dify_plugin.interfaces.agent import AgentModelConfig, AgentStrategy, ToolEntity
from pydantic import BaseModel
class BasicParams(BaseModel):
maximum_iterations: int
model: AgentModelConfig
tools: list[ToolEntity]
query: str
history_messages: []
history_messages: [UserPromptMessage(role=<PromptMessageRole.USER: 'user'>, content='hello, my name is novice', name=None), AssistantPromptMessage(role=<PromptMessageRole.ASSISTANT: 'assistant'>, content='Hello, Novice! How can I assist you today?', name=None, tool_calls=[])]