Code generation method and device based on LLM multi-agent cooperation and computer equipment
Through the code generation method based on LLM multi-agent collaboration, the problem of limited efficiency and quality in complex programming tasks in the prior art is solved, and task allocation and collaboration between agents is realized, programming efficiency and code quality are improved.
Patent Information
- Application Number
- CN202510261382.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-06-10
AI Technical Summary
Existing auxiliary programming tools based on single LLMs are limited in efficiency and quality when dealing with complex programming tasks. It is difficult for a single LLM to effectively decompose and plan tasks, and it is impossible to simulate team collaboration, which affects the efficiency of code review and integration.
The code generation method based on LLM multi-agent collaboration is adopted to obtain user programming requirements, generate a task tree, and evaluate the matching degree between the agent in the agent pool and the sub-task to be allocated based on LLM, and generate task allocation instructions to realize task allocation and collaboration between agents.
It improves programming efficiency and code quality, optimizes resource allocation, supports complex needs and efficient development of large-scale projects, and ensures high-quality completion of projects.
Smart Images

Figure CN120122931A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a programming method, and more specifically to a code generation method, device and computer equipment based on LLM multi-agent collaboration. Background Art
[0002] In recent years, LLM (Large Language Model) technology has developed rapidly, and representative achievements include OpenAI's GPT series, Google's Gemini, and Anthropic's Claude. These models have demonstrated strong capabilities in natural language processing, text generation, code generation, and other fields. In terms of programming assistance, a variety of LLM-based tools and methods have been proposed and have achieved certain results, especially when dealing with simple programming tasks, which can significantly improve development efficiency. MAS (Multi-Agent System) is a core research direction in the field of artificial intelligence, aiming to solve complex problems through the collaboration of multiple autonomous agents. MAS technology has achieved application results in many fields such as robot control, distributed computing, traffic management, and economic modeling. Although there are also studies in the field of software engineering that explore the application of MAS to tasks such as requirements analysis, code generation and testing, most of the related research is currently in the theoretical exploration stage or prototype system development stage, and has not yet formed a mature commercial product.
[0003] Chinese patent CN202411244668.0 proposes an artificial intelligence-assisted programming method that combines directed graphs and large models to generate code. When the preset directed graph cannot be covered, the large model is used for supplementary generation. This technical solution focuses on the combination of large models and multi-agent collaboration, focusing on solving the complexity of programming tasks. At present, there is another programming method, which is an auxiliary programming tool based on a single LLM. These tools use LLM as the core code generation engine. Users provide programming requirements, and LLM generates corresponding code snippets based on these requirements. Representative tools include GitHub Copilot, Tabnine, and Cursor, which have achieved code generation to a certain extent. Specifically, users enter natural language or code snippets in an integrated development environment to express their programming requirements; the requirements entered by the user are used as prompts and passed to the pre-trained LLM model for processing; LLM generates code snippets or suggestions based on the input requirements and context information; users select suitable snippets from the generated code suggestions and insert them into the code editor.
[0004] However, when existing auxiliary programming tools based on a single LLM handle complex programming tasks, it is difficult for a single LLM to effectively decompose and plan tasks, especially when facing large projects or complex requirements, the efficiency and quality are often limited; a single LLM needs to cover all programming fields, but the capabilities of LLM are limited, resulting in low quality of code generated in some fields, reducing the professionalism of programming assistance; a single LLM cannot simulate team collaboration and lacks collaboration and communication mechanisms, affecting the efficiency of code review and integration; the task scheduling strategy of the existing system is relatively simple, and it is impossible to flexibly optimize resource allocation according to demand, resulting in low system performance and resource utilization, and unable to cope with complex programming environments.
[0005] Therefore, it is necessary to design a new method to improve programming efficiency and quality, optimize resource allocation, and support the efficient development of complex requirements and large projects. Summary of the invention
[0006] The purpose of the present invention is to overcome the defects of the prior art and provide a code generation method, device and computer equipment based on LLM multi-agent collaboration.
[0007] To achieve the above object, the present invention adopts the following technical solution: a code generation method based on LLM multi-agent collaboration, comprising:
[0008] Obtain user programming requirements;
[0009] Analyze the user programming requirements based on LLM and decompose programming tasks to generate a task tree;
[0010] Selecting a subtask to be assigned from the task tree, and evaluating the matching degree between the agent in the agent pool and the subtask to be assigned based on the LLM, and generating a task assignment instruction;
[0011] Sending the task assignment instruction to the corresponding target agent so that the target agent executes the subtask to be assigned and feeds back the execution result;
[0012] The execution result is outputted.
[0013] A further technical solution is: analyzing the user programming requirements based on LLM and decomposing programming tasks to generate a task tree, including:
[0014] Convert the user programming requirement into a form to obtain a conversion result;
[0015] Input the conversion results into LLM for in-depth understanding and decomposition into key functional modules and components to obtain preliminary decomposition results;
[0016] Recursively decomposing the preliminary decomposition result to obtain subtasks;
[0017] The subtasks are organized into a task tree with a tree structure according to logical relationships.
[0018] A further technical solution is that the task tree records the task description, input and output data and dependency information of each node.
[0019] A further technical solution is: selecting a subtask to be assigned from the task tree, and evaluating the matching degree between the agent in the agent pool and the subtask to be assigned based on the LLM, and generating a task assignment instruction, including:
[0020] Obtain real-time information of intelligent agents;
[0021] Filter and sort the subtasks to be assigned from the task tree according to task priorities and dependencies;
[0022] Use LLM to evaluate the matching degree between each subtask to be assigned and the real-time information of the agent to obtain the target agent;
[0023] Generate a task assignment instruction according to the subtask to be assigned and the target agent.
[0024] A further technical solution is: the task assignment instruction includes the ID of the subtask to be assigned, the target agent ID, the task description and the input data.
[0025] A further technical solution is: screening and sorting the subtasks to be assigned from the task tree according to the task priorities and dependencies, including:
[0026] According to the task priorities and dependencies, by traversing the task tree and checking the subtask status, candidate subtasks are screened from the task tree;
[0027] The candidate subtasks are sorted using a topological sorting algorithm to obtain subtasks to be assigned.
[0028] A further technical solution is: sending the task assignment instruction to the corresponding target agent so that the target agent executes the subtask to be assigned and feeds back the execution result, including:
[0029] Send the task assignment instruction to the corresponding target intelligent agent so that the target intelligent agent can parse the task assignment instruction, decompose the subtasks to be assigned according to the parsed results, and collaborate with other intelligent agents to obtain the required data or solve the problem, execute the subtasks to be assigned according to the acquired content to generate an execution result, and feedback the execution result.
[0030] A further technical solution is: the execution result includes the result of executing the subtask to be assigned and the corresponding subtask status update message.
[0031] The present invention also provides a code generation device based on LLM multi-agent collaboration, comprising:
[0032] A requirement acquisition unit, used to acquire user programming requirements;
[0033] A task tree generating unit, configured to analyze the user programming requirements and decompose programming tasks based on the LLM to generate a task tree;
[0034] A task assignment instruction generating unit, configured to select a subtask to be assigned from the task tree, and to generate a task assignment instruction based on the LLM evaluation of the matching degree between the agent in the agent pool and the subtask to be assigned;
[0035] A sending unit, used for sending the task assignment instruction to the corresponding target agent, so that the target agent executes the subtask to be assigned and feeds back the execution result;
[0036] An output unit is used to output the execution result.
[0037] The present invention further provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor implements the above method when executing the computer program.
[0038] Compared with the prior art, the beneficial effects of the present invention are as follows: by analyzing user programming requirements, generating a task tree and optimizing task allocation, the system efficiently matches intelligent agents to execute subtasks, thereby improving resource utilization and development efficiency and ensuring high-quality completion of the project. Specifically, by obtaining and analyzing user programming requirements, the system can quickly understand task objectives and ensure accurate grasp of the development direction; based on LLM, programming requirements are decomposed into clear task trees to help the system identify the specific details and priorities of tasks and improve the efficiency of task management; based on the expertise and task requirements of the intelligent agent, the matching degree is evaluated and task allocation is optimized to ensure efficient resource utilization; the flexible task allocation mechanism can adapt to complex requirements and large projects, ensuring that each subtask can be executed by the most suitable intelligent agent; the feedback of execution results prompts the system to continuously optimize, ensure programming quality, improve development efficiency, and achieve continuous progress and collaboration in the project.
[0039] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0041] Figure 1 A schematic diagram of an application scenario of a code generation method based on LLM multi-agent collaboration provided by an embodiment of the present invention;
[0042] Figure 2 A flowchart of a code generation method based on LLM multi-agent collaboration provided by an embodiment of the present invention;
[0043] Figure 3 A schematic block diagram of a code generation device based on LLM multi-agent collaboration provided by an embodiment of the present invention;
[0044] Figure 4 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0045] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0047] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0048] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0049] See also Figure 1 and Figure 2 ,Figure 1 A schematic diagram of an application scenario of the code generation method based on LLM multi-agent collaboration provided in an embodiment of the present invention. Figure 2 A schematic flow chart of a code generation method based on LLM multi-agent collaboration provided in an embodiment of the present invention. The code generation method based on LLM multi-agent collaboration is applied in a server. The server interacts with the terminal for data, converts the user programming requirements into a task tree, refines and decomposes the tasks for efficient management; evaluates the matching degree between the agent and the task through LLM, reasonably allocates subtasks, and optimizes resource utilization; screens and sorts subtasks according to task priorities and dependencies to ensure the order and collaboration of tasks; the target agent receives the task and executes it, and ensures the subtask status update and progress tracking when feeding back the results; multi-agent collaboration and recursive decomposition support complex functional modules and subtasks, and improves code quality; the system can cope with the needs of large projects, support efficient task scheduling and dynamic collaboration, and ensure smooth project development.
[0050] Figure 2 Schematic diagram of the code generation method based on LLM multi-agent collaboration provided by an embodiment of the present invention. Figure 2 As shown, the method includes the following steps S110 to S150.
[0051] S110, obtaining user programming requirements.
[0052] In this embodiment, the user inputs programming requirements through different interfaces. These interfaces can be plug-ins of integrated development environment (IDE), web interface, command line interface, etc. Users can provide different forms of requirement descriptions through these tools:
[0053] Natural language text: For example, users can directly describe the required functionality in natural language, such as "write a program that can process CSV files."
[0054] Code framework: Users can provide some preliminary code framework or structure as a starting point and ask the system to complete or optimize it.
[0055] Project goal: In more complex applications, users may describe a specific project goal or task, such as: "Develop an intelligent chatbot that supports multi-language processing."
[0056] The programming requirements input by users may be diverse and unstructured. For example, the description can be in free-form text, code snippets, structured requirement forms, etc., so it is necessary to be able to flexibly handle various types of inputs. Due to the ambiguity and diversity of natural language, the requirement descriptions of users may also be ambiguous. For example, users may express their requirements using imprecise terms or vague language, resulting in deviations in the system's understanding. Therefore, appropriate technologies must be used to handle these potential ambiguities to ensure that the requirements can be accurately interpreted.
[0057] After obtaining the user's requirement description, the data will be passed to the subsequent task decomposition step. This step will analyze and process the user's requirements and decompose them into small tasks or subtasks that can be further processed.
[0058] To ensure accuracy, the system needs to preprocess the input data first, including:
[0059] Text analysis and processing: Perform operations such as word segmentation, part-of-speech tagging, and entity recognition on natural language input to extract key information.
[0060] Code parsing: For code framework input, the system needs to perform code syntax analysis, identify the structures of each part, and understand its meaning.
[0061] Semantic understanding: Understand the user's intention, identify the target function modules, business logic, and other necessary conditions.
[0062] Finally, the obtained user programming requirements will be transformed into clear task descriptions, providing a basis for subsequent task decomposition, matching, and allocation. Through efficient requirement acquisition and processing, a clear direction can be provided for the decomposition and execution of the entire programming task, improving development efficiency and quality.
[0063] S120. Analyze the user programming requirements based on the LLM and decompose the programming tasks to generate a task tree.
[0064] In this embodiment, the task tree is a tree-like structure generated by deeply analyzing and decomposing the user programming requirements, including task descriptions, input and output data, and dependency information. This process includes steps such as requirement transformation, module decomposition, recursive decomposition, and task organization.
[0065] The task descriptions, input and output data, and dependency information of each node are recorded in the task tree.
[0066] In one embodiment, the above step S120 may include steps S121 to S124.
[0067] S121. Perform a form transformation on the user programming requirements to obtain a transformation result.
[0068] In this embodiment, the conversion result refers to the result obtained by converting the programming requirement description submitted by the user into a format suitable for computer processing by converting the natural language requirement.
[0069] Specifically, the natural language description input by the user is converted into a standardized format to facilitate subsequent understanding and processing.
[0070] Extract key information from the requirement description and convert it into an actionable data structure, such as JSON, XML, or a specific domain model. This step helps convert the text of the requirement into structured data that machines can understand.
[0071] S122, input the conversion result into LLM, conduct in-depth understanding and decompose it into key functional modules and components to obtain a preliminary decomposition result.
[0072] In this embodiment, the preliminary decomposition results refer to key functional modules and components.
[0073] Specifically, the transformed requirement description will be used as input and sent to the LLM (Large Language Model) for further analysis and decomposition. The specific steps include:
[0074] Choose a suitable pre-trained LLM (such as GPT-4) or a LLM model fine-tuned according to the required task. This model will be responsible for processing the semantic analysis of user requirements and identifying the core functional modules in the requirements.
[0075] By designing specific prompts, LLM is guided to conduct in-depth analysis of user requirements, identify the functional modules and components, and decompose them logically. For example, providing instructions like "You are a senior software architect, please analyze the following requirements and output functional modules" helps LLM to decompose requirements efficiently.
[0076] LLM identifies the core functional modules and components based on the input requirement description and completes the initial decomposition. The output is usually presented in JSON format, including the module name and description information.
[0077] Specifically, prompt words may include:
[0078] Role setting: For example, "You are a senior software architect. Your task is to understand the programming requirements proposed by users and decompose them into preliminary functional modules and components."
[0079] Instructions: For example, “Please analyze the following user requirement description, identify the core functional modules and components contained therein, and output them in the form of a list.”
[0080] Format requirements: For example, "Please output the result in JSON format, including the module name and a brief description."
[0081] For example, provide examples of requirement descriptions and corresponding module decompositions to help the LLM better understand the task requirements.
[0082] Here is an example of a preliminary decomposition:
[0083] User requirement description: "Develop an online bookstore website where users can browse books, search for books, add them to the shopping cart, and place orders to purchase. Administrators can manage book information, order information, and user information."
[0084] LLM output result (example JSON):
[0086] {"module_name":"User module","description":"Responsible for user-related functions such as user registration, login, personal information management, and permission management"},
[0087] {"module_name":"Product module","description":"Responsible for product browsing functions such as displaying, searching, classifying, and viewing details of book information"},
[0088] {"module_name":"Shopping cart module","description":"Responsible for shopping cart management functions such as adding products to the shopping cart, viewing the shopping cart, and modifying shopping cart items"},
[0089] {"module_name":"Order module","description":"Responsible for order processing functions such as user placing orders, payment, order query, and order management"};
[0090] {"module_name":"Administrator module","description":"Responsible for backend management functions such as administrator login, book information management, order information management, and user information management"}
[0091] 。
[0092] The prompt is as follows:
[0093] "You are a senior software architect. Please analyze the following user requirement description, identify the core functional modules and components contained therein, and output the result in JSON format, including the module name and a brief description."
[0094] S123. Recursively decompose the preliminary decomposition result to obtain subtasks.
[0095] In this embodiment, a subtask refers to a partial task formed by dividing the entire programming process.
[0096] Through recursive decomposition, the initially identified functional modules are further split into smaller subtasks. Different decomposition strategies can be selected at this time, such as:
[0097] Function decomposition: Continue to decompose according to the functional hierarchy. That is, decompose by functional module and refine each module into smaller functional units.
[0098] Process decomposition: Refine the module according to the processing flow. For example, the user login function may be decomposed into multiple subtasks such as front-end display, back-end verification, database storage, etc. Specifically, for a certain functional module, decompose it according to the processing flow. For example, the user registration function can be decomposed into subtasks such as "display user registration form", "verify user data", "store user data", "send registration success email", etc.
[0099] Data decomposition: For modules involving data processing, decompose them into smaller subtasks according to data type or processing stage. For data processing tasks, decompose them according to the data processing stage or data type. For example, the data analysis task can be decomposed into subtasks such as "data collection", "data cleaning", "feature engineering", "model training", "result visualization", etc.
[0100] Hybrid strategy: Select appropriate decomposition strategies according to different subtask types.
[0101] During the process of recursive decomposition, it is necessary to ensure that each task is decomposed to a small enough granularity to be independently completed by the agent. In this step, the LLM may be repeatedly called to assist in detailed decomposition.
[0102] Specifically, for each first-level subtask after the initial decomposition, repeat the decomposition until the task granularity is small enough to be suitable for a single agent to independently complete. Set the termination conditions for decomposition, such as:
[0103] The length of the task description is below the threshold: Stop decomposing when the subtask description is concise.
[0104] The task type is a predefined atomic task type: For example, predefined atomic task types such as "code generation", "unit testing", "API document generation", etc., stop decomposing.
[0105] Reach the preset decomposition depth: For example, limit the maximum depth of the task tree to 3 or 4 levels.
[0106] LLM-assisted recursive decomposition (optional): The LLM can be used to assist in further decomposing tasks. Design new prompt words for each parent task to guide the LLM to decompose it into smaller subtasks.
[0107] Manual intervention (optional): During the automatic decomposition process, manual intervention is allowed. The results of each decomposition level are presented to the user, who can modify, adjust, or supplement the decomposition content to ensure the rationality of the decomposition.
[0108] Based on functional decomposition, taking the "user module" as an example:
[0109] First-level subtask: "User module" (responsible for functions such as user registration, login, and personal information management).
[0110] Further decomposition (second-level subtasks):
[0111] "User registration function";
[0112] "User login function";
[0113] "User personal information management function" (such as modifying passwords and updating email addresses);
[0114] "User permission management function" (such as role assignment and permission control);
[0115] Continue to decompose the "user registration function" (third-level subtasks):
[0116] "Display user registration form" (front-end development task);
[0117] "Validate user registration form data" (back-end development task);
[0118] "Store user data" (back-end development task, database operation);
[0119] "Send registration success email" (back-end development task, email service integration);
[0120] "Generate user registration API documentation" (documentation generation task);
[0121] Decomposition termination condition: For example, when decomposing to the "display user registration form" task, it is considered that the granularity is small enough to be assigned to the front-end development Agent for completion.
[0122] S124. Organize the subtasks into a task tree in a tree-like structure according to the logical relationship.
[0123] In this embodiment, in this step, all subtasks will be organized into a tree-like task tree according to their dependencies and logical structures. Each node represents a subtask, the root node of the task tree represents the initial user requirement, and the edges between the nodes represent the dependencies between tasks. The main information of the task tree includes:
[0124] Task description: Each node will describe in detail the content, objective, and specific requirements of the task.
[0125] Input and output data: Each subtask will indicate its input data, output data, and the dependencies of the processing results.
[0126] Task dependencies: Each task node indicates the predecessor tasks it depends on and which tasks will be affected after its completion.
[0127] The generation of the task tree is a key step, which will ensure that the relationship and sequence between tasks are clear and unambiguous, facilitating subsequent task allocation and scheduling.
[0128] S130, selecting a subtask to be assigned from the task tree, and evaluating the matching degree between the agent in the agent pool and the subtask to be assigned based on the LLM, and generating a task assignment instruction.
[0129] In this embodiment, the task assignment instruction refers to an instruction set containing all necessary information, which is used to guide the system to assign a specific task to a selected agent for execution. The task assignment instruction includes the ID of the subtask to be assigned, the ID of the target agent, the task description, and the input data.
[0130] Specifically, the task allocation instruction includes at least the following key components:
[0131] Subtask ID to be assigned: A unique identifier that identifies the specific subtask that needs to be executed. This helps to clearly specify which subtask is to be scheduled in the task tree.
[0132] Target Agent ID: The unique identification code of the agent responsible for executing the subtask. The selection of the appropriate agent is determined based on its matching degree with the task requirements, the current load and other decision factors.
[0133] Task description: Provides detailed information about the subtask, including but not limited to the task's goal, type, input data requirements, and output data specifications. This ensures that the agent clearly understands what it needs to accomplish.
[0134] Input data: Contains all the data required to perform the subtask or links / paths to these data. For example, for a front-end development task, it may include a requirements document for a user registration form.
[0135] By generating such a comprehensive task assignment instruction, the system can accurately convey the details of the task to be performed to the agent, ensuring that the task is executed efficiently and accurately according to the predetermined plan. In addition, this structured instruction also helps with subsequent task tracking, status updates, and troubleshooting.
[0136] In one embodiment, the above-mentioned step S130 may include steps S131 - S134 .
[0137] S131. Obtain real-time information of the agent.
[0138] In this embodiment, obtain the real-time information in the agent pool. This includes but is not limited to the agent list, the ability description of each agent, the current status, and the resource occupancy, etc. This information can be obtained through methods such as direct memory sharing, shared database, or API interface. The specific implementation details are as follows:
[0139] Agent list: Contains the IDs of all agents registered in the agent pool and their basic information.
[0140] Ability description: Covers detailed information such as the skill list, the field of expertise, and the experience level.
[0141] Status information: Reflects the current status of the agent (such as idle, busy, offline), the resource usage status, and the historical execution records.
[0142] In this embodiment, obtain the task tree. The obtaining method can be implemented through the following several ways:
[0143] Direct memory sharing: If task decomposition and task scheduling run in the same process or memory space, the task tree data structure can be directly shared.
[0144] Message queue: The task decomposition serializes the task tree data (for example, using the JSON format), and then sends it to the message queue (such as RabbitMQ or Kafka). The task scheduling module receives the data from the message queue and deserializes it.
[0145] API interface: The task scheduling requests the task decomposition module to provide the task tree data through the API interface (such as REST API or gRPC).
[0146] Obtain the real-time information of the agent pool (management module). These information include:
[0147] Agent list: The IDs of all agents currently registered in the agent pool and their basic information (such as agent type, status, etc.).
[0148] Agent ability description: The detailed ability description of each agent, including the skill list, the field of expertise, the experience level, etc. The description can be structured data or natural language.
[0149] Agent status information: The current status of each agent (such as idle, busy, offline), the resource occupancy (such as CPU, memory, etc.), the task execution history, etc.
[0150] The obtaining method can be through the following several ways:
[0151] Direct memory sharing: If the task scheduling and the agent pool are in the same process, the agent pool information can be shared.
[0152] Shared database or data storage: The agent pool information is stored in a shared database or data storage (such as Redis, etcd), and the task scheduling module reads the information from it.
[0153] API interface: The agent pool management provides API interfaces through which the task scheduling can request the agent pool information.
[0154] The state of the agent pool changes dynamically. Therefore, the task scheduling needs to update the information of the agent pool regularly or in real time to ensure the accuracy of scheduling decisions. A heartbeat mechanism or an event-driven mechanism can be used to achieve real-time updates.
[0155] S132. Screen and sort the sub-tasks to be assigned from the task tree according to the task priorities and dependencies.
[0156] In this embodiment, the sub-tasks to be assigned are the tasks that need to be assigned for execution.
[0157] In one embodiment, the above step S132 may include steps S1321 to S1322.
[0158] S1321. According to the task priorities and dependencies, by traversing the task tree and checking the sub-task states, screen the candidate sub-tasks from the task tree.
[0159] In this embodiment, the candidate sub-tasks refer to the tasks that need to be assigned for execution but have not been sorted yet.
[0160] S1322. Use a topological sorting algorithm to sort the candidate sub-tasks to obtain the sub-tasks to be assigned.
[0161] In this embodiment, according to the task priorities and dependencies, screen the sub-tasks in the "to be assigned" state from the task tree and sort them. This step ensures that only when all the preconditions of a sub-task are met will it be considered for assignment. The key points include:
[0162] Task state check: Identify all the sub-tasks in the "to be assigned" state.
[0163] Priority sorting: If there are multiple "to be assigned" tasks, sort them according to their priorities.
[0164] Dependency check: Ensure that the sub-tasks are executed in the correct order through a topological sorting algorithm.
[0165] In this embodiment, traverse the task tree and screen the sub-tasks with the state of "to be assigned".
[0166] If there are multiple tasks to be assigned, they are sorted according to the task priority. Tasks with higher priority should be assigned first. The priority of tasks can be pre-set or dynamically adjusted according to the urgency of the tasks or user requirements.
[0167] When selecting tasks, the dependencies between tasks need to be considered. A task can only be selected for assignment when all its dependent tasks have been completed (status is "completed" or "successful"). The topological sorting algorithm can be used to handle the dependencies between tasks to ensure that tasks are executed in the correct order.
[0168] For example, put all the "to be assigned" tasks whose dependent tasks have been completed into the priority queue, and tasks with higher priority are ranked at the front of the queue. The task scheduling module fetches tasks from the head of the queue for assignment each time. Poll and traverse the task tree to check the dependencies of each "to be assigned" task. If the dependencies are met, calculate the weights according to the task priority and make a random selection based on the weights (tasks with higher weights have a higher probability of being selected). Select the list of sub-tasks to be assigned (or a single optimal sub-task to be assigned).
[0169] S133. Use the LLM to evaluate the matching degree between each sub-task to be assigned and the real-time information of the agent to obtain the target agent.
[0170] In this embodiment, the target agent refers to the agent that matches the sub-task to be assigned.
[0171] Specifically, for each sub-task to be assigned, use the LLM to evaluate the matching degree of each agent in the agent pool. This step involves preparing the LLM input data, designing an effective Prompt, and parsing the LLM output results. The specific steps are as follows:
[0172] Create detailed prompt words for each sub-task to be assigned and candidate agent, including sub-task description, agent ability description, and evaluation target.
[0173] Carefully design the prompt words to guide the LLM to accurately understand and evaluate the matching degree between the agent and the task.
[0174] Input the prompt words into the LLM to let it perform natural language understanding, semantic analysis, and reasoning, and output the matching degree score or conclusion.
[0175] Convert the natural language output of the LLM into a quantified matching degree index, and sort the candidate agents accordingly.
[0176] In this embodiment, for each subtask to be assigned and each candidate agent, the task scheduling module needs to prepare the input data for the LLM, usually a prompt, which should include the following content:
[0177] Subtask description: Describe in detail the information such as the goal, type, input data, output data, and requirement constraints of the subtask. Relevant information can be extracted from the task tree nodes.
[0178] Agent ability description: Describe in detail the information such as the capabilities, skills, experience, and expertise areas of the candidate agent. Usually obtained from the agent pool information.
[0179] Evaluation goal: Clearly inform the LLM of the goal to be evaluated. For example, "Please evaluate whether this agent is suitable for executing this task and give a matching score (0-100 points)" or "Please determine whether this agent has all the skills required to complete this task."
[0180] Design an effective prompt to guide the LLM to perform agent ability evaluation and matching. Consider the following when designing:
[0181] Role setting: For example, "You are a senior software architect and team leader, and your task is to evaluate whether different agents are suitable for executing the given programming subtasks."
[0182] Instruction: For example, "Please carefully read the following subtask description and agent ability description, determine whether this agent is suitable for executing this subtask, and evaluate it from aspects such as skill matching degree, experience relevance, and domain knowledge fit, and give a comprehensive matching score (0-100 points, the higher the score, the higher the matching degree)."
[0183] Evaluation dimension (optional): Clearly specify the evaluation dimension, such as skill matching degree, experience relevance, domain knowledge fit, efficiency estimation, quality estimation, etc.
[0184] Scoring criterion (optional): Provide the scoring criterion or reference example to help the LLM understand the scale and meaning of the score.
[0185] Next, input the prompt into the LLM model. The LLM performs natural language understanding, semantic analysis, and reasoning based on the input, analyzes the subtask requirements and agent capabilities, and outputs a matching score or matching result. For example, "Suitable", "Not suitable", or "Score: 85 points".
[0186] Parse the results output by the LLM and extract the matching score or matching result. If the matching result output by the LLM is a natural language description, it needs to be converted into a quantitative matching index. For example, map "very suitable" to 90 points, "basically suitable" to 70 points, "not very suitable" to 50 points, "not suitable" to 30 points, etc.
[0187] Conduct an LLM evaluation on each candidate agent to obtain a matching score, and sort the candidate agents according to the matching score. The agent with the highest matching score is considered the most suitable executor.
[0188] For example, the sub-task description to be assigned (task_register_form_ui): "User registration form display (front-end development task). Input data requirements: User registration form requirements document. Output data specification: User registration form HTML / JS / CSS code."
[0189] Candidate agent description (code_gen_agent_frontend_1): "Agent type: Code generation Agent (front-end). Ability description: Good at front-end development of HTML, CSS, JavaScript, familiar with front-end frameworks such as React, Vue.js, and has 3 years of Web front-end development experience."
[0190] LLM output result example: "This agent is very suitable for executing this sub-task. Comprehensive matching score: 95 points."
[0191] Prompt example: "You are a senior software architect and team leader, and your task is to evaluate whether the following agent is suitable for executing the given programming sub-task.
[0192] Sub-task description: User registration form display (front-end development task). Input data requirements: User registration form requirements document. Output data specification: User registration form HTML / JS / CSS code.
[0193] Agent ability description: Agent ID: code_gen_agent_frontend_1. Agent type: Code generation Agent (front-end). Ability description: Good at front-end development of HTML, CSS, JavaScript, familiar with front-end frameworks such as React, Vue.js, and has 3 years of Web front-end development experience.
[0194] Please judge whether this agent is suitable for executing this sub-task, evaluate it from aspects such as skill matching degree, experience relevance, and domain knowledge fit, and give a comprehensive matching score (0-100 points, the higher the score, the higher the matching degree).
[0195] In addition, use the LLM for reasoning and decision-making to select the most suitable agent to complete the specified task. During the decision-making process, multiple factors need to be comprehensively considered, such as the priority of the task, the load situation of the agent, the overall state of the system, and relevant context information, etc.
[0196] When performing task allocation, in addition to the matching score between the agent and the task (evaluated by the LLM), the following decision-making factors also need to be considered:
[0197] Task priority: The urgency or importance of the task. Tasks with higher priorities should be processed first.
[0198] Agent load: The current workload situation of the agent, including the number of tasks it is currently executing, CPU load, memory usage, etc. Avoid allocating too many tasks to agents that are already overloaded.
[0199] System state: The utilization of the overall system resources, such as the overall usage rates of CPU and memory, and whether there are performance bottlenecks, etc.
[0200] Context information: For example, the background information of the task, historical task execution data, user preference settings, the current state of the code library, etc. This information helps to make more accurate decisions.
[0201] To guide the LLM to make appropriate inferences and decisions based on the above-collected decision-making factors, the prompt should include the following parts:
[0202] Role setting: For example, "You are an intelligent task scheduler, and your task is to select the most suitable agent to execute the given task according to the task requirements and the status of the agent."
[0203] Instruction: For example, "Please comprehensively consider the following factors and select the most suitable agent for the given subtask:
[0204] The matching score between the agent and the task (the higher the score, the better the match);
[0205] The priority of the task (the higher the priority, the more urgent);
[0206] The current load of the agent (the lower the load, the more suitable to take the task);
[0207] The overall state of the system;
[0208] Context information (if any): Please select the best agent from the following candidate agents and give the reasons for the selection.
[0209] Decision Factor Weights (Optional): Different weights can be assigned to each decision factor. For example, the matching degree between the agent and the task may be more important, followed by task priority, and the load situation with a lower weight, etc. The weights can be adjusted according to actual needs.
[0210] List all candidate agents and their relevant information, such as matching degree scores, current load situations, etc.
[0211] Input the designed prompt into the LLM. The LLM will perform reasoning and decision-making, considering various decision factors, select the most suitable agent to execute the task, and provide the reasons for the selection.
[0212] Parse the results output by the LLM, extract the ID of the optimal agent, and record the reasons given by the LLM. These reasons can be used for the explanation of task assignment and later auditing.
[0213] For example, the candidate agent list and relevant information:
[0214] (a) code_gen_agent_frontend_1: Matching degree score 95 points, load 0.2 (low);
[0215] (b) code_gen_agent_frontend_2: Matching degree score 90 points, load 0.8 (high);
[0216] Task priority: High;
[0217] System status: Normal;
[0218] Context information: None;
[0219] Prompt: You are an intelligent task scheduler, and your task is to select the most suitable agent to execute the task according to the task requirements and the status of the agents.
[0220] Please consider the following factors and select the optimal agent for the given subtask "User registration form display (front-end development task)":
[0221] Matching degree score between the agent and the task (the higher the better):
[0222] code_gen_agent_frontend_1: 95 points;
[0223] code_gen_agent_frontend_2: 90 points;
[0224] Task priority: High (very important);
[0225] Current load of the agent (the lower the better):
[0226] code_gen_agent_frontend_1: Load 0.2 (low);
[0227] code_gen_agent_frontend_2: Load 0.8 (high);
[0228] Current system status: Normal;
[0229] Context information: None;
[0230] Please select the optimal agent from the above candidate agents and give the reasons for the selection.
[0231] LLM output result: "Select code_gen_agent_frontend_1 as the optimal agent. Reason: code_gen_agent_frontend_1 has a higher matching score with the task (95 points vs 90 points), and the current load is lower (0.2 vs 0.8). It is more suitable for immediately executing high-priority tasks, can complete the tasks faster and release resources."
[0232] Based on the above decision-making process, generate the final task assignment instruction, including key information such as task ID, assigned agent ID, task description, input data, etc., for the scheduling and management of actual task execution.
[0233] S134. Generate a task assignment instruction according to the to-be-assigned subtask and the target agent.
[0234] In this embodiment, based on the above evaluation results, select the optimal agent for each to-be-assigned subtask and generate the corresponding task assignment instruction. This includes:
[0235] Collect decision factors: In addition to the matching score, factors such as task priority, agent load, system status, and context information also need to be comprehensively considered.
[0236] Decision Prompt design: Develop a Prompt to guide the LLM to make a final decision, and clarify the importance weights of various decision factors.
[0237] Inference and decision-making: Use the LLM for comprehensive reasoning, select the most suitable agent to execute a specific subtask, and provide the reasons for the selection.
[0238] Generate assignment instructions: Create a task assignment instruction including task ID, target agent ID, task description, and input data.
[0239] Suppose there is a front - end development task of "displaying user registration form", and one of the two candidate agents code_gen_agent_frontend_1 and code_gen_agent_frontend_2 needs to be selected for execution. After the matching degree evaluation, it is found that code_gen_agent_frontend_1 not only has a higher matching degree score (95 points vs 90 points), but also has a lower current load (0.2 vs 0.8). Therefore, code_gen_agent_frontend_1 is finally selected as the executor, and the corresponding task assignment instruction is generated.
[0240] S140. Send the task assignment instruction to the corresponding target agent so that the target agent executes the to - be - assigned subtask and feeds back the execution result.
[0241] In this embodiment, the execution result refers to the result formed by the target agent executing the to - be - assigned subtask.
[0242] Specifically, send the task assignment instruction to the corresponding target agent, so that the target agent parses the task assignment instruction, decomposes the to - be - assigned subtask according to the parsed result, cooperates with other agents to obtain the required data or solve problems, executes the to - be - assigned subtask according to the obtained content to generate an execution result, and feeds it back to the execution result.
[0243] Each agent needs to listen to the message receiving channel provided by the message passing module, which may be a specific message queue or API interface. The relevant configuration information (such as queue name, API address, etc.) is configured when the agent starts or registers.
[0244] The agent will continuously listen to this channel, waiting for the task assignment instruction from the task scheduling. The message passing module is responsible for routing the task assignment instruction (such as a message in JSON format) generated by the task scheduling module to the receiving channel of the target agent.
[0245] When the agent receives the message, it needs to parse the message, extract the content of the task assignment instruction, such as task ID, task description, input data reference, output data requirements, etc. This parsing process follows a predetermined message protocol for deserialization and data extraction.
[0246] Among them, the task assignment instruction contains the specific information of the task. These instructions are passed to the agent through the message passing module to start task execution. The task tree generated from the information such as task ID and description involved in the task assignment instruction defines the structure, attributes and dependencies of the task, providing basic information for task scheduling and execution.
[0247] When the agent receives a task assignment instruction, it determines whether it has the ability to execute the task based on the task description and task type. If the task is complex, the agent may need to further break it down into smaller subtasks (different from system-level task decomposition, this is a finer-grained task decomposition). For example, after receiving the task of "implementing the user registration function", the code generation agent may break it down into subtasks such as "generating user registration form code" and "generating user registration backend API code", and call different code generation modules respectively.
[0248] According to the task type, the agent calls the tools it is equipped with. For example:
[0249] Code generation agent: Call the LLM code generation model (such as GPT-3, Codex, etc.) and specify parameters such as programming language and framework. It may also need to use tools such as code editors and compilers.
[0250] Testing agent: Call an automated testing framework (such as JUnit, pytest, etc.) to write and execute test cases. It may also need to use code coverage and performance analysis tools.
[0251] Documentation agent: Call a documentation generation tool (such as Sphinx, JSDoc, etc.) to generate API documentation, user manuals, etc. It may need to access resources such as code libraries and API interfaces.
[0252] Data acquisition: The agent obtains the required data from local files, cloud storage, databases, etc. according to the input data reference in the task instruction. This data may include requirement documents, API interface definitions, code templates, test data, etc.
[0253] LLM-driven task execution: If the agent is driven by an LLM (such as a code generation agent), the core task execution steps include prompt design and LLM inference. The agent designs appropriate prompts according to the task description, inputs them into the LLM model for inference, and generates the required code, test cases, or documents, etc. The prompt design needs to be precise to ensure that the LLM understands the task intention and produces high-quality output.
[0254] Task execution monitoring and logging: The agent needs to monitor during the task execution process and record the execution logs, including start time, end time, progress, error information, resource consumption, etc. This information can be used for task status update, fault troubleshooting, and performance analysis, etc.
[0255] The information such as the task description, input and output data requirements, etc. included in the task instruction comes from the task tree. The task tree defines the decomposition structure of the task and guides the goals and scopes of the agent's tasks.
[0256] During the task execution, the agent may need to collaborate with other agents. For example, the data or information required by the current agent is generated or maintained by other agents, or the current agent encounters problems and needs to request help. The collaboration requirements can be predefined or dynamically generated during the execution.
[0257] When a collaboration requirement is identified, the agent constructs a collaboration request message and sends it to the target agent through the message passing module. The request message should include:
[0258] request_type: The type of the request (such as data request, information request, help request, etc.);
[0259] request_content: The specific content of the request (such as the name of the data to be requested, problem description, etc.);
[0260] sender_agent_id: The ID of the agent sending the request;
[0261] receiver_agent_id: The ID of the agent receiving the request;
[0262] The agent uses the message passing module to send the request message. After receiving the message, the target agent parses and processes it.
[0263] The target agent processes according to the request type and content and generates a response message. If it is a data request, the target agent will provide the requested data; if it is a help request, the target agent will analyze the problem and provide a solution.
[0264] The requesting agent parses and applies the result after receiving the collaboration response and continues to execute the task.
[0265] The collaboration of agents is completed during the task execution, solving problems such as dependency relationships and data sharing during task execution, and improving the efficiency and quality of task execution.
[0266] The collaboration relationships between agents may have been defined during the task decomposition phase. For example, the output of some tasks is the input of another task, which requires the task scheduler to consider the collaboration requirements between agents to ensure that the collaboration ability can be optimized when tasks are assigned.
[0267] The task execution result is the output of the agent after completing the task, which may include generated code, test reports, documents, etc. The process of generating the result includes the following steps:
[0268] Based on the output_data_specifications information in the task assignment instruction, the agent formats the task execution result to ensure that the result meets the preset standards. For example, the code generation Agent will generate code that conforms to the specified programming language specifications and code style; the testing Agent will generate a test report containing the execution results of test cases and coverage statistics; the documentation Agent will generate API documentation as required, and the format may be Markdown, HTML, or PDF.
[0269] For larger result data or cases that require persistent storage, the agent can choose to store the result data in a specified location, such as a local file system, cloud storage, or database. The storage information can be returned to the task scheduling module in the task status update message.
[0270] The formatted task execution result data is encapsulated into the payload part of the task status update message and prepared to be sent to the task scheduling module.
[0271] The task execution result is the final feedback on the task scheduling and the effectiveness of the task execution. The quality of the task execution result reflects the effects of task scheduling and agent execution. The task execution result needs to conform to the output_data_specifications specification of the task node in the task tree. The task tree clarifies the output requirements for each task and guides the agent to generate the corresponding result data.
[0272] After the task execution is completed, the agent sends a task status update message to the task scheduling module through the message passing module, informing the execution status and result of the task.
[0273] After the task execution is completed, the agent needs to construct a task status update message and send it to the task scheduling module through the message passing module. The task status update message includes:
[0274] message_type: The type of the message, such as "TaskCompletion" (task completed) or "TaskFailure" (task failed).
[0275] sender_agent_id: The ID of the agent sending the message.
[0276] receiver_agent_id: The ID of the task scheduling module receiving the message.
[0277] timestamp: The timestamp when the message is sent.
[0278] payload: The message payload, containing the specific information of the task status update, such as:
[0279] task_id: The ID of the task that has been completed or failed.
[0280] task_status: The status of task execution, such as "completed", "failed", "in_progress", "pending", etc.
[0281] result_data (optional): The result data of task execution (if the data volume is small, it is directly included in the message; if the data volume is large, a reference to the data storage location can be provided).
[0282] error_message (optional): The error message when the task fails.
[0283] execution_log (optional): The task execution log for debugging and auditing.
[0284] Serialized message: Serialize the task status update message data structure into a message format (such as a JSON string).
[0285] Message sending: Use the message passing module to send the task status update message to the task scheduling module. The routing of the message needs to accurately deliver the message to the receiving channel of the task scheduling module based on the receiver_agent_id.
[0286] Status cleanup (inside the agent): After sending the task status update message, the agent can perform internal status cleanup, such as releasing resources, clearing temporary data, and preparing to receive new tasks.
[0287] The task status update message is the final output. After receiving the task status update message, the task scheduling module updates the task status in the task tree and performs subsequent task scheduling based on the task status, such as assigning new dependent tasks to the completed tasks. The task status update message forms a feedback loop between task scheduling and task execution.
[0288] The task_id information in the task status update message identifies the task whose status is updated, and the task_id is derived from the generated task tree. The role of the task status update message is to update the status of the task node in the task tree, so as to keep the task tree up-to-date and ensure that subsequent task scheduling is based on the latest information.
[0289] S150. Output the execution result.
[0290] In this embodiment, the execution result includes the result obtained from the execution of the to-be-assigned subtasks and the corresponding subtask status update message.
[0291] Continuously monitor the message receiving channel provided by the messaging module to receive task status update messages sent by each agent. When an agent completes a task, it sends a task status update message containing the task execution status and result data to the task scheduling module.
[0292] When the task scheduling module receives a message, it needs to filter these messages and only process task status update messages (e.g., message types "TaskCompletion" or "TaskFailure"). Then, extract the task ID from the message payload to identify the execution result of the subtask corresponding to this message.
[0293] Extract the result data (result_data) of the task execution from the payload of the task status update message. Depending on the size and type of the result data, different storage methods are adopted:
[0294] Small data volume results: For small data volume results (e.g., code snippets, test report summaries, document fragments), they can be directly stored in the result_data field of the corresponding task node in the task tree. The task tree can be stored in memory or persistently stored in a database or file system.
[0295] Large data volume results: For large data volume results (e.g., code files, complete test reports, API documents, etc.), references to the data storage location (such as URL links, file paths) can be stored. The agent will provide references to the storage location in the task status update message, and the task scheduling module will store this reference information in the result_data_reference field of the corresponding task node in the task tree, while the data itself is stored in cloud storage (such as AWS S3, Azure BlobStorage), file system or database.
[0296] Update the status of the corresponding task node in the task tree according to the task_status information in the task status update message. For example, if task_status is "completed", update the status of the task node to "completed"; if task_status is "failed", update the status to "failed".
[0297] The task scheduling module needs to determine whether the entire programming task has been completed. The judgment basis includes:
[0298] All leaf node tasks in the task tree are completed: If the leaf nodes of the task tree represent the smallest executable subtasks, when all leaf node tasks are completed, it can be determined that the entire programming task has been completed.
[0299] The root node task status is "completed": The status of the root node of the task tree can be used as the completion status of the entire programming task. When the status of the root node task is updated to "completed", it indicates that the entire programming task is completed.
[0300] According to the type of the specific programming task, some more complex completion conditions can also be defined, such as requiring the completion of a specific number of key tasks, or achieving a certain code coverage rate, test pass rate, etc.
[0301] Summarize and integrate the execution results of each subtask, and finally form a complete programming achievement, such as a complete code project, software system, or API document, etc.
[0302] The task scheduling module needs to collect the execution result data (or data references) of all completed subtasks from the task tree. The task tree can be traversed to extract the result_data or result_data_reference fields of the task nodes with the status of "completed".
[0303] According to the type of the task and the output data specification, judge the data type of the execution result of each subtask. For example, the result of a code generation task is a code file, the result of a test task is a test report, and the result of a document generation task is a document file.
[0304] According to the type and goal of the programming task, select an appropriate result integration strategy to integrate the execution results of each subtask into a complete programming achievement. Common integration strategies include:
[0305] Code project integration: If the programming task is to develop a code project (such as a web application or a library file), it is necessary to integrate the code modules, configuration files, resource files, etc. generated by each code generation agent into a complete project directory structure. It may also be necessary to perform operations such as code compilation, building, and packaging to generate an executable system or code library. Code construction tools (such as Maven, Gradle, npm, Webpack) or containerization technologies (such as Docker) can be used to achieve code project integration. A dedicated code integration agent can be specified to complete this task.
[0306] Document summarization: If the task includes document generation (such as API documentation or user manuals), it is necessary to summarize the document fragments (such as API interface descriptions, function module descriptions) generated by each document generation agent into a complete document file. Document generation tools (such as Sphinx, JSDoc) or document merging tools can be used to achieve document summarization. A dedicated document summarization agent can be responsible for this task.
[0307] Test Report Consolidation: For programming tasks that involve testing (such as unit testing and integration testing), it is necessary to consolidate the test reports generated by individual test agents into an overall test report, summarizing information such as the execution results of test cases, code coverage, and performance metrics. A test report consolidation tool or a test management platform can be used to accomplish this task.
[0308] Data Result Aggregation: If the task is a data analysis or data processing task, it is necessary to aggregate, analyze, and visualize the data results generated by individual data processing agents to generate a final data analysis report or data product. Data analysis tools (such as Pandas, Spark, Tableau) or data visualization libraries (such as Matplotlib, D3.js) can be used to achieve data result aggregation and visualization.
[0309] Direct Combination: For some simple programming tasks, complex integration operations may not be required. Instead, only the result data of individual subtasks need to be simply combined. For example, splicing multiple code snippets into a single code file or merging multiple document fragments into a single document.
[0310] According to user requirements or the target application scenario, it may be necessary to convert the integrated programming result data into a specific format. For example, packaging a code project into a ZIP file or a Docker image, converting a document into PDF or HTML format, exporting a data analysis report as a CSV or Excel file, etc.
[0311] Take an example of project code integration:
[0312] Subtask Result Data: Assume that the code generation agent 1 generates a Python code file user_module.py for the user module, the code generation agent 2 generates a Java code file product_module.java for the product module, the architecture design agent generates a database Schema definition file schema.sql, and the configuration file agent generates an application configuration file application.properties.
[0313] Result Integration Strategy: Code project integration strategy.
[0314] Integration Process:
[0315] Create a project directory structure, such as online_bookstore_project / .
[0316] Copy user_module.py to the python_modules / subdirectory of the project directory.
[0317] Copy product_module.java to the java_modules / subdirectory of the project directory.
[0318] Copy schema.sql to the database / subdirectory of the project directory.
[0319] Copy application.properties to the config / subdirectory of the project directory.
[0320] Write code build scripts (e.g., build.sh, pom.xml) for compiling Java code, packaging Python code, initializing the database, etc.
[0321] Compress the project directory into a ZIP file online_bookstore_project.zip as the final programming result.
[0322] Result integration is the further processing of the execution results of all subtasks, integrating scattered result data into a meaningful whole. The task tree defines the decomposition structure of programming tasks and the relationships between subtasks, providing structured information for result integration. Through the parent-child relationships, dependencies, etc. of the task tree, the order and method of result integration can be determined. The agent pool may contain agents specifically for result integration (such as code integration agents, document summarization agents), and the task scheduling module may also consider the requirements of subsequent result integration during the agent scheduling process.
[0323] Finally, according to the type of programming result and the interactive requirements of the user, select the most suitable display method:
[0324] File creation: If the final result is a file (such as a code project compressed package, document, or data report), the file can be directly generated through commands or tools. After the user confirms, the file will be saved locally. This is applicable to code projects, documents, or report files.
[0325] Code editor display: If the result is a code snippet or code file, it can be directly displayed in the code editor, supporting functions such as code highlighting, editing, and running. This is applicable to code generation or modification tasks.
[0326] Web page display: If the result is a Web application or API, the access link to the deployed application or API can be provided, and the user can access it through a browser. This is applicable to Web development or API development tasks.
[0327] Visualization component display: If the result involves data visualization (such as charts or reports), it can be directly displayed in the user interface through visualization components (such as chart libraries). This is applicable to data analysis or visualization tasks.
[0328] Text output display: For simple text results (such as task completion status, error messages, or brief report summaries), they can be displayed in a text box or log output window. It is suitable for status feedback and display of brief information.
[0329] User interaction function (optional): Some interaction functions can be provided to help users operate and give feedback better:
[0330] Before returning the final result, allow users to preview part of the result, such as viewing code snippets, document summaries, or running a prototype of a web application for a trial run.
[0331] Users can modify the generated programming results, such as editing code, adjusting documents, or changing data analysis parameters. The modified results of users can be used as new inputs to restart the multi-agent assisted programming process for iterative optimization. Collect feedback from users on the results generated by the system, such as satisfaction ratings, code quality evaluations, and function integrity evaluations, etc. These feedbacks will help improve system functions, optimize task scheduling strategies, and enhance the capabilities of agents.
[0332] In this embodiment, by introducing hierarchical task decomposition, multi-agent collaboration, and LLM-based task scheduling, the limitations of the prior art in handling complex programming tasks are solved, and the following unique advantages are brought:
[0333] By subdividing complex programming requirements into multiple simple and manageable subtasks and using a specially designed agent pool to execute these subtasks, the present invention can significantly improve programming efficiency and code quality. This method with clear division of labor not only reduces the workload of a single agent but also ensures that each part can be processed with the most suitable technology, thus improving the fluency of the overall development process and the quality of the results.
[0334] Using the powerful capabilities of LLM for task scheduling, the system can dynamically evaluate and allocate the most suitable agent to complete a specific task. This not only makes task allocation more reasonable and efficient but also can adjust strategies according to real-time situations to adapt to changing requirements. Compared with traditional static or rule-based task allocation methods, this method provides a higher level of flexibility and intelligence.
[0335] The communication and collaboration between agents are achieved through an efficient message-passing-based mechanism. This way promotes the close cooperation between agents, simulates the working mode in a human team, allows agents to share information, coordinate work progress, and even review each other's work results. This greatly enhances the reliability of the system and the quality of the generated code.
[0336] The application scenario of the method in this embodiment far exceeds that of traditional assisted programming tools. It can be used not only in conventional software development projects, but also support the development of low-code / no-code platforms, help non-professional programmers participate in the software development process, and promote innovation. In addition, it also shows great potential in the field of education and can be used as an effective tool for learning and practicing programming skills.
[0337] In summary, the method in this embodiment is not just a simple programming assistance tool, but a comprehensive solution aiming to improve the overall efficiency, quality and flexibility of software development, while expanding its application scope to a wider range of fields.
[0338] The above code generation method based on LLM multi-agent collaboration analyzes the user's programming requirements, generates a task tree and optimizes task allocation. The system efficiently matches agents to execute subtasks, improves resource utilization and development efficiency, and ensures the high-quality completion of the project. Specifically, by obtaining and analyzing the user's programming requirements, the system can quickly understand the task objectives and ensure an accurate grasp of the development direction; based on LLM, the programming requirements are decomposed into a clear task tree to help the system identify the specific details and priorities of tasks and improve the efficiency of task management; according to the expertise of agents and task requirements, the matching degree is evaluated and task allocation is optimized to ensure efficient resource utilization; the flexible task allocation mechanism can adapt to complex requirements and large projects to ensure that each subtask can be executed by the most suitable agent; the feedback of the execution results prompts the system to continuously optimize, ensuring programming quality, improving development efficiency, and achieving continuous progress and collaboration in the project.
[0339] Figure 3 FIG. is a schematic block diagram of a code generation device 300 based on LLM multi-agent collaboration provided by an embodiment of the present invention. As Figure 3 shown, corresponding to the above code generation method based on LLM multi-agent collaboration, the present invention also provides a code generation device 300 based on LLM multi-agent collaboration. The code generation device 300 based on LLM multi-agent collaboration includes units for executing the above code generation method based on LLM multi-agent collaboration, and the device can be configured in a server. Specifically, please refer to Figure 3 , the code generation device 300 based on LLM multi-agent collaboration includes a requirement acquisition unit 301, a task tree generation unit 302, a task allocation instruction generation unit 303, a sending unit 304, and an output unit 305.
[0340] A requirements acquisition unit 301 for acquiring user programming requirements; a task tree generation unit 302 for analyzing and decomposing programming tasks based on an LLM for the user programming requirements to generate a task tree; a task assignment instruction generation unit 303 for selecting a subtask to be assigned from the task tree and generating a task assignment instruction based on the matching degree between an agent in the agent pool and the subtask to be assigned by the LLM; a sending unit 304 for sending the task assignment instruction to a corresponding target agent so that the target agent executes the subtask to be assigned and feeds back an execution result; and an output unit 305 for outputting the execution result.
[0341] In one embodiment, the task tree generation unit 302 includes a conversion subunit, a preliminary decomposition subunit, a recursive analysis subunit, and an organization subunit.
[0342] The conversion subunit is configured to perform a form conversion on the user programming requirements to obtain a conversion result; the preliminary decomposition subunit is configured to input the conversion result into an LLM for in-depth understanding and decompose it into key functional modules and components to obtain a preliminary decomposition result; the recursive analysis subunit is configured to perform recursive decomposition on the preliminary decomposition result to obtain subtasks; and the organization subunit is configured to organize the subtasks into a task tree in a tree structure according to a logical relationship.
[0343] In one embodiment, the task assignment instruction generation unit 303 includes an information acquisition subunit, a screening and sorting subunit, an evaluation subunit, and an instruction generation subunit.
[0344] The information acquisition subunit is configured to acquire real-time agent information; the screening and sorting subunit is configured to screen and sort the subtasks to be assigned from the task tree according to task priorities and dependencies; the evaluation subunit is configured to use an LLM to evaluate the matching degree between each subtask to be assigned and the real-time agent information to obtain a target agent; and the instruction generation subunit is configured to generate a task assignment instruction according to the subtask to be assigned and the target agent.
[0345] In one embodiment, the screening and sorting subunit includes a screening module and a sorting module.
[0346] The screening module is configured to screen candidate subtasks from the task tree by traversing the task tree and checking the subtask status according to task priorities and dependencies; and the sorting module is configured to sort the candidate subtasks using a topological sorting algorithm to obtain the subtasks to be assigned.
[0347] In one embodiment, the sending unit 304 is configured to send the task assignment instruction to the corresponding target agent, so that the target agent parses the task assignment instruction, decomposes the sub-task to be assigned according to the parsing result, and collaborates with other agents to obtain the required data or solve problems, executes the sub-task to be assigned according to the obtained content to generate an execution result, and feeds it back to the execution result.
[0348] It should be noted that those skilled in the art can clearly understand the specific implementation processes of the above code generation device 300 based on LLM multi-agent collaboration and each unit, which can refer to the corresponding descriptions in the foregoing method embodiments. For the sake of convenience and conciseness of description, they will not be elaborated here.
[0349] The above code generation device 300 based on LLM multi-agent collaboration can be implemented in the form of a computer program, and this computer program can run on a computer device as shown in Figure 4 Figure.
[0350] Please refer to Figure 4 , Figure 4 which is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device 50 may be a server. Among them, the server may be an independent server or a server cluster composed of multiple servers.
[0351] Referring to Figure 4 , the computer device 500 includes a processor 502, a memory, and a network interface 505 connected through a system bus 501. Among them, the memory may include a non-volatile storage medium 503 and an internal memory 504.
[0352] The non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions. When the program instructions are executed, the processor 502 can execute a code generation method based on LLM multi-agent collaboration.
[0353] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500.
[0354] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a code generation method based on LLM multi-agent collaboration.
[0355] The network interface 505 is used for network communication with other devices. Those skilled in the art can understand that Figure 4The structure shown is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device 500 to which the solution of this application is applied. Specifically, the computer device 500 may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0356] Among them, the processor 502 is used to run the computer program 5032 stored in the memory to implement the following steps:
[0357] Obtain the user's programming requirements; analyze and decompose the programming tasks based on the LLM to generate a task tree; select the subtasks to be assigned from the task tree, and evaluate the matching degree between the agents in the agent pool and the subtasks to be assigned based on the LLM to generate a task assignment instruction; send the task assignment instruction to the corresponding target agent so that the target agent executes the subtasks to be assigned and feedback the execution result; output the execution result.
[0358] In one embodiment, when the processor 502 implements the step of analyzing and decomposing the programming tasks based on the LLM to generate a task tree, the specific implementation steps are as follows:
[0359] Perform a formal transformation on the user's programming requirements to obtain a transformation result; input the transformation result into the LLM for in-depth understanding and decomposition into key functional modules and components to obtain a preliminary decomposition result; perform recursive decomposition on the preliminary decomposition result to obtain subtasks; organize the subtasks into a tree-structured task tree according to the logical relationship.
[0360] Among them, the task tree records the task descriptions, input and output data, and dependency information of each node.
[0361] In one embodiment, when the processor 502 implements the step of selecting the subtasks to be assigned from the task tree and evaluating the matching degree between the agents in the agent pool and the subtasks to be assigned based on the LLM to generate a task assignment instruction, the specific implementation steps are as follows:
[0362] Obtain the real-time information of the agents; screen and sort the subtasks to be assigned from the task tree according to the task priority and dependency relationship; use the LLM to evaluate the matching degree between each subtask to be assigned and the real-time information of the agents to obtain the target agent; generate a task assignment instruction according to the subtasks to be assigned and the target agent.
[0363] Among them, the task assignment instruction includes the ID of the subtask to be assigned, the ID of the target agent, the task description, and the input data.
[0364] In one embodiment, when the processor 502 implements the step of screening and sorting the subtasks to be assigned from the task tree according to the task priorities and dependencies, the specific implementation is as follows:
[0365] According to the task priorities and dependencies, by traversing the task tree and checking the subtask status, candidate subtasks are screened from the task tree; the topological sorting algorithm is used to sort the candidate subtasks to obtain the subtasks to be assigned.
[0366] In one embodiment, when the processor 502 implements the step of sending the task assignment instruction to the corresponding target agent so that the target agent executes the subtasks to be assigned and feeds back the execution result, the specific implementation is as follows:
[0367] Send the task assignment instruction to the corresponding target agent, so that the target agent parses the task assignment instruction, decomposes the subtasks to be assigned according to the parsed result, collaborates with other agents to obtain the required data or solve problems, executes the subtasks to be assigned according to the obtained content to generate an execution result, and feeds it back to the execution result.
[0368] Wherein, the execution result includes the result obtained by executing the subtasks to be assigned and the corresponding subtask status update message.
[0369] It should be understood that in the embodiments of the present application, the processor 502 may be a central processing unit (CPU), and this processor 502 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or this processor may also be any conventional processor, etc.
[0370] Those of ordinary skill in the art can understand that all or part of the processes in the methods of implementing the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, and the storage medium is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0371] Therefore, the present invention also provides a storage medium. The storage medium can be a computer-readable storage medium. The storage medium stores a computer program, and when the computer program is executed by a processor, the processor performs the following steps:
[0372] Obtain the user's programming requirements; analyze and decompose the programming tasks based on the LLM for the user's programming requirements to generate a task tree; select the subtasks to be assigned from the task tree, and evaluate the matching degree between the agents in the agent pool and the subtasks to be assigned based on the LLM to generate a task assignment instruction; send the task assignment instruction to the corresponding target agent for the target agent to execute the subtasks to be assigned and feedback the execution result; output the execution result.
[0373] In one embodiment, when the processor executes the computer program to implement the step of analyzing and decomposing the programming tasks based on the LLM for the user's programming requirements to generate a task tree, the following steps are specifically implemented:
[0374] Perform a formal transformation on the user's programming requirements to obtain a transformation result; input the transformation result into the LLM for in-depth understanding and decomposition into key functional modules and components to obtain a preliminary decomposition result; perform recursive decomposition on the preliminary decomposition result to obtain subtasks; organize the subtasks into a tree-structured task tree according to the logical relationship.
[0375] Wherein, the task tree records the task descriptions, input and output data, and dependency information of each node.
[0376] In one embodiment, when the processor executes the computer program to implement the step of selecting the subtasks to be assigned from the task tree and evaluating the matching degree between the agents in the agent pool and the subtasks to be assigned based on the LLM to generate a task assignment instruction, the following steps are specifically implemented:
[0377] Obtain the real-time information of the agents; screen and sort the subtasks to be assigned from the task tree according to the task priorities and dependency relationships; use the LLM to evaluate the matching degree between each subtask to be assigned and the real-time information of the agents to obtain the target agent; generate a task assignment instruction according to the subtasks to be assigned and the target agent.
[0378] Wherein, the task assignment instruction includes the ID of the subtask to be assigned, the ID of the target agent, the task description, and the input data.
[0379] In one embodiment, when the processor executes the computer program to implement the step of screening and sorting the subtasks to be assigned from the task tree according to the task priorities and dependency relationships, the following steps are specifically implemented:
[0380] According to the task priorities and dependencies, by traversing the task tree and checking the status of subtasks, candidate subtasks are screened from the task tree; the topological sorting algorithm is used to sort the candidate subtasks to obtain the subtasks to be assigned.
[0381] In one embodiment, when the processor executes the computer program to implement the step of sending the task assignment instruction to the corresponding target agent so that the target agent executes the subtasks to be assigned and feeds back the execution result, the following steps are specifically implemented:
[0382] Send the task assignment instruction to the corresponding target agent, so that the target agent parses the task assignment instruction, decomposes the subtasks to be assigned according to the parsing result, and cooperates with other agents to obtain the required data or solve problems, executes the subtasks to be assigned according to the obtained content to generate an execution result, and feeds it back to the execution result.
[0383] Among them, the execution result includes the result obtained by executing the subtasks to be assigned and the corresponding subtask status update message.
[0384] The storage medium can be various computer-readable storage media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disc, etc., which can store program codes.
[0385] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0386] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0387] The steps in the method of the embodiments of the present invention can be adjusted in sequence, combined, and deleted according to actual needs. The units in the device of the embodiments of the present invention can be combined, divided, and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.
[0388] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present invention.
[0389] The above is only the specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A code generation method based on LLM multi-agent collaboration, characterized in that: include: Obtain user programming requirements; Analyze the user programming requirements based on LLM and decompose programming tasks to generate a task tree; Selecting a subtask to be assigned from the task tree, and evaluating the matching degree between the agent in the agent pool and the subtask to be assigned based on the LLM, and generating a task assignment instruction; Sending the task assignment instruction to the corresponding target agent so that the target agent executes the subtask to be assigned and feeds back the execution result; The execution result is outputted.
2. The code generation method based on LLM multi-agent collaboration according to claim 1 is characterized in that: The step of analyzing the user programming requirements and decomposing programming tasks based on the LLM to generate a task tree includes: Convert the user programming requirement into a form to obtain a conversion result; Input the conversion results into LLM for in-depth understanding and decomposition into key functional modules and components to obtain preliminary decomposition results; Recursively decomposing the preliminary decomposition result to obtain subtasks; The subtasks are organized into a task tree with a tree structure according to logical relationships.
3. The code generation method based on LLM multi-agent collaboration according to claim 2 is characterized in that: The task tree records the task description, input and output data and dependency information of each node.
4. The code generation method based on LLM multi-agent collaboration according to claim 1 is characterized in that: The step of selecting a subtask to be assigned from the task tree, evaluating the matching degree between an agent in an agent pool and the subtask to be assigned based on the LLM, and generating a task assignment instruction includes: Obtain real-time information of intelligent agents; Filter and sort the subtasks to be assigned from the task tree according to task priorities and dependencies; Use LLM to evaluate the matching degree between each subtask to be assigned and the real-time information of the agent to obtain the target agent; Generate a task assignment instruction according to the subtask to be assigned and the target agent.
5. The code generation method based on LLM multi-agent collaboration according to claim 4 is characterized in that: The task assignment instruction includes the ID of the subtask to be assigned, the target agent ID, the task description and the input data.
6. The code generation method based on LLM multi-agent collaboration according to claim 1 is characterized in that: The step of screening and sorting the subtasks to be assigned from the task tree according to the task priorities and dependencies includes: According to the task priorities and dependencies, by traversing the task tree and checking the subtask status, candidate subtasks are screened from the task tree; The candidate subtasks are sorted using a topological sorting algorithm to obtain subtasks to be assigned.
7. The code generation method based on LLM multi-agent collaboration according to claim 1 is characterized in that: The sending of the task assignment instruction to the corresponding target agent so that the target agent executes the subtask to be assigned and feeds back the execution result includes: Send the task assignment instruction to the corresponding target intelligent agent so that the target intelligent agent can parse the task assignment instruction, decompose the subtasks to be assigned according to the parsed results, and collaborate with other intelligent agents to obtain the required data or solve the problem, execute the subtasks to be assigned according to the acquired content to generate an execution result, and feedback the execution result.
8. The code generation method based on LLM multi-agent collaboration according to claim 7 is characterized in that: The execution result includes the result of executing the subtask to be assigned and the corresponding subtask status update message.
9. A code generation device based on LLM multi-agent collaboration, characterized in that: include: A requirement acquisition unit, used to acquire user programming requirements; A task tree generating unit, configured to analyze the user programming requirements and decompose programming tasks based on the LLM to generate a task tree; A task assignment instruction generating unit, configured to select a subtask to be assigned from the task tree, and to generate a task assignment instruction based on the LLM evaluation of the matching degree between the agent in the agent pool and the subtask to be assigned; A sending unit, used for sending the task assignment instruction to the corresponding target agent, so that the target agent executes the subtask to be assigned and feeds back the execution result; An output unit is used to output the execution result.
10. A computer device, characterized in that: The computer device comprises a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the method according to any one of claims 1 to 8 when executing the computer program.
Citation Information
Patent Citations
An artificial intelligence assisted programming construction method
CN119179467B
Cited By
Multi-agent collaborative management method and system
CN120542463A
Robot control method and device, server, warehousing system and storage medium
CN120742745A
Software development system and method and storage medium
CN120743238A
Multi-agent cooperative task processing method and device, equipment and medium
CN120994346A
Component generation method and device, electronic equipment and storage medium
CN121008715A