Last updated
Last updated
Agent Strategy Overview
An Agent Strategy is an extensible template that defines standard input content and output formats. By developing specific Agent strategy interface functionality, you can implement various Agent strategies such as CoT (Chain of Thought) / ToT (Tree of Thought) / GoT (Graph of Thought) / BoT (Backbone of Thought), and achieve complex strategies like .
To add Agent strategies in a plugin, add the plugins.agent_strategies
field in the manifest.yaml file and define the Agent provider. Example code:
Some unrelated fields in the manifest file are omitted. For detailed Manifest format, refer to .
Create an agent.yaml file with basic Agent provider information:
Create a function_calling.yaml file to define the Agent strategy code:
Select which model to use
Choose which tools to utilize
Configure the maximum number of iterations
Input a query to start executing the Agent
All these parameters work together to define how the Agent will process tasks and interact with the selected tools and models.
Retrieving Parameters
Based on the four parameters defined earlier, the model type parameter is model-selector, and the tool type parameter is a special array[tools]. The retrieved parameters can be converted using the SDK’s built-in AgentModelConfig and list[ToolEntity].
Invoking the Model
Invoking a specific model is an essential capability of the Agent plugin. Use the session.model.invoke() function from the SDK to call the model. The required input parameters can be obtained from the model.
Example Method Signature for Invoking the Model:
You need to pass the model information (model_config), prompt information (prompt_messages), and tool information (tools). The prompt_messages parameter can be referenced using the example code below, while tool_messages require certain transformations.
Refer to the example code for using invoke model:
Invoking Tools
Invoking tools is also a crucial capability of the Agent plugin. Use self.session.tool.invoke() to call a tool.
Example Method Signature for Invoking a Tool:
Required parameters include provider_type, provider, tool_name, and parameters. Typically, tool_name and parameters are generated by the LLM during Function Calling.
Example Code for Using invoke tool:
The output of the self.session.tool.invoke() function is a Generator, which requires stream parsing.
Refer to the following function for parsing:
Log
To view the Agent's thinking process, besides normal message returns, you can use specialized interfaces to display the entire Agent thought process in a tree structure.
Creating Logs
This interface creates and returns an AgentLogMessage
, which represents a node in the log tree.
If a parent is passed in, it indicates this node has a parent node.
The default status is "Success". However, if you want to better display the task execution process, you can first set the status to "start" to show a "in progress" log, then update the log status to "Success" after the task is completed. This way, users can clearly see the entire process from start to finish.
The label will be used as the log title shown to users.
Completing Logs
You can use the log completion endpoint to change the status if you previously set "start" as the initial status.
Example Implementation
This example demonstrates a simple two-step execution process: first outputting a "Thinking" status log, then completing the actual task processing.
The code format is similar to the standard format and defines four parameters: model
, tools
, query
, and max_iterations
to implement the most basic Agent strategy. This means that users can: