This document details the development process for Dify’s Agent strategy plugins, including adding Agent strategy fields in the Manifest file, defining Agent providers, and the core steps for implementing Agent strategies. It provides complete example code for getting parameters, invoking models, invoking tools, and generating and managing logs.
plugins.agent_strategies
field in the manifest.yaml
file and also define the Agent provider. Here is an example:
manifest
file have been omitted here. For the detailed format of the Manifest, please refer to the Define Plugin Information via Manifest File document.
agent.yaml
file and fill in the basic Agent provider information.
function_calling.yaml
strategy file is specified.
function_calling.yaml
file:
Tool
standard format, defining four parameters: model
, tools
, query
, and max_iterations
, to implement the most basic Agent strategy. This code allows users to select a model and the tools to use, configure the maximum number of iterations, and finally input a query to start executing the Agent.
model-selector
, and the tool type parameter is a special array[tools]
. The forms obtained in the parameters can be converted using the built-in AgentModelConfig
and list[ToolEntity]
in the SDK.
session.model.invoke()
function in the SDK to invoke the model. You can get the required input parameters from the model.
Example method signature for invoking the model:
model_config
, prompt information prompt_messages
, and tool information tools
.
The prompt_messages
parameter can be invoked using the example code below; the tool_messages
require some conversion.
Please refer to the example code for using invoke model:
self.session.tool.invoke()
to call them. Example method signature for invoking a tool:
provider_type
, provider
, tool_name
, and parameters
. In Function Calling, tool_name
and parameters
are often generated by the LLM. Example code for using invoke tool:
self.session.tool.invoke()
function is a Generator, which means it also needs to be parsed streamingly.
Please refer to the following function for the parsing method:
AgentLogMessage
, which represents a node in the log tree.parent
is passed, it indicates that the node has a parent node.label
will be used to display the log title to the user.start
status as the initial state in the previous step, you can use the finish log interface to change the status.