Task execution method and device based on agent and mcp collaborative optimization
By constructing a graph structure and selecting the optimal target hyperedge, the dynamic adaptability and robustness issues in the collaborative operation of multi-agent systems and MCP tools are solved, improving the task execution effect and efficiency, and making it applicable to emergency dispatching in coal mines and smart cities.
Patent Information
- Application Number
- CN202610155988.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-04
- Publication Date
- 2026-05-01
- Estimated Expiration
- 2046-02-04
AI Technical Summary
Existing technologies suffer from insufficient dynamic adaptability and lack of robustness in collaborative operations between multiple agents and model context protocol tools in complex and dynamic scenarios such as underground coal mines and emergency dispatch in smart cities, resulting in low task execution efficiency and success rate.
By constructing a predefined graph structure, obtaining context feature vectors, determining the matching scores of candidate hyperedges, and selecting the optimal target hyperedge to call the MCP tool and agent to execute task instructions, intelligent collaboration between multiple agents and the MCP tool is achieved.
It improves the effectiveness and efficiency of task completion, is applicable to complex and dynamic scenarios such as industrial production collaboration and smart city scheduling, and meets the decision robustness requirements of high-risk scenarios.
Smart Images

Figure CN121636122B_ABST
Abstract
Description
Task execution method and apparatus based on intelligent agent and MCP collaborative optimization Technical Field
[0001] This application relates to the field of intelligent scheduling technology, and in particular to a task execution method and apparatus based on intelligent agent and MCP collaborative optimization. Background Technology
[0002] In complex and dynamic scenarios such as underground coal mines and emergency dispatching in smart cities, the collaborative operation of multi-agent and model context protocol (MCP) tools is the core support for ensuring system safety and improving task execution efficiency. Scenarios such as underground coal mines and emergency dispatching in smart cities have significant characteristics such as high risk, dynamism, and uncertainty: on the one hand, task requirements are constantly adjusted with changes in the environment (such as sudden changes in gas concentration in underground coal mines and changes in resource dispatching requirements after sudden disasters in cities); on the other hand, the agents participating in the collaboration (such as environmental monitoring agents, personnel positioning agents, and equipment control agents) have problems such as fluctuating computational load and unstable communication status, while MCP tools (such as gas sensors and ventilation controllers) face challenges such as changes in availability and fluctuations in response latency.
[0003] To achieve collaboration between multi-agent systems and MCP tools, existing technologies mainly employ fixed-topology collaboration modes and deterministic decision-making models. However, these suffer from two major problems: the dynamic adaptability of static topologies and the lack of robustness in deterministic models. Static topologies cannot introduce alternative resources or supplementary collaborative units in a timely manner, which can easily lead to insufficient collaboration capabilities and directly affect task execution efficiency and success rate. Deterministic models can only output a single point estimation result and cannot quantify the model's own cognitive uncertainty about the prediction result, making it difficult to meet the stringent requirements for decision robustness in high-risk industrial scenarios. Summary of the Invention
[0004] This application aims to at least partially address one of the technical problems in the related art.
[0005] Therefore, the first objective of this application is to propose a task execution method based on the collaborative optimization of agents and MCP, so as to realize intelligent collaboration between multiple agents and MCP tools and efficiently execute tasks.
[0006] The second objective of this application is to propose a task execution device based on intelligent agent and MCP collaborative optimization.
[0007] The third objective of this application is to propose an electronic device.
[0008] The fourth objective of this application is to provide a computer-readable storage medium.
[0009] The fifth objective of this application is to provide a computer program product.
[0010] To achieve the above objectives, the first aspect of this application proposes a task execution method based on intelligent agent and MCP collaborative optimization, comprising:
[0011] Obtain a predefined graph structure, which includes one or more candidate hyperedges for each type of task, and the nodes in the candidate hyperedges are Model Context Protocol (MCP) tools or agents used for task execution;
[0012] Receive task instructions input by the user, and obtain context feature vectors based on the graph structure and the task instructions;
[0013] Based on the context feature vector, determine the matching score of each candidate hyperedge in the graph structure;
[0014] By comparing the matching scores of the candidate superedges, the target superedge is determined from the candidate superedges;
[0015] The task instruction is executed by calling the MCP tool and / or agent corresponding to the target hyperedge to obtain the task execution result.
[0016] To achieve the above objectives, a second aspect of this application proposes a task execution device based on intelligent agent and MCP collaborative optimization, comprising:
[0017] The first acquisition module is used to acquire a predefined graph structure, which includes one or more candidate hyperedges for each type of task, and the nodes in the candidate hyperedges are Model Context Protocol (MCP) tools or agents used for task execution.
[0018] The second acquisition module is used to receive task instructions input by the user and acquire context feature vectors based on the graph structure and the task instructions.
[0019] The third acquisition module is used to determine the matching score of each candidate hyperedge in the graph structure based on the context feature vector.
[0020] The fourth acquisition module is used to compare the matching scores of the candidate hyperedges and determine the target hyperedge from the candidate hyperedges;
[0021] The task execution module is used to call the MCP tool and / or agent corresponding to the target hyperedge to execute the task instructions and obtain the task execution result.
[0022] To achieve the above objectives, a third aspect of this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0023] The memory stores computer-executed instructions;
[0024] The processor executes computer execution instructions stored in the memory to implement the method described in the first aspect embodiment.
[0025] To achieve the above objectives, a fourth aspect of this application provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, are used to implement the method described in the first aspect embodiment.
[0026] To achieve the above objectives, a fifth aspect of this application provides a computer program product that, when executed by a processor, implements the method described in the first aspect embodiment.
[0027] The task execution method and apparatus based on agent and MCP collaborative optimization provided in this application obtain a graph structure constructed by MCP tools and agents for task execution. When a user's task instruction is received, a context feature vector is obtained based on the graph structure and the task instruction. The matching score of each candidate hyperedge in the graph structure is obtained according to the context feature vector. The matching scores of the candidate hyperedges are compared to determine the target hyperedge. The task is executed with the optimal target hyperedge to obtain the task execution result. This realizes intelligent scheduling between multiple MCP tools and multiple agents, improving the task completion effect and efficiency.
[0028] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0029] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:
[0030] Figure 1 is a flowchart illustrating a task execution method based on intelligent agent and MCP collaborative optimization provided in an embodiment of this application;
[0031] Figure 2 is a schematic diagram of a process for obtaining the matching score of candidate superedges according to an embodiment of this application;
[0032] Figure 3 is a logic block diagram of obtaining a quantization matrix provided in an embodiment of this application;
[0033] Figure 4 is a logic flowchart of obtaining a matching score provided in an embodiment of this application;
[0034] Figure 5 is a flowchart illustrating a task execution method based on intelligent agent and MCP collaborative optimization provided in an embodiment of this application;
[0035] Figure 6 is a logic flowchart of a model iterative optimization provided in an embodiment of this application;
[0036] Figure 7 is a logical flowchart of a task execution method based on intelligent agent and MCP collaborative optimization provided in an embodiment of this application;
[0037] Figure 8 is a schematic diagram of a task execution device based on intelligent agent and MCP collaborative optimization provided in an embodiment of this application. Detailed Implementation
[0038] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0039] The following description, with reference to the accompanying drawings, describes a task execution method and apparatus based on intelligent agent and MCP collaborative optimization according to embodiments of this application.
[0040] Figure 1 is a flowchart illustrating a task execution method based on intelligent agent and MCP collaborative optimization provided in an embodiment of this application. As shown in Figure 1, the method includes the following steps:
[0041] S101, obtain the predefined graph structure.
[0042] The graph structure includes one or more candidate hyperedges for each type of task, and the nodes in the candidate hyperedges are Model Context Protocol (MCP) tools or agents used for task execution.
[0043] For example, suppose a set of intelligent agents , As an environmental monitoring agent, Personnel location agent, Device control agent; MCP toolset ,For example For gas sensors, For Ultra-Wideband (UWB) positioning tools, For ventilation equipment controllers; a candidate hyperedge is obtained through collaboration between one or more intelligent agents and the MCP tool. Each candidate hyperedge corresponds to an executable task, such as candidate hyperedges for emergency tasks or candidate hyperedges for routine inspection tasks. Assume the candidate hyperedges... This candidate super-edge corresponds to the task of "gas concentration monitoring and ventilation control". This candidate superedge corresponds to the collaborative unit of the "personnel positioning" task. Including intelligent agents and MCP tools and Candidate hyperedge Including intelligent agents and MCP tools .
[0044] Based on the collaborative relationships among nodes in the candidate hyperedges, the connecting edges between nodes are determined, and the graph structure is constructed based on the connecting edges and nodes.
[0045] S102 receives the task instructions input by the user and obtains the context feature vector based on the graph structure and the task instructions.
[0046] It is understandable that the task instructions input by the user are user-initiated tasks. For example, the task instruction is "The gas concentration in area 3 underground exceeds the standard and needs to be monitored and controlled urgently." Based on this task instruction, the MCP tool and / or intelligent agent are invoked to execute the task instruction.
[0047] Optionally, the MCP tool or agent corresponding to the node can be obtained according to the graph structure, and then the state data of each node can be obtained. The state data of the node is used to reflect information such as whether the node can work and its work efficiency. The state data of the nodes are summarized to obtain the node state vector.
[0048] Optionally, the text information in the task instructions can also be encoded to obtain the instruction feature vector corresponding to the task instructions.
[0049] Furthermore, the node state vector and the instruction feature vector are concatenated and fused to obtain the context feature vector.
[0050] S103, based on the context feature vector, determine the matching score of each candidate hyperedge in the graph structure.
[0051] It is understood that in this embodiment, the context feature vector integrates the text features of node instructions and the state features of nodes in the graph structure. The matching score of each candidate hyperedge is calculated based on the context feature vector. This matching score is used to reflect the benefit of using the current candidate hyperedge to perform the task.
[0052] Optionally, the weight vector corresponding to each candidate hyperedge can be obtained. For example, the weight of the candidate hyperedge can be evaluated based on the historical task execution information of the candidate hyperedge. The better the historical task execution effect, the higher the corresponding weight. Conversely, the worse the historical task execution effect, the lower the corresponding weight.
[0053] In some embodiments, the operation is performed based on the weight of each candidate hyperedge and the current context feature vector. For example, the product of the context feature vector and the weight of the candidate hyperedge is obtained as the matching score. The higher the matching score, the better the historical task execution effect of the corresponding candidate hyperedge, and the more priority is given to selecting the current candidate hyperedge for task execution.
[0054] S104. Compare the matching scores of the candidate superedges to determine the target superedge from the candidate superedges.
[0055] Optionally, the candidate superedge with the highest matching score can be selected as the target superedge.
[0056] S105, invoke the MCP tool and / or agent corresponding to the target hyperedge to execute the task instructions and obtain the task execution result.
[0057] If the target hyperedge is an MCP tool and / or agent, such as "environmental monitoring agent, gas sensor, equipment control agent and ventilation controller", then activate the environmental monitoring agent, gas sensor, equipment control agent and ventilation controller to execute the task instructions input by the user, thereby obtaining the task execution result.
[0058] For example, assuming the input task instruction is "The gas concentration in area 3 underground exceeds the standard, and emergency monitoring and control are required", the process of executing the task instruction through the target super-edge can be as follows: the equipment control agent controls the activation of the corresponding equipment, the environmental monitoring agent and the gas sensor collect the real-time gas concentration in area 3 underground, and the ventilation controller activates the ventilation equipment for ventilation.
[0059] In this embodiment, a graph structure constructed by MCP tools and agents for task execution is obtained. The graph structure includes one or more candidate hyperedges. When a user's task instruction is received, a context feature vector is obtained based on the graph structure and the task instruction. The matching score of each candidate hyperedge in the graph structure is obtained based on the context feature vector. The matching scores of the candidate hyperedges are compared, and the candidate hyperedge with the highest matching score is selected as the target hyperedge. The task is executed with the optimal target hyperedge to obtain the task execution result. This realizes intelligent scheduling between multiple MCP tools and multiple agents, improves the task completion effect and efficiency, and can be widely adapted to various complex and dynamic scenarios such as industrial production collaboration and smart city scheduling.
[0060] Based on the above embodiments, the process of obtaining the matching score of candidate hyperedges will be described. Figure 2 is a schematic flowchart of obtaining the matching score of candidate hyperedges provided by an embodiment of this application. As shown in Figure 2, the method includes the following steps:
[0061] S201, obtain the context feature vector based on the graph structure and task instructions.
[0062] Optionally, in this embodiment, the context feature vector can be obtained by fusing the semantic embedding vector and the state feature vector. For example, the semantic embedding vector and the state feature vector are concatenated to obtain the context feature vector, wherein the semantic embedding vector is obtained by encoding task information, and the state feature vector is a vector obtained by the real-time state information of the nodes in the graph structure.
[0063] In some embodiments, a semantic embedding vector can be obtained based on the task instruction. The semantic embedding vector is a vector after the task information is encoded. For example, assuming the task instruction is "the gas concentration in area 3 underground exceeds the standard and needs to be monitored and controlled urgently", the task instruction is input into the Bidirectional Encoder Representations from Transformers (BERT) model, and the BERT model outputs a 256-dimensional semantic embedding vector.
[0064] In some embodiments, real-time state data of nodes in the graph structure can be obtained, and the real-time state data of the nodes can be weighted and aggregated to obtain a state feature vector. The real-time state data includes, but is not limited to, the real-time computing load of the agent, historical response speed, real-time availability of the MCP tool (such as online or offline) and current response latency, so as to reflect the state of the nodes in the current graph structure in order to improve the accuracy of candidate hyperedge selection.
[0065] Optionally, in this embodiment, the weight feature value of the node in the node weight matrix is used as the aggregation weight of the node; the real-time state data of all nodes in the candidate hyperedge are weighted and aggregated according to the aggregation weight to obtain the aggregation vector; the node quantity feature value of the candidate hyperedge is determined based on the hyperedge cardinality matrix; the ratio of the aggregation vector to the node quantity feature value is calculated to obtain the state feature vector.
[0066] For example, the state data of intelligent agents (e.g., a1 with 60% load and a response time of 0.3 seconds) and MCP tools (e.g., t1 online with a response latency of 0.1 seconds) are first normalized to unify data from different ranges into values between 0 and 1, avoiding large numerical differences that could affect the analysis results. When aggregating the real-time state data of nodes, the weight eigenvalues of the nodes in the node weight matrix are used as the aggregation weights of the nodes. For example, in the node weight matrix... The weighted eigenvalue is 0.8. The weight feature value is 0.5. Based on the aggregation weight, the real-time state data of all nodes in the candidate hyperedge are weighted and aggregated to obtain an aggregation vector. In this embodiment, the aggregated data can be averaged into a 256-dimensional numerical vector to obtain the aggregation vector. During aggregation, the weight features of the nodes are fully considered so that the aggregated vector is more in line with the actual priority of the nodes. After determining the aggregation vector, in order to unify the data dimensions of different candidate hyperedges, the ratio of the aggregation vector to the node number feature value is calculated to avoid errors caused by the different number of nodes in the candidate hyperedges, and a 256-dimensional state feature vector is obtained.
[0067] It is understood that in this embodiment, the context feature vector is obtained by concatenating the semantic embedding vector and the state feature vector, so the context feature vector is a 512-dimensional vector.
[0068] Among them, the node weight matrix and hyperedge cardinality matrix used to obtain the state feature vector are quantization matrices of the graph structure, and specific methods for obtaining them may include:
[0069] (1) Construct an incidence matrix with nodes in the graph structure as rows and each candidate hyperedge as a column. The elements of the incidence matrix indicate whether the corresponding node exists in the candidate hyperedge. For example, if the graph structure includes six nodes and three candidate hyperedges, the six nodes are represented as { , , , , , The three candidate superedges are represented as follows: , and Among them, candidate superedge for{ , , , Candidate hyperedge for{ , Candidate hyperedge for{ , , , The six nodes form the rows of the incidence matrix, and the three candidate hyperedges form the columns, resulting in a 6*3 incidence matrix. Elements in the incidence matrix take values of 0 and 1. A value of 1 indicates that the node is within the corresponding candidate hyperedge, and a value of 0 indicates that the node is not within the corresponding candidate hyperedge. For example, for node... It belongs to the candidate superedge and candidate superedge Then in the correlation matrix OK The elements of the column are all 1s in the association matrix. OK The elements of the column are all 0, in the association matrix OK The elements of the column are all 1; for nodes It does not belong to the candidate hyperedge and Then in the correlation matrix OK The sum of the element values of the column OK All elements in the column have a value of 0.
[0070] (2) The weight of each candidate superedge is obtained based on historical task execution records and professional knowledge. Historical task execution records refer to the task execution records of candidate superedges in the past period. The probability of candidate superedges being activated and the contribution of successful task execution can be obtained. Candidate superedges that have frequently and successfully handled high-value tasks in the past period have higher weights. Professional knowledge refers to the judgment of the priority of the task corresponding to the current candidate superedge by experts in the relevant field based on their professional knowledge and experience. For example, in the field of coal mine safety, experts will clearly point out that the priority of the "emergency response" task is much higher than that of "daily inspection". The higher the priority, the higher the weight of the candidate superedge. In this embodiment, the weight value range is limited to [0, 1]. For example, the candidate superedges corresponding to emergency tasks The weight is 0.8, and the candidate superedges corresponding to daily tasks are... The weight is 0.5, and the candidate hyperedges corresponding to the perception tasks are... The weight is 0.7.
[0071] (3) Determine the set of candidate hyperedges corresponding to each node based on the correlation matrix, and calculate the sum of weights corresponding to the set of candidate hyperedges to obtain the weight feature value of the corresponding node; construct a diagonal matrix based on the weight feature values of all nodes to obtain the node weight matrix of the graph structure.
[0072] For example, suppose the graph structure includes six nodes: { , , , , , }, then the node weight matrix is a 6*6 matrix, and for the first diagonal element, it is a node. The weighted feature value, if the node Belongs to candidate superedge and candidate superedge Then the node The weighted eigenvalues are candidate hyperedges Weights and candidate hyperedges The weights are added together, which is 0.8 + 0.7 = 1.5. If the node Belongs to candidate superedge and candidate superedge Then the corresponding set of candidate hyperedges is the candidate hyperedge set. and candidate superedge ,node The weighted eigenvalues are candidate hyperedges Weights and candidate hyperedges The sum of the weights is 0.5 + 0.7 = 1.2; and so on, the third diagonal element is the node. The weighted feature values, with the fourth diagonal element being the node. The weighted feature values, with the fifth diagonal element being the node. The weighted feature values and the sixth diagonal element are the nodes. The weighted eigenvalues.
[0073] (4) Obtain the number of nodes in each candidate hyperedge and obtain the node number feature value of the candidate hyperedge; construct a diagonal matrix based on the node number feature values of all candidate hyperedges to obtain the hyperedge cardinality matrix of the graph structure. In this embodiment, the node number feature value is the number of nodes in the candidate hyperedge.
[0074] For example, suppose the graph structure includes candidate hyperedges. Candidate hyperedge and candidate superedge Then the hyperedge cardinality matrix is a 3x3 matrix, where the candidate hyperedges are... for{ , , , Candidate hyperedge for{ , Candidate hyperedge for{ , , , }, then the candidate superedge The number of nodes has a feature value of 4, and it is a candidate superedge. The node count feature value is 2, and the candidate superedge is... The number of nodes has a characteristic value of 4, which means that the first diagonal element in the hyperedge cardinality matrix has a value of 4, the second diagonal element has a value of 2, and the third diagonal element has a value of 4.
[0075] Optionally, Figure 3 is a logical block diagram of obtaining a quantization matrix. The association matrix is determined by the attribution relationship between nodes and candidate hyperedges, the weights of candidate hyperedges are obtained, and the node weight matrix and hyperedge cardinality matrix are obtained based on the weights of candidate hyperedges and the association matrix.
[0076] S202, obtain the historical task execution records for each candidate superedge.
[0077] Historical task execution records include at least historical context feature vectors and task execution rewards. Historical context feature vectors refer to the context feature vectors of candidate hyperedges during historical execution, while historical execution rewards reflect the performance of candidate hyperedges in historical task execution. The better the task execution performance, the higher the corresponding execution reward.
[0078] Optionally, the historical task execution records of candidate superedges can be stored in an internal database, and the corresponding records can be read directly from the internal database.
[0079] S203 uses the ridge regression algorithm to obtain the edge weight vector of the corresponding candidate hyperedge based on the historical context feature vector and task execution reward.
[0080] Optionally, in this embodiment, the edge weight vector of the candidate hyperedge is used to reflect the reliability of the current candidate hyperedge in similar scenarios. The calculation formula based on the ridge regression algorithm is expressed as follows:
[0081]
[0082] in, Let be the edge weight vector of the candidate hyperedge; The matrix consisting of the historical context feature vectors of the candidate hyperedges has dimensions of . , The number of historical task execution records. The feature vector dimension is 512 in this embodiment. It is the transpose of the historical context feature vector; Rewards for completing tasks; It is a 512×512 identity matrix; is the regularization parameter for ridge regression, used to avoid overfitting. Its value can be set from 0.01 to 0.1. In this embodiment, it is set to... .
[0083] It should be noted that, in the initial stage of the task, when there are no historical context feature vectors and task execution rewards, the edge weight vectors of all candidate hyperedges are initialized to zero vectors, and the matrix formed by the historical context vectors... Initialize to The identity matrix is multiplied by a small regularization coefficient, for example ,in For the feature vector dimension, As a regularization parameter, this setting ensures that all candidate hyperedges have the same, non-zero exploration reward in the initial stage, enabling the model to conduct a fair initial exploration of all possible trajectories. As the task progresses and historical data accumulates, and It will be iteratively updated based on the actual context vector and task rewards.
[0084] S204. Calculate the estimated reward based on the product of the transpose of the context feature vector and the edge weight vector, and calculate the exploration reward based on the context feature vector and the historical context feature vector.
[0085] Optionally, the estimated reward is a known gain obtained based on the context feature vector and the edge weight vector, and the specific calculation can be expressed as:
[0086]
[0087] in, For the estimated reward; For context feature vectors, It is the transpose of the context feature vector; Let be the edge weight vector of the candidate hyperedge.
[0088] Optionally, the exploration reward is the potential exploration gain obtained based on the context feature vector and the historical context feature vector, and the specific calculation can be expressed as:
[0089]
[0090] in, To explore rewards.
[0091] S205, weighted combination of estimated reward and exploration reward, to obtain the matching score of each candidate superedge in the graph structure.
[0092] Optionally, exploration parameters can be obtained. Based on exploration parameters The exploration reward is weighted and then combined with the estimated reward to obtain the matching score of the candidate superedge. The matching score is expressed as:
[0093]
[0094] in, For candidate hyperedges The matching score.
[0095] In some embodiments, the edge weight vectors of candidate hyperedges can be obtained through a pre-trained linear model, and the estimated reward can be calculated based on the product of the transpose of the context feature vector and the edge weight vector. The exploration reward can be calculated based on the context feature vector and the historical context feature vector. The estimated reward and the exploration reward are weighted and combined to obtain the matching score of each candidate hyperedge in the graph structure.
[0096] For example, the pre-trained linear model can be a Linear Upper Confidence Bound (LinUCB) model. Based on this LinUCB model, the edge weight vectors of candidate hyperedges are calculated, and the estimated reward and exploration reward are calculated based on the context feature vector and the edge weight vector, thereby obtaining the matching score of the candidate hyperedge and improving the efficiency of obtaining the matching score. Figure 4 shows the logical flowchart of obtaining the matching score in this embodiment. After determining the quantization matrix of the graph structure, the real-time state data of the nodes is obtained, and the state feature vector is determined according to the real-time state data and the quantization matrix. The semantic embedding vector is obtained based on the task instruction input by the user. The semantic embedding vector and the state feature vector are concatenated to form the context feature vector. Each candidate hyperedge is traversed and the edge weight vector is obtained through the ridge regression algorithm. The matching score of each candidate hyperedge is obtained according to the context feature vector and the edge weight vector, and the candidate hyperedge with the largest matching score is determined as the optimal target hyperedge. Then, the MCP tool and / or agent in the target hyperedge is called to perform the task. When there is a next task input, the target hyperedge corresponding to the task is obtained based on the same method and the task is performed.
[0097] In this embodiment, during the process of obtaining the matching score, state feature vectors are obtained based on the real-time state data of nodes in the graph structure. When obtaining the state feature vectors, the quantization matrix of the graph structure is used for auxiliary acquisition to improve the accuracy of obtaining the state feature vectors. Semantic embedding vectors are obtained based on task instructions. The semantic embedding vectors and state feature vectors are fused to obtain accurate context feature vectors. Historical task execution records of each candidate hyperedge are obtained. The edge weight vectors of the candidate hyperedges are obtained based on the historical task execution records. The estimated reward and exploration reward of the candidate hyperedge are determined based on at least one of the edge weight vectors and context feature vectors. The final matching score is obtained based on the estimated reward and exploration reward. This matching score fully considers the state of the nodes and the task execution effect of the candidate hyperedges. Based on the matching score, the priority of each candidate hyperedge being selected can be intuitively reflected, improving the efficiency of filtering target hyperedges based on the matching score and the accuracy of target hyperedge selection.
[0098] Based on the above embodiments, Figure 5 is a flowchart illustrating a task execution method based on intelligent agent and MCP collaborative optimization provided by an embodiment of this application. As shown in Figure 5, the method includes the following steps:
[0099] S501, obtain the predefined graph structure.
[0100] In this application embodiment, the implementation method of step S501 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0101] S502 receives task instructions input by the user.
[0102] In this application embodiment, the implementation method of step S502 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0103] S503 obtains the context feature vector based on the graph structure and task instructions.
[0104] In this application embodiment, the implementation method of step S503 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0105] S504: Obtain the historical task execution records for each candidate superedge.
[0106] In this application embodiment, the implementation method of step S504 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0107] S505 uses the ridge regression algorithm to obtain the edge weight vector of the corresponding candidate hyperedge based on the historical context feature vector and task execution reward.
[0108] In this application embodiment, the implementation method of step S505 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0109] S506: Calculate the estimated reward based on the product of the transpose of the context feature vector and the edge weight vector, and calculate the exploration reward based on the context feature vector and the historical context feature vector.
[0110] In this application embodiment, the implementation method of step S506 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0111] S507 calculates a weighted combination of the estimated reward and the exploration reward to obtain the matching score for each candidate superedge in the graph structure.
[0112] In this application embodiment, the implementation method of step S507 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0113] S508: Compare the matching scores of the candidate superedges to determine the target superedge from the candidate superedges.
[0114] In this application embodiment, the implementation method of step S508 can be implemented in any of the various embodiments of this disclosure, and no limitation is made here, nor will it be described in detail.
[0115] S509, invoke the MCP tool and / or agent corresponding to the target hyperedge to execute the task instructions and obtain the task execution result.
[0116] Furthermore, after obtaining the task execution result, task execution data can be obtained, including but not limited to core task data such as task progress rate, communication resource consumption, and time resource consumption; the task progress rate, communication resource consumption, and time resource consumption are weighted and calculated to obtain the basic task reward.
[0117] Optionally, the calculation of the basic task reward is expressed as follows:
[0118]
[0119] in, Basic rewards for the task; This is the task progress rate, used to reflect whether the task has met the target. For example, if the gas concentration drops from 1.2% to 0.8%, the target has not been fully met. This represents the consumption of communication resources, used to reflect the overhead of task communication, and is a quantified value of the amount of data transmitted. This refers to the consumption of time resources, which is a quantitative value of the time taken to execute a task. , and These are the weighting coefficients corresponding to task progress rate, communication resource consumption, and time resource consumption, for example... , , (satisfy ).
[0120] In some embodiments, multiple sets of sampled model parameters of the Bayesian Hypergraph Network (B-HCN) model can be obtained, and the B-HCN model performs multiple task feature predictions under each set of sampled model parameters to obtain task prediction results. Specifically, the association matrix of the graph structure and the current state data of the nodes in the graph structure can be obtained; the association matrix and the current state data are input into the B-HCN model, and the hypergraph convolutional layer of the B-HCN model fuses the association matrix and the current state data into collaborative features; the B-HCN model under different sampled model parameters performs task feature prediction based on the collaborative features to obtain task prediction results.
[0121] In this embodiment, the method for obtaining multiple sets of sampled model parameters can employ Monte Carlo sampling, for example, from the posterior distribution of parameters in the B-HCN model. M independent samples are performed. In this embodiment, M is 50, resulting in 50 sets of sampled model parameters. Substituting the parameters of the 50 sampled models into the B-HCN model, we obtained the task prediction results for 50 task features. Each task prediction result is expressed as follows: .
[0122] The B-HCN model predicts based on the collaborative structure between MCP tools or agents in the correlation matrix, and combines the analysis of current state data to predict task features. For example, in this embodiment, the task feature is gas concentration. The B-HCN model under different sampling model parameters predicts the gas concentration 10 minutes later, thus obtaining 50 task prediction results for "gas concentration 10 minutes later".
[0123] It is understandable that in this embodiment, the correlation matrix is used to define the analysis scope of the B-HCN model, determining that a certain MCP tool and agent belong to the same candidate hyperedge. A particular MCP tool and agent cannot be considered independently during prediction; when the candidate hyperedge changes, the prediction logic of the corresponding B-HCN model is completely different. The current state data of the nodes in the graph structure is the real-time performance data of the MCP tools or agents in the candidate hyperedge, used to inform the B-HCN model of the data processing speed and operating efficiency of the current node, thus affecting the final gas concentration prediction result. The correlation matrix and the current state data are fused into a collaboration feature, used to represent "who collaborates with whom" and "who collaborates well or poorly with whom." This collaboration feature serves as the core basis for task prediction, thereby enabling multiple predictions based on the B-HCN model under different sampling model parameters, resulting in multiple sets of final task prediction results.
[0124] Furthermore, the risk perception reward can be determined based on the basic task reward and the task prediction results; specifically, the task volatility index can be determined based on the variance of the task prediction results under different sampling model parameters; in this embodiment, the task volatility index is the variance of the task prediction results under different sampling model parameters, expressed as:
[0125]
[0126] in, The variance of the task prediction results is also known as the task volatility index. The larger the variance, the higher the volatility / risk of the task results. For example, the gas concentration data fluctuates. The number of parameters in the sampling model; This represents the task prediction result under the j-th group of sampled model parameters; This represents the average value of the task prediction results under the parameters of the M sampled models.
[0127] Furthermore, a weighted calculation is performed on the basic task reward and the task volatility indicator to obtain the risk perception reward. The calculation of the risk perception reward is expressed as follows:
[0128]
[0129] in, Rewards for risk perception; Basic rewards for the task; For task fluctuation indicators; The weights for task volatility indicators are used to adapt to the risk avoidance needs of high-risk scenarios, for example... =0.2.
[0130] Furthermore, the linear model is iteratively optimized based on risk-perceived rewards. The optimized linear model is used to obtain the matching score of candidate hyperedges for the next task. It can be understood that the risk-perceived rewards include the basic task reward reflecting the task completion effect and the task fluctuation index reflecting the fluctuation of the task result. The linear model is iteratively optimized based on the risk-perceived rewards, using the risk-perceived rewards as a "feedback signal". The linear model will update its own weight vector and historical data according to the risk-perceived rewards. When selecting candidate hyperedges in the future, it will prioritize the trajectory with "higher risk-perceived rewards", that is, the optimal solution of "good effect + low risk", thereby realizing the iterative update of the linear model and making the process of obtaining matching scores based on the linear model more accurate.
[0131] Specifically, in the process of optimizing the linear model, the context feature vector corresponding to the task execution result can be updated to the historical context feature vector set, and the risk perception reward can be updated to the historical task execution reward set of the candidate superedge. The linear model is iteratively optimized with the updated historical context feature vector set and historical task execution reward set. The linear model can recalculate the edge weight vector of the candidate superedge according to the updated data, that is, let the model remember the performance of this task, so as to improve the accuracy of the next task decision.
[0132] In some embodiments, the B-HCN model can be iteratively updated. For example, the trajectory data of the current task execution can be added to the training set of the B-HCN model. The task execution trajectory data includes, but is not limited to, the target hyperedge used during task execution and the task execution results (such as gas concentration changes, ventilation volume adjustment records), etc. If the accumulated trajectory data does not reach the quantity threshold, data collection continues. When the data in the training set reaches the quantity threshold, the posterior distribution of the parameters of the B-HCN model is optimized using variational inference. This improves the accuracy of the model's quantification of "task fluctuation indicators".
[0133] Understandably, the updated linear model and B-HCN model are continued to be used for task execution and reward acquisition. Upon receiving the next task instruction, analysis is performed based on the optimized linear model and B-HCN model, which have better performance. After the analysis, the linear model and B-HCN model are iteratively optimized to achieve an adaptive closed loop and improve task execution efficiency. Figure 6 shows the logical flowchart of model iterative optimization in this embodiment. After calling the MCP tool and / or agent in the target hyperedge to execute the task, task execution data is collected to calculate the basic task reward, and the association is input into the B-HCN model. The system obtains current state data of matrices and nodes, acquires multiple sets of sampled model parameters based on the B-HCN model, obtains multiple sets of task prediction results based on these parameters, acquires task fluctuation indicators based on these prediction results, and obtains risk perception rewards by combining the task fluctuation indicators with the basic task rewards. Based on these risk perception rewards, the system optimizes and iterates the linear model and the B-HCN model, outputting risk perception rewards, updated model files, and a decision evaluation report. The system then continues the execution analysis of the next task based on the optimized and iterated model, and continues iterative optimization of the model after the next task is completed, thereby significantly improving task execution performance.
[0134] In this embodiment, upon receiving a user's task instruction, the state feature vector and semantic embedding vector are obtained based on the graph structure and the task instruction, respectively, to obtain an accurate context feature vector. Based on at least one of the edge weight vector and context feature vector of the candidate hyperedge, a more accurate matching score for the candidate hyperedge is obtained. The candidate hyperedge with the highest matching score is selected as the target hyperedge, improving the efficiency and accuracy of selecting the target hyperedge based on the matching score. The task is then executed using the optimal target hyperedge to obtain the task execution result. Furthermore, after task execution, task execution data can be obtained to acquire the basic task reward. A risk perception reward is obtained by combining the task fluctuation index and the basic task reward. The linear model used to acquire the matching score is iteratively optimized based on the risk perception reward, enabling the linear model to obtain a more accurate matching score through continuous optimization and learning. This achieves intelligent scheduling between multiple MCP tools and multiple agents, while improving task completion effect and efficiency. The model is continuously optimized and learned as the task is executed, making it widely adaptable to various complex and dynamic scenarios such as industrial production collaboration and smart city scheduling, fully meeting the requirements for decision-making safety and reliability in high-risk scenarios.
[0135] Figure 7 is a logical flowchart of a task execution method based on agent and MCP collaborative optimization provided in an embodiment of this application. The input layer defines node entities based on domain knowledge / historical data, agent attribute information, MCP tool attribute information, user-input task instructions, and real-time status data. It then constructs a graph structure based on nodes and candidate hyperedges and obtains a set of quantized matrices for the graph structure, such as the association matrix, node weight matrix, and hyperedge cardinality matrix in this embodiment. It constructs a context feature vector based on the task instructions and graph structure, obtains the edge weight vector for each candidate hyperedge, and calculates the matching score of the candidate hyperedge based on the context feature vector and edge weight vector. The candidate hyperedge with the highest score is selected as the target hyperedge, and the MCP tool in the target hyperedge is activated and invoked. The system either executes tasks using an agent or a smart agent, obtains task execution results, acquires task execution data after task execution to obtain basic task rewards, and obtains task fluctuation indicators based on the B-HCN model. It then combines the basic task rewards and task fluctuation indicators to obtain risk perception rewards, thereby optimizing and updating the B-HCN model and LinUCB model based on the risk perception rewards for the next round of task execution. It can also output a risk assessment report for this task execution and the optimal target hyperedge solution. After the next round of execution, it continues to optimize and update the B-HCN model and LinUCB model in a closed loop, thereby fully improving the efficiency and effectiveness of target task execution.
[0136] To achieve the above embodiments, this application also proposes a task execution device based on intelligent agent and MCP collaborative optimization.
[0137] Figure 8 is a schematic diagram of a task execution device based on intelligent agent and MCP collaborative optimization provided in an embodiment of this application. As shown in Figure 8, the task execution device 800 based on intelligent agent and MCP collaborative optimization includes:
[0138] The first acquisition module 801 is used to acquire a predefined graph structure, which includes one or more candidate hyperedges for each type of task. The nodes in the candidate hyperedges are Model Context Protocol (MCP) tools or agents used for task execution.
[0139] The second acquisition module 802 is used to receive the task instructions input by the user and obtain the context feature vector according to the graph structure and the task instructions;
[0140] The third acquisition module 803 is used to determine the matching score of each candidate hyperedge in the graph structure based on the context feature vector;
[0141] The fourth acquisition module 804 is used to compare the matching scores of candidate hyperedges and determine the target hyperedge from the candidate hyperedges;
[0142] The task execution module 805 is used to call the MCP tool and / or agent corresponding to the target hyperedge to execute task instructions and obtain task execution results.
[0143] Furthermore, in one possible implementation of this application embodiment, the second acquisition module 802 is used for:
[0144] Obtain the set of quantization matrices for the graph structure. The set of quantization matrices shall include at least the node weight matrix and the hyperedge cardinality matrix.
[0145] Obtain real-time status data of nodes in a graph structure;
[0146] Based on the node weight matrix and the hyperedge cardinality matrix, the real-time state data of the nodes are weighted and aggregated to obtain the state feature vector;
[0147] Obtain the semantic embedding vector according to the task instructions;
[0148] The semantic embedding vector and the state feature vector are fused to obtain the context feature vector.
[0149] Furthermore, in one possible implementation of this application embodiment, the second acquisition module 802 is used for:
[0150] Construct an association matrix with nodes in the graph structure as rows and each candidate hyperedge as a column. The elements of the association matrix indicate whether the corresponding node exists in the candidate hyperedge.
[0151] The weight of each candidate superedge is obtained based on historical task execution records and professional knowledge;
[0152] Based on the correlation matrix, determine the set of candidate hyperedges corresponding to each node, and calculate the sum of the weights of the candidate hyperedge sets to obtain the weight feature value of the corresponding node.
[0153] Construct a diagonal matrix based on the weight eigenvalues of all nodes to obtain the node weight matrix of the graph structure;
[0154] Obtain the number of nodes in each candidate hyperedge to get the node count feature value of the candidate hyperedge;
[0155] Construct a diagonal matrix based on the node count eigenvalues of all candidate hyperedges to obtain the hyperedge cardinality matrix of the graph structure.
[0156] Furthermore, in one possible implementation of this application embodiment, the second acquisition module 802 is used for:
[0157] The weight eigenvalues of the nodes in the node weight matrix are used as the aggregate weights of the nodes;
[0158] The real-time state data of all nodes in the candidate hyperedge are weighted and aggregated according to the aggregation weight to obtain the aggregation vector;
[0159] The node count feature value of candidate hyperedges is determined based on the hyperedge cardinality matrix;
[0160] The state feature vector is obtained by calculating the ratio of the aggregation vector to the node number feature value.
[0161] Furthermore, in one possible implementation of this application embodiment, the third acquisition module 803:
[0162] Obtain the historical task execution record for each candidate superedge. The historical task execution record includes at least the historical context feature vector and the task execution reward.
[0163] Based on historical context feature vectors and task execution rewards, the edge weight vectors of corresponding candidate hyperedges are obtained through ridge regression algorithm;
[0164] The estimated reward is calculated based on the product of the transpose of the context feature vector and the edge weight vector, and the exploration reward is calculated based on the context feature vector and the historical context feature vector.
[0165] The estimated reward and the exploration reward are weighted and combined to obtain the matching score for each candidate superedge in the graph structure.
[0166] Furthermore, in one possible implementation of this application embodiment, the third acquisition module 803 is further configured to:
[0167] The edge weight vectors of candidate hyperedges are obtained through a pre-trained linear model. The estimated reward is calculated by multiplying the transpose of the context feature vector with the edge weight vector. The exploration reward is calculated based on the context feature vector and the historical context feature vector. The estimated reward and the exploration reward are weighted and combined to obtain the matching score of each candidate hyperedge in the graph structure.
[0168] Furthermore, in one possible implementation of this application embodiment, the task execution module 805 is further configured to:
[0169] In response to obtaining the task execution result, acquire task execution data, including but not limited to task progress rate, communication resource consumption, and time resource consumption;
[0170] The task's basic reward is obtained by weighting the task progress rate, communication resource consumption, and time resource consumption.
[0171] Multiple sets of sampled model parameters of the Bayesian Hypergraph Convolutional Network (B-HCN) model are obtained, and the B-HCN model performs multiple task feature predictions under each set of sampled model parameters to obtain the task prediction results.
[0172] The risk perception reward is determined based on the basic task reward and the task prediction results.
[0173] The linear model is iteratively optimized based on risk-perceived rewards. The optimized linear model is then used to obtain the matching score of candidate hyperedges for the next task.
[0174] Furthermore, in one possible implementation of this application embodiment, the task execution module 805 is used for:
[0175] Obtain the association matrix of the graph structure and the current state data of the nodes in the graph structure;
[0176] The association matrix and current state data are input into the B-HCN model, and the hypergraph convolutional layer of the B-HCN model fuses the association matrix and current state data into collaborative features.
[0177] The B-HCN model under different sampling model parameters predicts task features based on collaborative features and obtains task prediction results.
[0178] Furthermore, in one possible implementation of this application embodiment, the task execution module 805 is used for:
[0179] Based on the variance of task prediction results under different sampling model parameters, a task fluctuation index is determined.
[0180] The risk perception reward is obtained by weighting the basic task reward and the task fluctuation index.
[0181] Furthermore, in one possible implementation of this application embodiment, the task execution module 805 is used for:
[0182] Update the context feature vector corresponding to the task execution result to the historical context feature vector set, and update the risk perception reward to the historical task execution reward set of the candidate superedge;
[0183] The linear model is iteratively optimized using the updated set of historical context feature vectors and the set of historical task execution rewards.
[0184] It should be noted that the foregoing explanation of the task execution method embodiment based on agent and MCP collaborative optimization also applies to the task execution device based on agent and MCP collaborative optimization in this embodiment, and will not be repeated here.
[0185] In this embodiment, upon receiving a user's task instruction, the state feature vector and semantic embedding vector are obtained based on the graph structure and the task instruction, respectively, to obtain an accurate context feature vector. Based on at least one of the edge weight vector and context feature vector of the candidate hyperedge, a more accurate matching score for the candidate hyperedge is obtained. The candidate hyperedge with the highest matching score is selected as the target hyperedge, improving the efficiency and accuracy of selecting the target hyperedge based on the matching score. The task is then executed using the optimal target hyperedge to obtain the task execution result. Furthermore, after task execution, task execution data can be obtained to acquire the basic task reward. A risk perception reward is obtained by combining the task fluctuation index and the basic task reward. The linear model used to acquire the matching score is iteratively optimized based on the risk perception reward, enabling the linear model to obtain a more accurate matching score through continuous optimization and learning. This achieves intelligent scheduling between multiple MCP tools and multiple agents, while improving task completion effect and efficiency. The model is continuously optimized and learned as the task is executed, making it widely adaptable to various complex and dynamic scenarios such as industrial production collaboration and smart city scheduling, fully meeting the requirements for decision-making safety and reliability in high-risk scenarios.
[0186] To implement the above embodiments, this application also proposes an electronic device, including: a processor and a memory communicatively connected to the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to implement the method provided in the foregoing embodiments.
[0187] To implement the above embodiments, this application also proposes a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the methods provided in the foregoing embodiments.
[0188] To implement the above embodiments, this application also proposes a computer program product, including a computer program that, when executed by a processor, implements the methods provided in the foregoing embodiments.
[0189] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in this application all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0190] It should be noted that personal information collected from users should be used for legitimate and reasonable purposes and should not be shared or sold outside of these legitimate uses. Furthermore, such collection / sharing should only be conducted after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign an agreement / authorization that includes authorization of relevant user information before the user uses the function. In addition, any necessary steps must be taken to protect and safeguard access to such personal information data and ensure that others with access to personal information data comply with their privacy policies and procedures.
[0191] This application is intended to provide an implementation scheme for users to selectively prevent the use or access to their personal information data. Specifically, this disclosure is intended to provide hardware and / or software to prevent or block access to such personal information data. Once personal information data is no longer needed, risks can be minimized by restricting data collection and deleting data. Furthermore, where applicable, such personal information is de-identified to protect user privacy.
[0192] In the foregoing descriptions of the embodiments, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0193] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0194] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0195] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0196] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0197] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0198] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0199] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.
Claims
1. A task execution method based on intelligent agent and MCP collaborative optimization, characterized in that, include: Obtain a predefined graph structure, which includes one or more candidate hyperedges for each task type, where the nodes in the candidate hyperedges are Model Context Protocol (MCP) tools or agents used for task execution; receive task instructions input by the user, and obtain context feature vectors based on the graph structure and the task instructions; determine the matching score of each candidate hyperedge in the graph structure based on the context feature vectors; compare the matching scores of the candidate hyperedges, and determine the target hyperedge from the candidate hyperedges. The task instruction is executed by calling the MCP tool and / or agent corresponding to the target hyperedge to obtain the task execution result; wherein, obtaining the context feature vector based on the graph structure and the task instruction includes: obtaining a set of quantization matrices for the graph structure, the set of quantization matrices including at least a node weight matrix and a hyperedge cardinality matrix; obtaining real-time state data of nodes in the graph structure; weighting and aggregating the real-time state data of the nodes according to the node weight matrix and the hyperedge cardinality matrix to obtain a state feature vector; obtaining a semantic embedding vector according to the task instruction; fusing the semantic embedding vector with the state feature vector to obtain the context feature vector; the step of obtaining the context feature vector based on the above The following feature vector is used to determine the matching score of each candidate hyperedge in the graph structure, including: obtaining the historical task execution record of each candidate hyperedge, wherein the historical task execution record includes at least a historical context feature vector and a task execution reward; obtaining the edge weight vector of the corresponding candidate hyperedge using the ridge regression algorithm based on the historical context feature vector and the task execution reward; calculating the estimated reward based on the product of the transpose of the context feature vector and the edge weight vector, and calculating the exploration reward based on the context feature vector and the historical context feature vector; and weighting the estimated reward and the exploration reward to obtain the matching score of each candidate hyperedge in the graph structure.
2. The method according to claim 1, characterized in that, The step of obtaining the quantization matrix set of the graph structure includes: constructing an association matrix with nodes in the graph structure as rows and each candidate hyperedge as a column, wherein the elements of the association matrix indicate whether the corresponding node exists in the candidate hyperedge; obtaining the weight of each candidate hyperedge based on historical task execution records and professional knowledge; determining the candidate hyperedge set corresponding to each node based on the association matrix, and calculating the sum of the weights corresponding to the candidate hyperedge set to obtain the weight feature value of the corresponding node; constructing a diagonal matrix based on the weight feature values of all nodes to obtain the node weight matrix of the graph structure; obtaining the number of nodes in each candidate hyperedge to obtain the node number feature value of the candidate hyperedge; and constructing a diagonal matrix based on the node number feature values of all candidate hyperedges to obtain the hyperedge cardinality matrix of the graph structure.
3. The method according to claim 2, characterized in that, The step of weighted aggregation of the real-time state data of the nodes based on the node weight matrix and the hyperedge cardinality matrix to obtain a state feature vector includes: using the weight feature values of the nodes in the node weight matrix as the aggregation weights of the nodes; weighted aggregation of the real-time state data of all nodes in the candidate hyperedge based on the aggregation weights to obtain an aggregation vector; determining the node quantity feature value of the candidate hyperedge based on the hyperedge cardinality matrix; and calculating the ratio of the aggregation vector to the node quantity feature value to obtain the state feature vector.
4. The method according to any one of claims 1-3, characterized in that, The process of determining the matching score of the candidate hyperedge further includes: obtaining the edge weight vector of the candidate hyperedge through a pre-trained linear model, calculating the estimated reward based on the product of the transpose of the context feature vector and the edge weight vector, calculating the exploration reward based on the context feature vector and the historical context feature vector, and weighting the estimated reward and the exploration reward to obtain the matching score of each candidate hyperedge in the graph structure.
5. The method according to claim 4, characterized in that, The method further includes: in response to obtaining a task execution result, acquiring task execution data, the task execution data including task progress rate, communication resource consumption, and time resource consumption; performing a weighted calculation on the task progress rate, the communication resource consumption, and the time resource consumption to obtain a basic task reward; acquiring multiple sets of sampled model parameters of a Bayesian Hypergraph Convolutional Network (B-HCN) model, and performing multiple task feature predictions by the B-HCN model under each set of sampled model parameters to obtain a task prediction result; determining a risk-aware reward based on the basic task reward and the task prediction result; iteratively optimizing the linear model based on the risk-aware reward, the optimized linear model being used to obtain the matching score of candidate hyperedges for the next task.
6. The method according to claim 5, characterized in that, The step of performing multiple task feature predictions by the B-HCN model under each set of sampling model parameters to obtain task prediction results includes: obtaining the association matrix of the graph structure and the current state data of the nodes in the graph structure; inputting the association matrix and the current state data into the B-HCN model, and fusing the association matrix and the current state data into collaborative features by the hypergraph convolutional layer of the B-HCN model; and performing task feature prediction based on the collaborative features by the B-HCN model under different sampling model parameters to obtain task prediction results.
7. The method according to claim 6, characterized in that, The step of determining the risk perception reward based on the basic task reward and the task prediction result includes: determining the task volatility index based on the variance of the task prediction results under different sampling model parameters; and performing a weighted calculation on the basic task reward and the task volatility index to obtain the risk perception reward.
8. The method according to claim 7, characterized in that, The iterative optimization of the linear model based on the risk-perceived reward includes: updating the context feature vector corresponding to the task execution result to the historical context feature vector set, and updating the risk-perceived reward to the historical task execution reward set of the candidate superedge; and iteratively optimizing the linear model using the updated historical context feature vector set and the historical task execution reward set.
Citation Information
Patent Citations
Multi-agent cooperation method and device based on MCP and medium
CN120631469A
Parallel task execution method and device oriented to agent system and electronic equipment
CN121008887A