Multi-agent cooperation method and device, electronic equipment and storage medium
By disassembling user tasks into subtasks and selecting the best agent to perform, the problem of low collaboration efficiency of multi-agent systems is solved, and more efficient task execution and better solutions are achieved.
Patent Information
- Application Number
- CN202510239656.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-03-28
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
How to improve the collaboration efficiency of multi-agent systems to meet the needs of complex tasks.
By disassembling the user task into multiple subtasks with high degree of compatibility with the agent, and selecting the optimal agent to perform the subtask based on the description information of the subtask and the output results of the agent, the optimal solution for the user task is finally generated.
It improves the efficiency of multi-agent collaboration, improves the efficiency of user tasks and the quality of solutions.
Smart Images

Figure CN119722003A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a multi-agent collaboration method, device, electronic device and storage medium. Background Art
[0002] With the development of artificial intelligence technology, the traditional single-agent processing method is unable to meet the increasingly complex task requirements. Therefore, multi-agent systems have been widely used in various fields. However, how to use multiple agents to efficiently perform complex tasks has become an urgent problem to be solved. Summary of the invention
[0003] In view of this, an object of the present invention is to provide a multi-agent collaboration method, device, electronic device and storage medium, which can improve the collaboration effect of multiple agents, thereby improving the execution efficiency of user tasks and the quality of solutions.
[0004] In order to achieve the above purpose, the technical solution adopted by the embodiment of the present invention is as follows: In a first aspect, the present invention provides a multi-agent collaboration method, the method comprising: Decompose user tasks into multiple subtasks according to each agent; Determine the optimal agent for each of the subtasks according to the description information of each of the subtasks and the output results of each of the agents performing the subtasks; The solution corresponding to the user task is obtained based on the output results obtained by each of the optimal agents performing the corresponding subtasks.
[0005] In an optional implementation, the step of decomposing the user task into multiple subtasks according to each agent includes: Using a large language model to decompose the user task, a plurality of initial tasks are obtained; Calculating the similarity between each of the initial tasks and each of the intelligent agents to obtain a plurality of first similarities corresponding to each of the initial tasks; When each of the initial tasks has a first similarity that exceeds a first threshold, each of the initial tasks, multiple first similarities corresponding to the initial tasks, description information of the agent and expected output are input into the large language model for optimization to obtain multiple subtasks.
[0006] In an optional implementation, the calculating the similarity between each of the initial tasks and each of the agents to obtain a plurality of first similarities corresponding to each of the initial tasks includes: For each of the initial tasks, obtaining a task vector corresponding to the initial task according to the description information of the initial task; According to the description information and expected output of each of the agents, an agent vector corresponding to the agent is obtained; The similarities between the task vector and each of the agent vectors are calculated respectively to obtain a plurality of first similarities corresponding to the initial task.
[0007] In an optional implementation, determining the optimal agent for each of the subtasks according to the description information of each of the subtasks and the output results of each of the agents executing the subtasks includes: For each of the subtasks, randomly select one of the agents as the target agent; Utilizing the target agent to execute the subtask and obtain an output result; Calculating a second similarity between the output result and the description information of the subtask; When the second similarity exceeds a second threshold, determining the target agent as the optimal agent corresponding to the subtask; When the second similarity does not exceed the second threshold, one is randomly selected from the remaining agents as a new target agent.
[0008] In an optional embodiment, the method further comprises: When all of the second similarities do not exceed the second threshold, determining the voting agent according to the output results corresponding to each of the agents; When there is only one voting agent, the voting agent is used as the optimal agent for the subtask; When there are multiple voting agents, each of the voting agents is determined as a candidate agent in turn; Calculating a third similarity between the expected output of each other agent and the output result of the candidate agent performing the subtask; the other agents are agents in the voting agent except the candidate agent; Calculating a fourth similarity between the description information of each of the other agents and the description information of the subtask; Obtaining a comprehensive pass rate corresponding to the candidate agent according to the third similarity and the fourth similarity corresponding to the candidate agent; The candidate agent with the smallest comprehensive pass rate is determined as the optimal agent for the subtask.
[0009] In an optional implementation manner, obtaining a solution corresponding to the user task according to the output results obtained by each of the optimal agents performing the corresponding subtasks includes: Obtaining a question-answer pair corresponding to the subtask according to the description information of each subtask and the output result obtained by the optimal agent performing the subtask; Determining the contribution of each subtask to the user task according to the question-answer pairs of each subtask and the description information of the user task; Each of the question-answer pairs and the corresponding contribution is input into a large language model, and the output result corresponding to the subtask is optimized according to the contribution to obtain the solution.
[0010] In an optional implementation manner, determining the contribution of each subtask to the user task according to the question-answer pair of each subtask and the description information of the user task includes: Obtaining, according to the description information of each question-answer pair and the user task, an association probability between each subtask and the user task; Sum the association probabilities of the subtasks and the user task to obtain a total probability; The ratio of each associated probability to the total probability is determined as the contribution of each subtask to the user task.
[0011] In a second aspect, the present invention provides a multi-agent collaboration device, the device comprising: The disassembly module is used to disassemble the user task into multiple subtasks according to each agent; A selection module, used to determine the best agent for each subtask according to the description information of each subtask and the output results of each agent performing the subtask; The output module is used to obtain the solution corresponding to the user task according to the output results obtained by each optimal intelligent agent executing the corresponding subtask.
[0012] In a third aspect, the present invention provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the multi-agent collaboration method described in any of the aforementioned embodiments.
[0013] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the multi-agent collaboration method as described in any one of the aforementioned embodiments.
[0014] Compared with the prior art, the multi-agent collaboration method, device, electronic device and storage medium provided by the embodiments of the present invention decomposes the user task into multiple subtasks with high compatibility with the agent based on the multi-agent, effectively improving the rationality of the user task decomposition. At the same time, based on the description information of the subtask and the output results of each agent executing the subtask, the optimal agent is selected for each subtask, and the corresponding subtask is executed by the optimal agent to obtain the output results corresponding to each subtask. The optimal solution corresponding to the user task is generated according to the output results corresponding to each subtask, which effectively improves the collaboration efficiency of the multi-agent, thereby improving the execution efficiency of the user task and the quality of the solution.
[0015] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0017] Figure 1 A flow chart of a multi-agent collaboration method provided by an embodiment of the present invention is shown.
[0018] Figure 2 Another flow chart of the multi-agent collaboration method provided by an embodiment of the present invention is shown.
[0019] Figure 3 A schematic diagram of a process for generating a first similarity provided by an embodiment of the present invention is shown.
[0020] Figure 4 Another flow chart of the multi-agent collaboration method provided by an embodiment of the present invention is shown.
[0021] Figure 5 A block diagram of a multi-agent collaboration device provided by an embodiment of the present invention is shown.
[0022] Figure 6 A block diagram of an electronic device provided by an embodiment of the present invention is shown.
[0023] Icon: 100 - electronic device; 110 - memory; 120 - processor; 130 - communication module; 400 - multi-agent collaboration device; 401 - disassembly module; 402 - optimal selection module; 403 - output module. DETAILED DESCRIPTION
[0024] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0025] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0026] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0027] With the rapid development of Internet technology and computer technology, using a single agent to perform user tasks can no longer meet the increasingly complex task requirements. Multi-agent systems are gradually being applied to various fields of artificial intelligence. How to improve the collaboration efficiency of multi-agents has become a problem of great concern to technicians in this field.
[0028] Based on this, the multi-agent collaboration method and device provided by the embodiment of the present invention decomposes the user task into multiple subtasks with high compatibility with the agent based on the multi-agent, effectively improving the rationality of the user task decomposition. At the same time, based on the description information of the subtask and the output results of each agent executing the subtask, the optimal agent is selected for each subtask, and the corresponding subtask is executed by the optimal agent to obtain the output results corresponding to each subtask. The optimal solution corresponding to the user task is generated according to the output results corresponding to each subtask, which effectively improves the collaboration efficiency of the multi-agent, thereby improving the execution efficiency of the user task and the quality of the solution.
[0029] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0030] Please refer to Figure 1 , Figure 1 A schematic diagram of a multi-agent collaboration method provided by an embodiment of the present invention is shown. The method comprises the following steps: Step S10, breaking down the user task into multiple subtasks according to each agent.
[0031] In the embodiment of the present invention, in order to improve the execution efficiency of user tasks, a task decomposer is used to decompose complex user tasks. Based on the characteristics of multiple agents, the user tasks are decomposed into multiple subtasks so that each subtask can be assigned to a matching agent for execution, thereby improving the execution efficiency and quality of the user tasks.
[0032] Step S20, determining the optimal agent for each subtask based on the description information of each subtask and the output results of each agent executing the subtask.
[0033] In the embodiment of the present invention, each agent is used to perform a subtask and obtain an output result. The description information of the subtask is compared with each output result, and the optimal agent for each subtask is selected from each agent. The optimal agent is the agent that is most suitable for performing the subtask among the agents. The optimal agents corresponding to different subtasks may be the same agent or different agents.
[0034] Step S30, obtaining a solution corresponding to the user task based on the output results obtained by each optimal agent executing the corresponding subtask.
[0035] In the embodiment of the present invention, the optimal agent is used to execute the corresponding subtask to obtain the output result of the subtask, and the output results of each subtask are integrated to obtain the solution corresponding to the user task.
[0036] In summary, the multi-agent collaboration method provided in the embodiment of the present invention decomposes the user task into multiple sub-tasks with high compatibility with the agent based on the multi-agent, which effectively improves the rationality of the user task decomposition. At the same time, based on the description information of the sub-task and the output results of each agent executing the sub-task, the optimal agent is selected for each sub-task, and the corresponding sub-task is executed by the optimal agent to obtain the output results corresponding to each sub-task. The optimal solution corresponding to the user task is generated according to the output results corresponding to each sub-task, which effectively improves the collaboration efficiency of the multi-agent, thereby improving the execution efficiency of the user task and the quality of the solution.
[0037] Optionally, the following is a possible implementation method for how to decompose subtasks. Figure 2 , Figure 1 The sub-steps of step S10 may include: Step S100, using a large language model to decompose user tasks to obtain multiple initial tasks.
[0038] In the embodiment of the present invention, the user task is input into the large language model, and the large language model is instructed to decompose the user task into multiple initial tasks.
[0039] Step S101, calculating the similarity between each initial task and each intelligent agent, and obtaining a plurality of first similarities corresponding to each initial task.
[0040] In the embodiment of the present invention, for each initial task, the similarity between the initial task and each agent is calculated to obtain a plurality of first similarities corresponding to each initial task.
[0041] Optionally, a possible implementation manner is provided below for how to calculate the first similarity corresponding to each initial task. Figure 2 The sub-steps of step S101 may include: For each initial task, the task vector corresponding to the initial task is obtained according to the description information of the initial task; the agent vector corresponding to the agent is obtained according to the description information and expected output of each agent; the similarity between the task vector and each agent vector is calculated respectively to obtain multiple first similarities corresponding to the initial task.
[0042] As a possible implementation, assume that the user task is input into the large language model and decomposed into three initial tasks. Figure 3 For example, the description information of each initial task is input into the word vector model to obtain the task vector corresponding to each initial task. The description information and expected output of each agent are input into the word vector model to obtain the agent vector corresponding to each agent. The similarity is calculated using each task vector and each agent vector in turn to obtain multiple first similarities corresponding to each initial task.
[0043] It should be noted that the similarity can be calculated by common methods such as cosine similarity, Euclidean distance, Manhattan distance, etc., which can be selected according to the actual application scenario and are not limited by the present invention. The description information of the agent is used to characterize the function of the agent, that is, the problem that the agent can handle. The expected output of the agent is used to standardize the format of the output content.
[0044] Step S102, when each initial task has a first similarity exceeding a first threshold, each initial task, multiple first similarities corresponding to the initial task, description information of the agent and expected output are input into the large language model for optimization to obtain multiple subtasks.
[0045] In the embodiment of the present invention, the multiple first similarities of each initial task are sorted in order of size. When the largest first similarity corresponding to the initial task exceeds the first threshold, it means that the initial task is reasonably decomposed and the corresponding intelligent agent can be found to perform the initial task. When the largest first similarity corresponding to the initial task does not exceed the first threshold, it means that the initial task decomposition does not meet the requirements of the first threshold, the decomposition is unreasonable, and the large language model needs to be used to re-decompose the user task until the largest first similarity corresponding to each initial task exceeds the first threshold, and the first stage of decomposition of the user task is completed.
[0046] Each initial task, multiple first similarities corresponding to the initial task, the agents corresponding to the first similarities, the agent's description information and the expected output are input into the large language model together, instructing the large language model to decompose the user task based on agent optimization to obtain multiple subtasks.
[0047] It can be seen that the embodiment of the present invention uses a large language model to decompose the user task into multiple initial tasks that have a high degree of fit with the agent, and then instructs the large language model to optimize and decompose the user task based on the agent, the initial tasks, and the similarity between each initial task and the agent, so as to obtain multiple subtasks to be executed, thereby effectively improving the rationality of the user task decomposition so that the subtasks can be executed more reasonably, thereby improving the execution quality of the user task.
[0048] Optionally, for how to obtain the optimal agent for a subtask, a possible implementation method is provided below. Figure 2 , Figure 1 The sub-steps of step S20 may include: Step S200: for each subtask, randomly select an agent as the target agent.
[0049] In an embodiment of the present invention, when obtaining the optimal agent corresponding to each subtask, an agent can be randomly obtained from multiple agents as a target agent, and the following steps are used to determine whether the target agent is the optimal agent corresponding to the subtask.
[0050] Step S201, use the target agent to execute the subtask and obtain the output result.
[0051] Step S202: Calculate the second similarity between the output result and the description information of the subtask.
[0052] In an embodiment of the present invention, the target agent executes the subtask to obtain a corresponding output result. The output result is input into a word vector model to obtain a result vector corresponding to the output result, and the description information of the subtask is input into the word vector model to obtain a vector corresponding to the subtask. The similarity between the result vector and the vector corresponding to the subtask is calculated to obtain a second similarity.
[0053] Step S203, when the second similarity exceeds the second threshold, the target agent is determined as the optimal agent corresponding to the subtask; When the second similarity exceeds the second threshold, the target agent is determined as the optimal agent corresponding to the subtask, and the optimal agent corresponding to the next subtask is obtained by iteration until the optimal agent corresponding to each subtask is obtained.
[0054] Step S204, when the second similarity does not exceed the second threshold, randomly select one from the remaining agents as a new target agent until the traversal is completed.
[0055] In the embodiment of the present invention, if the second similarity does not exceed the second threshold, it means that the target agent cannot be determined as the optimal agent corresponding to the subtask. A new agent is randomly obtained from the remaining agents as a new target agent. After obtaining the new target agent, return to step S201 and iterate until the optimal agent corresponding to the subtask is determined or all agents are traversed.
[0056] Among them, for each subtask, the remaining agents are the agents in the multi-agents that have not been selected as the target agent. When each agent in the multi-agents has been selected as the target agent, the number of remaining agents corresponding to the subtask is 0, that is, the multi-agents have been traversed based on this subtask.
[0057] It can be seen that the embodiment of the present invention selects the best agent for each subtask by iteratively traversing multiple agents, so as to improve the execution efficiency and quality of the subtask.
[0058] Optionally, when the similarity between each agent and the subtask does not meet the second threshold requirement, a possible implementation method is provided below for determining the optimal agent corresponding to the subtask. Figure 4 , Figure 1 The sub-steps of step S20 may further include: Step S205, when all the second similarities do not exceed the second threshold, the voting agent is determined according to the output results corresponding to each agent.
[0059] In an embodiment of the present invention, when the second similarity between a subtask and all agents does not exceed the second threshold, it means that the optimal agent corresponding to the subtask cannot be selected through the second threshold, and it is necessary to select the optimal agent corresponding to the subtask through multi-agent voting.
[0060] When an agent reports an error when executing a subtask, the error information is recorded in the output result. When an agent reports an error in the output result when executing a subtask, it means that the agent has given up the competition for the best agent. When an agent reports no error in the output result when executing a subtask, it means that the agent can participate in the competition for the best agent. The agent without error information recorded in the output result is determined as the voting agent.
[0061] For example, an agent that calculates weights needs to input structured data, but the subtask does not have structured data. The agent will report an error when executing the subtask. Reporting an error is equivalent to the agent giving up the competition for the best agent, that is, not serving as the voting agent for the subtask.
[0062] Step S206: When there is only one voting agent, the voting agent is used as the optimal agent for the subtask.
[0063] Step S207: when there are multiple voting agents, each voting agent is determined as a candidate agent in turn.
[0064] In the embodiment of the present invention, when there is only one voting agent, the voting agent is determined as the optimal agent for the subtask. When there are multiple voting agents, each voting agent is determined as a candidate agent in turn, and the optimal agent corresponding to the subtask is determined by comparing the comprehensive pass rates of the candidate agents.
[0065] Step S208, calculating the third similarity between the expected output of each other agent and the output result of the candidate agent performing the subtask; the other agents are the agents in the voting agents except the candidate agent.
[0066] Step S209, calculating the fourth similarity between the description information of each other intelligent agent and the description information of the subtask.
[0067] Step S210, obtaining the comprehensive pass rate corresponding to the candidate agent according to the third similarity and the fourth similarity corresponding to the candidate agent.
[0068] In the embodiment of the present invention, it is assumed that there are three voting agents, namely agent A, agent B and agent C. When agent A is a candidate agent, agent B and agent C are other agents; when agent B is a candidate agent, agent A and agent C are other agents; when agent C is a candidate agent, agent A and agent B are other agents. The calculation formula of the comprehensive pass rate is as follows:
[0069] in, Candidate Agent The overall pass rate, Candidate Agent The output results of executing subtasks are shared with other agents The third similarity of the expected output, Candidate Agent Output results of executing subtasks; For other agents Expected output: For other agents The fourth similarity between the description information of the task and the description information of the subtask, k is the number of other agents.
[0070] Step S211, determine the candidate agent with the smallest comprehensive pass rate as the optimal agent for the subtask.
[0071] In the embodiment of the present invention, the voting principle is to calculate the similarity between the description information of the subtask and the description information of other agents, and to calculate the similarity between the output result of executing the subtask and the expected output of other agents. The higher the similarity with other agents, the less suitable the candidate agent is to become the optimal agent of the subtask. Therefore, the candidate agent with the smallest comprehensive pass rate is selected as the optimal agent of the subtask.
[0072] It can be seen that the embodiment of the present invention selects the best agent for each subtask by combining threshold judgment with voting, so as to complete the user task through the efficient collaboration of the best agents. In a multi-agent collaboration system, each agent can participate in the execution of subtasks and vote for other agents, so as to select the best agent for each subtask, thereby further improving the execution efficiency and quality of subtasks.
[0073] Optionally, for a solution on how to output user tasks, the following provides a possible implementation method. Figure 2 , Figure 1 The sub-steps of step S30 may include: Step S300, obtaining the question-answer pair corresponding to the subtask based on the description information of each subtask and the output result obtained by the optimal agent executing the subtask.
[0074] In the embodiment of the present invention, after selecting the optimal agent required for each subtask, the optimal agent executes the corresponding subtask, obtains the output result corresponding to each subtask, and obtains an output result set, such as . The description information of each subtask and the output result corresponding to the subtask form a question-answer pair. For example, the description information of subtask s And the output result The question-answer pairs corresponding to the subtask s , generate question-answer pairs corresponding to all subtasks in the above manner.
[0075] Step S301, determining the contribution of each subtask to the user task based on the question-answer pairs of each subtask and the description information of the user task.
[0076] Step S302: Input each question-answer pair and the corresponding contribution into the large language model, optimize the output results corresponding to the subtask according to the contribution, and obtain a solution.
[0077] In the embodiment of the present invention, the contribution of each subtask's question-answer pair to the user task is calculated, and the contribution is used as the importance ranking weight of the question-answer pair. The question-answer pair and the corresponding contribution are input into the large language model, which instructs the large language model to reorganize and optimize the output results according to the contribution, and obtain the optimal solution corresponding to the user task.
[0078] It can be seen that the embodiment of the present invention uses the description information, output results and user tasks of the subtasks to determine the importance of each subtask to the user task, and uses a large language model to reorganize and optimize the output results of each subtask based on the importance of each subtask, and finally obtains the optimal solution corresponding to the user task, further improving the quality of the solution and the efficiency of acquisition.
[0079] Optionally, a possible implementation method is provided below for how to obtain a solution to a user task. Figure 2 The sub-steps of step S301 may include: According to the description information of each question-answer pair and the user task, the association probability of each subtask and the user task is obtained; the association probability of each subtask and the user task is summed to obtain the total probability; the ratio of each association probability to the total probability is determined as the contribution of each subtask to the user task.
[0080] In the embodiment of the present invention, the calculation formula of contribution is as follows:
[0081] in, is the contribution of subtask t to user task T; is the question-answer pair for subtask t The probability of association with user task T; n is the number of subtasks contained in user task T.
[0082] Association Probability It can be calculated using the joint probability density function of the preset reference strategy / prior distribution. The joint probability density function is as follows:
[0083] Among them, x represents the description information of the user task T; y represents the question-answer pair of the subtask; The mean vector representing x; The mean vector representing y; Characterizes the variance of x; Characterizes the variance of y; is the correlation coefficient, which is used to reflect the degree of linear correlation between x and y; Is a constant.
[0084] In order to more clearly illustrate the multi-agent collaboration method provided by an embodiment of the present invention, the following examples are used for illustration.
[0085] As a possible implementation, a multi-agent center is constructed, which includes multiple agents with different description information to achieve collaborative work among multiple agents. Assume that the multi-agent center includes three agents, namely RAG_agent, sql_agent and csv_agent. Among them, description is the description information of the agent, and expected_output is the expected output of the agent. Specifically, the information of the multi-agent center is as follows: tool_info = { "agents": [ { "name": "RAG_agent", "description": "Enhanced Retrieval Generation; A RAG tool that retrieves relevant text, obtains knowledge / industry standards / data analysis strategies related to user questions, and summarizes and generates answers.", "expected_output": "Based on the retrieved information, RAG_agent will generate a summary or answer directly related to the user's query. This may include factual information, industry standards, or data analysis strategies."}; { "name": "sql_agent", "description": "SQL code writing and execution; a tool that helps users write SQL queries and execute them safely in a specified database environment. Functional description: Query building: Build valid SQL query statements based on the user's natural language requests. Query execution: Safely execute the constructed SQL queries in the specified database environment. Result presentation: Return query results to the user in an easy-to-understand format. Error handling: Handle any errors that may occur during SQL execution and provide useful feedback.", "expected_output": "sql_agent will build SQL queries from the user's input and execute them in a safe environment. It will then return the results in a readable format, or provide error information and correction suggestions if the query fails."}; { "name": "csv_agent", "description": "CSV data analysis; a tool that helps users write Python code to analyze CSV data. Use your programming and language skills to solve problems.", "expected_output": "csv_agent will provide Python code blocks to analyze CSV data based on the user's requirements. This includes collecting necessary information, performing data analysis tasks, and outputting results. The agent ensures that the provided code is complete and can be executed without user modification."} ]}.
[0086] The above multi-agent center is used to perform user tasks. Assume that the user task is to extract the relevant data of the main agricultural product markets in Province A according to the agricultural product market monitoring and early warning analysis method, build a market index analysis system with the help of index analysis method, and generate a large screen for monitoring and early warning of agricultural product market data in Province A according to the provided data dashboard layout information.
[0087] The large language model is used to decompose the user tasks into three initial tasks, namely initial task 1, initial task 2 and initial task 3. Among them, initial task 1 is to extract relevant data of the main agricultural product markets in Province A; initial task 2 is to use index analysis methods to construct market indexes; initial task 3 is to generate a large screen for monitoring and early warning of agricultural product market data in Province A based on the provided data dashboard layout information.
[0088] Since the three initial tasks all have a first similarity that exceeds the first threshold, the three initial tasks, the multiple first similarities corresponding to each initial task, the descriptive information of the agent and the expected output are output to the large language model, instructing agent-based optimization to obtain four subtasks, namely subtask 1, subtask 2, subtask 3 and subtask 4.
[0089] Among them, subtask 1 is to obtain relevant data of the main agricultural product markets in Province A. Construct SQL query statements to extract relevant data of the main agricultural product markets in Province A from the database. Execute SQL queries to obtain data. Subtask 2 is to build a market index analysis system with the help of index analysis methods. Write Python code to perform index analysis on the obtained data. Generate a market index analysis system.
[0090] Subtask 3 is to extract the layout information of the data dashboard template from the knowledge base and select a suitable data dashboard. Subtask 4 is to generate a large screen for monitoring and early warning of agricultural product market data in Province A based on the provided data dashboard layout information. Generate the layout and design of the large screen based on the data dashboard layout information. Display the analysis results and data visualization on the large screen.
[0091] Match the best agent for each subtask. Take subtask 1 as an example. Randomly select an agent to perform subtask 1. Assume that csv_agent is randomly selected as the target agent. Use csv_agent to perform subtask 1 and get the output result. Assume that the output result is to determine the data source, such as public data sets, industry reports, etc. Use the Python code provided by csv_agent to download or read related files. Clean the data and handle missing values, outliers, etc. Extract the required data fields, such as price, transaction volume, date, etc.
[0092] The similarity is calculated based on the output result corresponding to subtask 1 and the description information of subtask 1 to obtain the second similarity. Since the subtask requires writing a SQL statement, the second similarity corresponding to csv_agent does not meet the second threshold requirement. Other agents are traversed to obtain new target agents, and then the new target agents are used to execute subtask 1. If there is an agent that meets the second threshold, the agent is determined as the optimal agent for subtask 1. If there is no agent that meets the second threshold, enter the multi-agent voting stage.
[0093] Since RAG_agent is responsible for knowledge retrieval and generation, it cannot write code and will report an error when executing this task, so RAG_agent gives up voting. According to the new error information in the output results of each agent executing subtask 1, the voting agents are determined to be csv_agent and sql_agent. csv_agent or sql_agent is taken as a candidate agent in turn, and the comprehensive pass rate is calculated based on the expected output of other agents, the third similarity between the output results of the candidate agent executing subtask 1, and the fourth similarity between the description information of subtask 1 and the description information of other agents. The candidate agent with the smallest comprehensive pass rate is determined as the optimal agent for subtask 1.
[0094] According to the above method of selecting the best agent, the best agent for subtask 1 is sql_agent, the best agent for subtask 2 is csv_agent, the best agent for subtask 3 is RAG_agent, and the best agent for subtask 4 is csv_agent.
[0095] Use the optimal agent to perform each subtask and obtain the output results corresponding to each subtask. Among them, the output result of subtask 1 is to use sql_agent to obtain the relevant data of the main agricultural product markets in Province A. SQL query construction: SELECT *FROM market_data WHERE region = 'Province A' AND product_type IN ('Main agricultural products'); execute the query to obtain data.
[0096] The output of subtask 2 is to use csv_agent to perform index analysis on the acquired data and build a market index analysis system.
[0097] Python code: # filename: market_index_analysis.py import pandas as pd # Read data data = pd.read_csv('market_data.csv') # Calculate market index data['market_index'] = data['price']* data['volume'] # Save the results data.to_csv('market_index_result.csv', index=False) Execute the code to generate market index analysis results.
[0098] The output of subtask 3 is to use RAG_agent to retrieve the data dashboard layout information.
[0099] Top: Overview of the agricultural product market in Province A, showing the average price index for the latest date. Middle: The second module, two independent line graphs, the pig price index line graph, and the pig real-time price trend graph; the third module, two independent bar graphs, the aquatic product price index line graph, and the aquatic product real-time price trend graph. The fourth module, two independent line graphs, the vegetable pig price index line graph, and the vegetable real-time price trend graph. The fifth module, two independent double line graphs, the pig and aquatic product price index comparison line graph, and the vegetable and aquatic product price index comparison line graph. Bottom: Data table, listing the price index and real-time price of specific dates for easy reference.
[0100] Chart style: Line chart: clearly mark the date axis, distinguish the two lines of price index and real-time price, and use different colors and markers.
[0101] Color scheme: Use soft but contrasting color combinations, such as dark blue and bright orange, to easily distinguish different categories.
[0102] Legends and titles: Make sure each chart has a clear title and legend that clearly states the meaning of the price index and real-time prices.
[0103] Interactivity and aesthetics: Interactive design: Allow users to select different date ranges through drop-down menus or sliders to dynamically update data in charts and tables.
[0104] Responsive design: Ensure that the dashboard can be displayed well on different devices (desktop, tablet, mobile phone), and automatically adjust the layout to suit the screen size.
[0105] Visual beauty: The overall design is concise and clear, avoiding excessive decoration and ensuring that data presentation is the main focus.
[0106] The output result of subtask 4 is to use CSV_agent to generate a large screen for monitoring and early warning of agricultural product market data in Province A according to the data dashboard layout information.
[0107] Generate large-screen layout and design, and display analysis results and data visualization on the large screen.
[0108] Python code: import matplotlib.pyplot as plt def plot_indices(price_idx, volume_idx): fig, ax = plt.subplots() ax.plot(price_idx, label='Price Index') ax.plot(volume_idx, label='Volume Index') ax.set_title('Market Indices Analysis') ax.legend() plt.show() … Follow the steps below to generate the optimal solution for the user task.
[0109] Step 1: Generate question-answer pairs based on the description information and output results of the subtasks, and determine the contribution of each subtask to the user task based on the description information of the question-answer pairs and the user task. Taking subtask 1 as an example, the question-answer pairs are {[Get the relevant data of the main agricultural product markets in Province A. Construct SQL query statements to extract the relevant data of the main agricultural product markets in Province A from the database. Execute SQL query to obtain data. ], [Use sql_agent to obtain the relevant data of the main agricultural product markets in Province A. SQL query construction: SELECT * FROM market_data WHERE region = 'Province A' AND product_type IN ('Main agricultural products'); Execute query to obtain data]}.
[0110] With the overall task {According to the agricultural product market monitoring and early warning analysis method, extract the relevant data of the main agricultural product market in Province A, use the index analysis method to build a market index analysis system, and generate a large screen for monitoring and early warning of agricultural product market data in Province A based on the provided data dashboard layout information.} Calculate the contribution, if it is 0.22.
[0111] Step 2: Input the question-answer pairs and contribution of each subtask into the large language model for optimized output. For example, input the question-answer pairs and contribution {[Get the relevant data of the main agricultural product markets in Province A. Construct SQL query statements to extract the relevant data of the main agricultural product markets in Province A from the database. Execute SQL query to obtain data], [Use sql_agent to get the relevant data of the main agricultural product markets in Province A. SQL query construction: SELECT * FROM market_data WHERE region = 'Province A' AND product_type IN ('Main agricultural products'); Execute query to obtain data], 0.22;........} into the large language model for optimized output.
[0112] Step 3: Get the optimal solution corresponding to the user task.
[0113] Subtask 1: Obtain relevant data on major agricultural product markets in Province A.
[0114] Objective: Construct SQL query statements to extract relevant data about the main agricultural product markets in Province A from the database, and execute SQL queries to obtain data.
[0115] Solution: Use `sql_agent` to build and execute SQL queries.
[0116] SQL query statement: ```sql SELECT product_name, market_price, transaction_volume, transaction_date FROM agricultural_markets WHERE province = 'Guangdong' AND transaction_date BETWEEN '2024-01-01' AND '2024-12-31'; # Use sql_agent to execute queries and get results results = sql_agent.execute(query) print(results) Subtask 2: Construct a market index analysis system.
[0117] Objective: To conduct index analysis on the acquired data and generate a market index analysis system.
[0118] Solution: Use Python for data analysis and index calculations.
[0119] Python code: ```Python # filename: index_analysis.py import pandas as pd def calculate_indices(df): base_period = df[df['transaction_date'] == 'base_date']# Set the base period price_index = df['market_price'] / base_period['market_price'].values[0] * 100 volume_index = df['transaction_volume'] / base_period['transaction_volume'].values[0] * 100 return price_index, volume_index # Assume that `results` is the data obtained from the database df = pd.DataFrame(results) price_idx, volume_idx = calculate_indices(df) print(price_idx) print(volume_idx) ``` Subtask 3: Extract data dashboard template layout information.
[0120] Objective: Extract data dashboard template layout information from the knowledge base and select the appropriate data dashboard.
[0121] Solution: Use an appropriate method or tool to select a template.
[0122] Subtask 4: Generate a large screen for monitoring and early warning of agricultural product market data in Province A.
[0123] Objective: Generate a large screen for monitoring and early warning of agricultural product market data in Province A based on the provided data dashboard layout information.
[0124] Solution: Use data visualization tools (such as matplotlib, Plotly, etc.) to create large-screen layouts.
[0125] Python code (using matplotlib for simple display): ```Python # filename: generate_dashboard.py import matplotlib.pyplot as plt def plot_indices(price_idx, volume_idx): fig, ax = plt.subplots() ax.plot(price_idx, label='Price Index') ax.plot(volume_idx, label='Trading Volume Index') ax.set_title('Market Index Analysis') ax.legend() plt.show() It can be seen that the embodiment of the present invention uses a large language model to decompose the user task into multiple initial tasks that are highly compatible with the agent, and then instructs the large language model to optimize and decompose the user task based on the agent, the initial task, and the similarity between each initial task and the agent, so as to obtain multiple subtasks to be executed, thereby effectively improving the rationality of the user task decomposition. The optimal agent is selected for each subtask by iteratively traversing and calculating the similarity and collaborative voting, and the corresponding subtask is executed by the optimal agent to obtain the output result corresponding to each subtask. Finally, the output result of the subtask is optimized by using the contribution of each subtask to the user task, and the optimal solution corresponding to the user task is obtained, which effectively improves the collaboration efficiency of multiple agents, thereby improving the execution efficiency of user tasks and the quality of solutions.
[0126] Based on the same inventive concept, the basic principles and technical effects of the multi-agent collaboration device provided in the embodiment of the present invention are the same as those in the above embodiment. For the sake of brief description, for parts not mentioned in this embodiment, reference may be made to the corresponding contents in the above embodiment.
[0127] Please refer to Figure 5 , Figure 5 A block diagram of a multi-agent collaboration device 400 provided in an embodiment of the present invention. The multi-agent collaboration device 400 includes a disassembly module 401, a selection module 402 and an output module 403.
[0128] A decomposition module 401 is used to decompose the user task into multiple subtasks according to each agent; The optimal selection module 402 is used to determine the optimal agent for each subtask based on the description information of each subtask and the output results of each agent performing the subtask; The output module 403 is used to obtain a solution corresponding to the user task based on the output results obtained by each optimal agent executing the corresponding subtask.
[0129] In summary, the multi-agent collaboration device provided in the embodiment of the present invention decomposes the user task into multiple sub-tasks with high compatibility with the agent based on the multi-agent, which effectively improves the rationality of the user task decomposition. At the same time, based on the description information of the sub-task and the output results of each agent executing the sub-task, the optimal agent is selected for each sub-task, and the corresponding sub-task is executed by the optimal agent to obtain the output results corresponding to each sub-task. The optimal solution corresponding to the user task is generated according to the output results corresponding to each sub-task, which effectively improves the collaboration efficiency of the multi-agent, thereby improving the execution efficiency of the user task and the quality of the solution.
[0130] Optionally, the disassembly module 401 is specifically used to use a large language model to disassemble user tasks to obtain multiple initial tasks; calculate the similarity between each initial task and each intelligent agent to obtain multiple first similarities corresponding to each initial task; when each initial task has a first similarity exceeding a first threshold, each initial task, the multiple first similarities corresponding to the initial task, the description information of the intelligent agent and the expected output are input into the large language model for optimization to obtain multiple subtasks.
[0131] Optionally, the disassembly module 401 is specifically used to obtain, for each initial task, a task vector corresponding to the initial task based on the description information of the initial task; obtain an agent vector corresponding to the agent based on the description information and expected output of each agent; and calculate the similarity between the task vector and each agent vector respectively to obtain multiple first similarities corresponding to the initial task.
[0132] Optionally, the optimization module 402 is specifically used to randomly select an agent as a target agent for each subtask; use the target agent to execute the subtask to obtain an output result; calculate the second similarity between the output result and the description information of the subtask; when the second similarity exceeds a second threshold, determine the target agent as the optimal agent corresponding to the subtask; when the second similarity does not exceed the second threshold, randomly select one from the remaining agents as a new target agent.
[0133] Optionally, the optimization module 402 is also used to determine the voting agent according to the output results corresponding to each agent when all the second similarities do not exceed the second threshold; when there is only one voting agent, use the voting agent as the optimal agent for the subtask; when there are multiple voting agents, determine each voting agent as a candidate agent in turn; calculate the third similarity between the expected output of each other agent and the output result of the candidate agent performing the subtask; other agents are agents other than the candidate agent among the voting agents; calculate the fourth similarity between the description information of each other agent and the description information of the subtask; obtain the comprehensive pass rate corresponding to the candidate agent based on the third and fourth similarities corresponding to the candidate agent; and determine the candidate agent with the smallest comprehensive pass rate as the optimal agent for the subtask.
[0134] Optionally, the output module 403 is specifically used to obtain question-answer pairs corresponding to the subtasks based on the description information of each subtask and the output results obtained by the optimal intelligent agent executing the subtask; determine the contribution of each subtask to the user task based on the question-answer pairs of each subtask and the description information of the user task; input each question-answer pair and the corresponding contribution into the large language model, optimize the output results corresponding to the subtask according to the contribution, and obtain a solution.
[0135] Optionally, the output module 403 is specifically used to obtain the association probability between each subtask and the user task based on the description information of each question-answer pair and the user task; sum the association probabilities between each subtask and the user task to obtain the total probability; and determine the ratio of each association probability to the total probability as the contribution of each subtask to the user task.
[0136] Please refer to Figure 6 , is a block diagram of an electronic device 100 provided in an embodiment of the present invention. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, the processor 120, and the communication module 130 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0137] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.
[0138] The processor 120 is used to read / write data or programs stored in the memory 110 and execute corresponding functions. For example, when the computer program stored in the memory 110 is executed by the processor 120, the social dynamics extraction method disclosed in the above embodiments can be implemented.
[0139] The communication module 130 is used to establish a communication connection between the electronic device 100 and other communication terminals through a network, and to send and receive data through the network.
[0140] It should be understood that Figure 6 The structure shown is only a schematic diagram of the structure of the electronic device 100. The electronic device 100 may also include Figure 6 More or fewer components as shown, or with Figure 6 Different configurations shown. Figure 6 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0141] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by the processor 120, the multi-agent collaboration method disclosed in the above embodiments is implemented.
[0142] The embodiment of the present invention further provides a program product, which, when executed by the processor 120, implements the multi-agent collaboration method disclosed in the above embodiments.
[0143] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0144] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0145] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0146] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A multi-agent collaboration method, characterized in that: The method comprises: Decompose user tasks into multiple subtasks according to each agent; Determine the optimal agent for each of the subtasks according to the description information of each of the subtasks and the output results of each of the agents performing the subtasks; The solution corresponding to the user task is obtained based on the output results obtained by each of the optimal agents performing the corresponding subtasks.
2. The multi-agent collaboration method according to claim 1, characterized in that: The user task is decomposed into multiple subtasks according to each agent, including: Using a large language model to decompose the user task, a plurality of initial tasks are obtained; Calculating the similarity between each of the initial tasks and each of the intelligent agents to obtain a plurality of first similarities corresponding to each of the initial tasks; When each of the initial tasks has a first similarity that exceeds a first threshold, each of the initial tasks, multiple first similarities corresponding to the initial tasks, description information of the agent and expected output are input into the large language model for optimization to obtain multiple subtasks.
3. The multi-agent collaboration method according to claim 2, characterized in that: The calculating the similarity between each of the initial tasks and each of the intelligent agents to obtain a plurality of first similarities corresponding to each of the initial tasks includes: For each of the initial tasks, obtaining a task vector corresponding to the initial task according to the description information of the initial task; According to the description information and expected output of each of the agents, an agent vector corresponding to the agent is obtained; The similarities between the task vector and each of the agent vectors are calculated respectively to obtain a plurality of first similarities corresponding to the initial task.
4. The multi-agent collaboration method according to claim 1, characterized in that: Determining the optimal agent for each subtask according to the description information of each subtask and the output result of each agent performing the subtask comprises: For each of the subtasks, randomly select one of the agents as the target agent; Utilizing the target agent to execute the subtask and obtain an output result; Calculating a second similarity between the output result and the description information of the subtask; When the second similarity exceeds a second threshold, determining the target agent as the optimal agent corresponding to the subtask; When the second similarity does not exceed the second threshold, one is randomly selected from the remaining agents as a new target agent.
5. The multi-agent collaboration method according to claim 4, characterized in that: The method further comprises: When all of the second similarities do not exceed the second threshold, determining the voting agent according to the output results corresponding to each of the agents; When there is only one voting agent, the voting agent is used as the optimal agent for the subtask; When there are multiple voting agents, each of the voting agents is determined as a candidate agent in turn; Calculating a third similarity between the expected output of each other agent and the output result of the candidate agent performing the subtask; the other agents are agents in the voting agents other than the candidate agent; Calculating a fourth similarity between the description information of each of the other agents and the description information of the subtask; Obtaining a comprehensive pass rate corresponding to the candidate agent according to the third similarity and the fourth similarity corresponding to the candidate agent; The candidate agent with the smallest comprehensive pass rate is determined as the optimal agent for the subtask.
6. The multi-agent collaboration method according to claim 1, characterized in that: The step of obtaining a solution corresponding to the user task according to the output results obtained by each optimal agent performing the corresponding subtask comprises: Obtaining a question-answer pair corresponding to the subtask according to the description information of each subtask and the output result obtained by the optimal agent performing the subtask; Determining the contribution of each subtask to the user task according to the question-answer pairs of each subtask and the description information of the user task; Each of the question-answer pairs and the corresponding contribution is input into a large language model, and the output result corresponding to the subtask is optimized according to the contribution to obtain the solution.
7. The multi-agent collaboration method according to claim 6, characterized in that: Determining the contribution of each subtask to the user task according to the question-answer pair of each subtask and the description information of the user task includes: Obtaining, according to the description information of each question-answer pair and the user task, an association probability between each subtask and the user task; Sum the association probabilities of the subtasks and the user task to obtain a total probability; The ratio of each associated probability to the total probability is determined as the contribution of each subtask to the user task.
8. A multi-agent collaboration device, characterized in that: The device comprises: The disassembly module is used to disassemble the user task into multiple subtasks according to each agent; A selection module, used to determine the best agent for each subtask according to the description information of each subtask and the output results of each agent performing the subtask; The output module is used to obtain the solution corresponding to the user task according to the output results obtained by each optimal intelligent agent executing the corresponding subtask.
9. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the multi-agent collaboration method described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the multi-agent collaboration method as described in any one of claims 1-7.
Citation Information
Patent Citations
Multi-agent cooperative task allocation strategy and implementation method and system thereof
CN118396337A
Information processing method and device, electronic equipment and storage medium
CN118796472A
Intelligent agent construction and application system based on large language model
CN118966267A
Task processing method and device, intelligent terminal and storage medium
CN119536986A
Cited By
JEDEC state transition diagram question-answer pair generation system and method
CN120688630A
A jelec state transition diagram question and answer pair generation system and method
CN120688630B
Intelligent agent task processing method, equipment, medium and product
CN121599119A
Teaching plan generation method and system based on multi-agent cooperation
CN121683726A
Multi-agent cooperation method and system
CN121787462A