Task execution method based on model context protocol
By adopting a task execution method based on model context protocol, and utilizing an autoregressive language model for task planning and decomposition, dynamically generating service interfaces and handling exceptions, this approach addresses the shortcomings of autonomous AI agents in task decomposition, service registration, and multimodal task collaborative scheduling, thereby achieving full-process autonomy of the agent and stability of task execution.
Patent Information
- Application Number
- CN202511449204.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-11
- Publication Date
- 2026-01-23
AI Technical Summary
Existing technologies for building autonomous AI agents suffer from several problems, including a lack of structured support for task decomposition, a lack of automatic adaptation capabilities for service registration and invocation, insufficient fault tolerance for task execution, and insufficient multimodal task collaborative scheduling capabilities. These issues result in poor flexibility and stability of the agents when facing complex tasks.
A task execution method based on model context protocol is adopted. Task planning and decomposition are performed through autoregressive language model, service interface descriptions are dynamically generated and registered, and exceptions are monitored and handled in real time to achieve autonomous task execution and service replacement.
It enables agents to achieve full-process autonomy in complex tasks, supports efficient and accurate task decomposition and multimodal task processing, and ensures the continuity of task processes and the reliability of results.
Smart Images

Figure CN121390331A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of artificial intelligence, and in particular to a task execution method based on a model context protocol, which is aimed at the automatic decomposition, service execution and result integration of complex tasks. BACKGROUND
[0002] Artificial intelligence systems are gradually evolving from a single model task execution paradigm to an agent scheme with autonomous perception, autonomous decision-making and autonomous execution capabilities. Such a scheme no longer relies on artificial explicit instructions or process design, but through model-driven task understanding, planning, execution and learning mechanism to achieve end-to-end automatic completion of complex tasks. However, in the process of building a fully autonomous and sustainable AI agent scheme, there are still the following key technical challenges:
[0003] Task decomposition lacks structured support, and existing task schemes mostly rely on templates or rule-driven, which lack flexibility and generalization ability when facing complex or unstructured tasks. Although large language models have good task understanding ability, how to effectively decompose tasks into executable minimum units and explicitly define the dependency relationship between subtasks still lacks a systematic solution. In addition, most current schemes still adopt a linear process of "generating once and executing once", lacking structured task tree modeling and dynamic optimization mechanism, making it difficult to meet the needs of multi-round collaboration and high-order task execution.
[0004] Service registration and invocation still need to be predefined, lacking automatic adaptation capability. Although the model context protocol (MCP) has been proposed as a unified service protocol standard to regulate the communication and interaction between agents and services, the service end of the MCP protocol still needs developers to predefine service capabilities, parameter structures and interface formats. This premise seriously limits the adaptive ability of the scheme. In the agent scheme, there is still a gap between task execution and service invocation, and the agent model needs to parse the task text and map it to the MCP interface predefined by the developer. This manual mapping mechanism not only relies on hard coding, but also cannot cope with service changes, API failures or task form changes, lacking flexibility and stability. Therefore, a mechanism is needed to automatically generate service registration information and dynamically bind interface capabilities, so that the agent can automatically register services and dynamically construct MCP service capabilities when facing new tasks, thereby realizing "model-driven service orchestration".
[0005] The task execution fault tolerance is insufficient, the exception handling and service replacement mechanism are lacked, and the system often encounters problems such as service unavailability, interface failure or response exception in actual operation. The existing scheme mostly lacks task failure backtracking, subtask replacement or standby service mechanism, and once a certain link fails, the whole task is often interrupted or cannot be completed, and the stability and robustness are poor. At the same time, even if there is an alternative functional service, the system usually cannot complete the automatic switching and migration calling between services, and lacks the complete fault tolerance process of 'perceiving faults, replacing resources and retrying execution'.
[0006] The multi-modal task coordination scheduling capability is insufficient, the tasks handled by modern intelligent agents are increasingly complex, often requiring the integration of text, image, audio, structured data and other multi-modal inputs, and the calling of cross-modal services. The existing scheme mostly relies on text-driven logic, lacks unified modeling and task scheduling mechanism for multi-modal content, resulting in unclear execution path and inconsistent context in tasks such as combination of text and image, image-to-text, text-to-image execution. This makes the intelligent agent adaptability limited when facing actual multi-modal application scenarios, and it is difficult to realize unified input and output management, cross-modal task distribution and service selection.
[0007] Therefore, it is urgent to design a task execution method with autonomous capability of task planning, service registration, task execution and exception handling whole process, to realize a truly fully autonomous intelligent agent architecture. SUMMARY
[0008] The technical problem solved by the present application is to overcome the shortcomings of the prior art and provide a task execution method with autonomous capability of task planning, service registration, task execution and exception handling whole process.
[0009] To solve the above technical problems, the present application provides a fully autonomous AI intelligent agent task execution method based on model context protocol, mainly comprising the following steps:
[0010] Step 1: task planning and decomposition, the complex task input by the user is decomposed into a subtask tree with dependency relationship through the task planning module;
[0011] Step 2: dynamic registration and adaptation of services, for the subtasks in the subtask tree, a service interface description conforming to the model context protocol is dynamically generated, and the service interface is registered to the execution environment;
[0012] Step 3: task execution and result integration, based on the dependency relationship of the subtask tree, the registered services are called in sequence to execute the corresponding subtasks, and the execution results of each subtask are integrated to generate the task result;
[0013] Step 4: Abnormality processing and dynamic reconstruction, monitoring the execution process of the sub-tasks, when an exception occurs, re-generating a task plan or replacing the called service according to the exception information to continue executing the task.
[0014] In the step 1,
[0015] The task decomposition is performed by a task planning module based on an autoregressive language model, wherein the autoregressive language model is trained by a group relative strategy optimization method, and the optimization target is to improve the effectiveness of the task decomposition path.
[0016] In the step 2, the service interface description generated dynamically includes one or more of parameter definition, calling mode, permission limit and calling specification.
[0017] In the step 1, the complex task input by the user includes one or more modalities of input such as text, image and audio; and in the step 3, the task result is a multi-modal result.
[0018] The step 4 specifically includes:
[0019] Step 4.1: Monitoring the execution process of the sub-tasks, and generating an error report and feeding back when an exception occurs;
[0020] Step 4.2: Reconstructing the corresponding task sub-tree and re-calling the service according to the error report;
[0021] Step 4.3: Automatically selecting a candidate service for replacement calling based on the health degree record and compatibility identification in the service registry.
[0022] The present application has the following beneficial effects:
[0023] 1. The intelligent agent can autonomously complete task understanding, decomposition, service configuration and execution, and realize the full-process automation of "task-driven, model self-arrangement".
[0024] 2. Through strategy optimization training, the intelligent agent can dynamically generate an optimal task tree according to the context, and realize efficient and accurate task decomposition.
[0025] 3. The service interface can be automatically generated and registered, and the dynamic construction and adaptive calling of service capability can be realized.
[0026] 4. The task failure automatic backtracking and service replacement are supported, and the task process is ensured not to be interrupted and the result is reliable and reachable. BRIEF DESCRIPTION OF DRAWINGS
[0027] Figure 1 The method flowchart of the exemplary embodiment of the present application. DETAILED DESCRIPTION
[0028] The application is a task execution method based on a model context protocol (MCP), mainly including task planning and decomposition, service registration, task execution, and exception handling and service replacement mechanism.
[0029] In this embodiment, the autoregressive language model is trained using a pre-built dataset, enabling it to decompose complex tasks into subtask trees.
[0030] The task planning module based on the autoregressive language model receives user input tasks, generates task trees in combination with context information, and recursively decomposes the tasks into multiple subtask trees with dependency relationships.
[0031] The autoregressive language model is trained using a group relative strategy optimization method, with the optimization goal being to improve the effectiveness of task decomposition paths, and the model is updated and optimized based on execution effect feedback of different decomposition paths.
[0032] For subtasks obtained by decomposition, a standardized service interface description is dynamically generated based on external identity information, which is derived from outside the system and used for subject identity recognition and authentication, including but not limited to API access keys or user account credentials.
[0033] The service interface description includes one or more of parameter definition, invocation method, permission restriction, and invocation specification, and the generated service interface is registered to the client for subsequent invocation.
[0034] According to the dependency relationship of subtasks and registered services, registered services are invoked in sequence to execute corresponding subtasks.
[0035] The subtasks include one or more of text, image, and audio user input tasks.
[0036] The output results of each subtask are obtained, and the execution results of each subtask are integrated to generate the final task result.
[0037] During task execution, the subtask execution state is monitored, and when invocation exceptions or result errors occur, error reports are generated and feedback is provided.
[0038] According to the error report, the corresponding task sub-tree is restructured, the failed task path is replaced, and the service is re-invoked.
[0039] The backup service mechanism automatically selects the most similar candidate service for replacement invocation based on the health degree record and compatibility identifier in the service registration table, to ensure that the task can continue to be executed.
[0040] The following will be described in detail in conjunction with the accompanying drawings Figure 1 The method flow of an exemplary embodiment of the application is described in detail:
[0041] Step 1: Training and building task planning and decomposition agents
[0042] Step 1.1: The training of the task planning and decomposition agent adopts a group relative strategy optimization method. The training data set is composed of multi-modal task samples, including task descriptions, artificially annotated task trees, and execution feedback. The optimization goal of GRPO is to maximize the effectiveness of the task decomposition path. Specifically, it is trained by comparing the execution effects (such as execution success rate, result quality) of different decomposition paths. During the training process, the model dynamically adjusts the task decomposition strategy according to the feedback, and preferentially selects decomposition paths that can efficiently complete tasks. Task types include but are not limited to document generation, image processing, data analysis, etc.
[0043] Step 1.2: The task planning and decomposition agent is based on a self-recurrent language model, which uses a self-recurrent language model as the basic model to understand complex tasks from user input in the context. User input can be in the form of text descriptions, images, audio, etc. multi-modal tasks, such as "generate a travel plan document containing text and image content". The agent recursively splits complex tasks into the smallest executable units through self-recurrent generation. For example, the above task can be split into "get user travel preferences", "search destination information", "generate itinerary text", "generate relevant scenic spot pictures", etc. The task tree ensures the dependency relationship between sub-tasks and the logical order of subsequent execution.
[0044] The task planning module provides overall functional definition and architecture, and the self-recurrent language model is the core computing entity of this module, responsible for performing specific understanding and reasoning tasks, while the group relative strategy optimization is a specific training paradigm adopted to improve the effectiveness and reliability of the self-recurrent language model in generating task decomposition paths. Through this hierarchical design, the task planning module not only has strong semantic understanding ability, but also obtains the special skill of generating high-quality task decomposition paths through targeted optimization.
[0045] Step 2: Building service registration agents
[0046] Step 2.1: The service registration agent is based on a self-recurrent generative model, which uses the same self-recurrent language model as the task planning agent. After the task planning is completed, the service registration agent converts each smallest task unit decomposed in step 1 into an MCP service that can be called by other agents. For each service, the system not only generates its function implementation, but also synchronously constructs complete interface description information to ensure that the service can be accurately called and integrated. The interface description includes the following key elements:
[0047] Parameter Definition: Clearly define the input parameters required by the service and the data format returned. For example, the input for the "Search Destination Information" subtask includes destination name, time range, and the output is structured point-of-interest information in JSON format;
[0048] Invocation Mode: Specify the invocation mode of the service (e.g., synchronous or asynchronous);
[0049] Permission Control: Define access permission policies, including whether authentication is required, token authorization, or internal calls only;
[0050] Invocation Specification: Set the service's invocation frequency limit, maximum concurrency, failure retry strategy, etc., to ensure the stability and security of the solution.
[0051] By constructing a service registration agent, the task unit is automatically converted into a standardized and combinable service, providing a basic capability for task collaboration and dynamic scheduling between agents.
[0052] Step 2.2: The generated MCP service will automatically register to the client's service directory through the standardized MCP protocol. The registration process is completed by the service registration agent, mainly including storing the service interface information into the service registry, recording the unique identifier, function description, and compatibility identifier of the service. The service registration agent supports dynamic updating of the registry, and when the external service interface changes (such as API version update), it automatically regenerates and registers a new service interface. Generally, the registry can support up to 1000 concurrent service interfaces, ensuring efficient scheduling in the task execution phase.
[0053] In step 2, the service registration agent registers the generated MCP service to the execution environment, and the service registration information formed is a dynamically maintained data set, which is far from limited to the basic interface description of the service. What is particularly key is that this registration information is continuously updated and contains the health record and compatibility identifier of each service.
[0054] The health record is used to quantitatively evaluate the reliability of the service, which includes but is not limited to historical call success rate, average response time, recent failure times, etc.
[0055] The compatibility identifier is used to identify the functional replaceability between services, which is generated by calculating the vector similarity (such as cosine similarity) of service interface description, input and output parameters, etc.
[0056] Step 3: Construct the task execution agent
[0057] Step 3.1: The task execution agent is based on a high-level language model and supports processing multi-modal input tasks. Input types include but are not limited to text (natural language instructions), images (picture description or generation tasks), and audio (voice instructions or audio processing tasks). The task execution agent calls the corresponding MCP service according to the sub-task tree generated by the task planning agent. For example, for the "generate travel plan text" sub-task, the agent calls the text generation service, inputs user preferences and destination information, and obtains structured travel text; for the "generate related scenic spot pictures" sub-task, the agent calls the image generation service, inputs the scenic spot description, and generates corresponding visual pictures.
[0058] Step 3.2: The task execution agent fuses the MCP service outputs of each sub-task to generate the final multi-modal task result. The fusion process uses a multi-modal integration model based on attention mechanism, with input being the intermediate results of each sub-task (such as text, image, structured data), and output being a unified final result. For example, for the travel plan document task, the final result is a structured document containing travel text and scenic spot pictures. The fusion model learns the semantic association between different modalities through training, ensuring the context consistency and logical integrity of the output result.
[0059] Step 4: Abnormal handling and service substitution
[0060] Step 4.1: The task execution agent monitors the MCP service call status in real time, detects abnormal situations (such as service timeout, interface returns error, result does not meet expectations). When an exception occurs, the agent generates a detailed error report, including error type (service unavailable, parameter error, etc.), sub-task ID, and call context. The error report is fed back to the task planning and decomposition agent for subsequent task adjustment.
[0061] Step 4.2: The task planning and decomposition agent analyzes the failure cause according to the error report and dynamically reconstructs the task sub-tree. For example, if the "search destination information" sub-task fails due to service unavailability, the agent can replace it with the "extract information from backup knowledge base" sub-task and regenerate the task execution path.
[0062] Step 4.3: The backup service mechanism automatically selects the candidate service with the most similar function to the failed service based on the compatibility identifier in the service registry. The compatibility identifier calculates the distance between service interface description vectors through cosine similarity. After calling the substitute service, the task execution agent verifies the validity of the output result. If it still fails, repeat steps 4.1 to 4.3 until the task is successful or the maximum number of retries (such as 3 by default) is reached.
[0063] In the exception handling and dynamic reconstruction process of step 4, the service registration information that the system "according to" is the core decision basis of the health degree record and the compatibility identifier. When the subtask execution is abnormal, first query the compatibility identifier corresponding to the failed service, quickly locate the candidate service cluster similar in function; then, according to the health degree record of these candidate services, preferentially select the service with the highest health degree and the most stable service for replacement call. This mechanism ensures that the exception decision process is data-driven and traceable, rather than random or blind.
[0064] Advantages of the present application:
[0065] 1. The present application realizes the full-process automation from task understanding to execution through multi-agent cooperation, and can complete complex tasks without manual intervention.
[0066] 2. The task planning and decomposition agent dynamically generates an efficient task decomposition path through group relative strategy optimization, improving the accuracy and success rate of task execution.
[0067] 3. The service registration agent automatically generates and registers the MCP service interface, supports dynamic service orchestration, and adapts to the needs of task changes and service updates.
[0068] 4. The exception handling and service replacement mechanism ensures the robustness of the scheme and the continuity of the task flow through error backtracking and dynamic service switching.
[0069] 5. The multi-modal task support and result fusion mechanism enables the scheme to handle complex multi-modal tasks and generate context-consistent comprehensive output.
[0070] The present application realizes a completely autonomous AI agent task execution method based on the MCP protocol by constructing a task planning and decomposition agent, a service registration agent and a task execution agent, combined with an exception handling and service replacement mechanism. The related scheme can adaptively handle multi-modal complex tasks, dynamically generate service interfaces and complete calls, and support task reconstruction and service replacement in abnormal situations. Compared with traditional methods, the present application can effectively improve the autonomy, robustness and multi-modal task processing capability of the scheme, and is suitable for various practical application scenarios such as document generation, image processing and data analysis.
[0071] The above embodiments do not limit the present application in any way, and through the above description, relevant personnel can make various changes and modifications without deviating from the scope of the technical idea of the present application. Any other improvements and applications made by equivalent transformation to the above embodiments are within the scope of the present application. The technical scope of the present application is not limited to the content of the specification, and must be determined by the scope of the claims.
Claims
1. A method for task execution based on a model context protocol, characterized in that, The method comprises the following steps: Step 1: task planning and decomposition, a task planning module is used to decompose a complex task input by a user into a subtask tree with dependency relationships; Step 2: dynamic registration and adaptation of services, a service interface description conforming to a model context protocol is dynamically generated for a subtask in the subtask tree, and the service interface is registered in an execution environment; Step 3: task execution and result integration, based on the dependency relationships of the subtask tree, registered services are sequentially called to execute corresponding subtasks, and the execution results of the subtasks are integrated to generate a task result; Step 4: exception handling and dynamic reconstruction, the execution process of a subtask is monitored, when an exception occurs in the execution, a task plan is regenerated or a called service is replaced according to exception information and in combination with service registration information, so as to continue to execute the task.
2. The method of claim 1, wherein, In step 1, a task planning module based on an autoregressive language model is used to perform task decomposition; wherein the autoregressive language model is trained by a group relative strategy optimization method, and the optimization target is to improve the effectiveness of the task decomposition path.
3. The method of claim 1, wherein, In step 2, the dynamically generated service interface description includes one or more of parameter definition, calling mode, permission limit and calling specification.
4. The method of claim 1, wherein, In step 1, the complex task input by the user includes one or more modal inputs of text, image and audio; in step 3, the task result is a multi-modal result.
5. The method of claim 1, wherein, Step 4 specifically comprises: Step 4.1: monitoring the execution process of a subtask, when an exception occurs, generating an error report and feeding back; Step 4.2: reconstructing a corresponding task sub-tree and re-calling a service according to the error report; Step 4.3: automatically selecting a candidate service to replace the calling based on the health degree record and compatibility identification in the service registration table.
Citation Information
Cited By
Lightweight agent development method and system based on MCP protocol
CN121833293A