Multi-agent based code generation method, device, medium and program product
Through the multi-agent collaboration mode and the step-by-step feedback and optimization mechanism of master-slave agents, the problems of full-process collaboration fragmentation and unclear role division in the code generation process are solved, and efficient and clear code generation is achieved for complex code generation tasks.
Patent Information
- Application Number
- CN202510789382.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-13
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-06-13
AI Technical Summary
Existing technologies in the code generation process have problems such as fragmented collaboration across the entire process, unclear division of roles, and static decision-making, making it difficult to meet the needs of complex task scenarios.
A multi-agent collaboration model is adopted, including master agents and slave agents. Through step-by-step feedback and optimization mechanisms, a full-process solution generation and update link is constructed to achieve clear role division, dynamic generation and balance between master and slave agents.
It meets the requirements of complex code generation tasks, improves the quality and efficiency of code generation, and reduces errors caused by role switching and repeated dialogues.
Smart Images

Figure CN120315688B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a multi-agent based code generation method, device, medium and program product. Background Art
[0002] In code generation technology based on large language models, developers only need to enter a brief natural language description or prompt, and the large language model can quickly generate the corresponding code snippet, saving the time of writing code from scratch. Related technologies include: breaking down the code generation task into multiple sub-tasks based on the complexity of the code generation task and the results of semantic understanding to generate standard code; leveraging large language models in conjunction with attention mechanisms, using multiple agents, and achieving toolchain integration through the MCP protocol; and code generation based on the collaboration of heterogeneous multi-agents (such as critic agents and analyst agents).
[0003] However, in the actual code generation process, related technologies have defects such as the fragmentation of full-process collaboration, unclear role division, and static decision-making, which makes it difficult to meet the needs of actual complex task scenarios. Summary of the Invention
[0004] In view of the above problems, the present invention provides a multi-agent based code generation method, apparatus, device, medium and program product.
[0005] According to a first aspect of the present invention, a multi-agent-based code generation method is provided, wherein the multi-agent includes a master agent and a slave agent, and the method includes: in response to code generation requirement information received from a user, determining first evaluation information corresponding to a first processing solution generated by the master agent based on a first strategy, and determining second evaluation information corresponding to a second processing solution generated by the slave agent based on a second strategy, wherein the first processing solution is a master solution generated for the requirement information, and the second processing solution is a slave solution after refinement of the first processing solution; when the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, the second processing solution is updated by the slave agent and the first processing solution is updated by the master agent in sequence to obtain an updated solution; when the updated evaluation information corresponding to the updated solution meets the preset update conditions, code corresponding to the requirement information is generated.
[0006] The second aspect of the present invention provides a code generation device based on multiple agents, wherein the multiple agents include a master agent and a slave agent, and the device includes: an evaluation information determination module, an update module, and a code generation module. The evaluation information determination module is used to determine, in response to code generation requirement information input by a user, first evaluation information corresponding to a first processing scheme generated by the master agent based on a first strategy, and second evaluation information corresponding to a second processing scheme generated by the slave agent based on a second strategy, wherein the first processing scheme is a master scheme generated for the requirement information, and the second processing scheme is a slave scheme after refinement of the first processing scheme; the update module is used to update the second processing scheme using the slave agent and the first processing scheme using the master agent in sequence to obtain an updated scheme when the first evaluation information and the second evaluation information do not meet the preset evaluation conditions; the code generation module is used to generate code corresponding to the requirement information when the updated evaluation information corresponding to the updated scheme meets the preset update conditions.
[0007] The third aspect of the present invention provides an electronic device comprising: a memory; and a processor configured to execute the above-mentioned multi-agent-based code generation method according to instructions and data stored in the memory.
[0008] The fourth aspect of the present invention further provides a computer-readable storage medium having a computer program or instructions stored thereon, which implements the steps of the above method when the computer program or instructions are executed by a processor.
[0009] The fifth aspect of the present invention further provides a computer program product, comprising a computer program or instructions, which implement the steps of the above method when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The above contents and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
[0011] Figure 1 An application scenario diagram of a multi-agent-based code generation method, apparatus, device, medium, and program product according to an embodiment of the present invention is shown;
[0012] Figure 2 A flowchart of a multi-agent based code generation method according to an embodiment of the present invention is shown;
[0013] Figure 3 A flowchart of another multi-agent-based code generation method according to an embodiment of the present invention is shown;
[0014] Figure 4Shown is a structural block diagram of a multi-agent based code generation device according to an embodiment of the present invention;
[0015] Figure 5 A block diagram of an electronic device for executing a multi-agent-based code generation method according to an embodiment of the present invention is shown;
[0016] Figure 6 A block diagram of an electronic device suitable for implementing a multi-agent based code generation method according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0017] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concept of the present invention.
[0018] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the presence of the features, steps, operations and / or components, but do not exclude the presence or addition of one or more other features, steps, operations or components.
[0019] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0020] When expressions such as "at least one of A, B, and C, etc." are used, they should generally be interpreted in accordance with the meaning commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0021] In some examples, planning engineers break down code task information into multiple sub-code tasks based on the complexity of the code generation task and semantic understanding. The sub-code tasks are converted into Python code sequences by a code writing agent. The sub-code blocks of the Python code sequences are then combined into standard execution functions by a code integration agent. Each Python code sequence is executed according to the standard execution function to generate standard code. The standard code is corrected by a code testing agent and then returned to the user.
[0022] However, this method only focuses on the error rate and test coverage of the generated code, without considering global factors such as requirement consistency and development cycle. It can only generate simple code with clear requirements and complete design, and is unable to cope with more complex tasks.
[0023] In some examples, a pre-trained large-scale language model is combined with an attention mechanism to generate an enhanced semantic understanding vector corresponding to the initial source code; logical error patterns are identified to determine the defect type and location of the initial source code; a reinforcement learning algorithm selects the optimal repair path by simulating multiple repair paths and evaluating the effectiveness of each repair path, and generates a repair code snippet through the optimal repair path; the repair code snippet replaces the corresponding part in the initial source code, and generates the target source code; the target source code is scored based on the code quality assessment model to obtain quality feedback results; and the target source code with change annotations and quality feedback results is output.
[0024] However, this solution uses multiple agents and implements tool chain integration through the Model Context Protocol (MCP). It focuses on automated processes but lacks intelligent collaboration. The collaboration between multiple agents is only through dialogue and collaborative work to complete process automation. There is a lack of clear division of responsibilities. The collaboration between agents only relies on dialogue or manually defined rules for correction. It is difficult to balance the conflicts of multiple goals, and global optimization cannot be achieved through dynamic game. It is easy for each agent to fall into role switching and repeated dialogue.
[0025] In some examples, a critic agent instantiated with a specialized heterogeneous large language model is added to the multi-agent collaboration process. The critic agent is used to verify the consistency and feasibility of the requirement documents provided by the analyst agent, and to make modification suggestions at an early stage, so as to promptly detect deviations and problems in the early stages of the task, thereby reducing the cost and complexity of later corrections to a certain extent.
[0026] However, this solution uses heterogeneous critic agents to verify requirements, focusing only on the early requirements analysis stage, not covering the entire process of quality control, and lacking full-link closed-loop collaboration from requirements design to testing, resulting in fragmentation in the requirements transmission process due to the ambiguity of semantic expression.
[0027] Based on the above problems, the present invention provides a code generation method based on multiple agents, wherein the multiple agents include a master agent and a slave agent, and the method includes: in response to code generation requirement information received from a user, determining first evaluation information corresponding to a first processing solution generated by the master agent based on a first strategy, and determining second evaluation information corresponding to a second processing solution generated by the slave agent based on a second strategy, wherein the first processing solution is a master solution generated for the requirement information, and the second processing solution is a slave solution after refinement of the first processing solution; when the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, the slave agent is used to update the second processing solution and the master agent is used to update the first processing solution in turn to obtain an updated solution; when the updated evaluation information corresponding to the updated solution meets the preset update conditions, code corresponding to the requirement information is generated.
[0028] According to an embodiment of the present invention, through the multi-role collaboration of the master agent and the slave agent, for the code generation requirement information, based on the processing strategies corresponding to the master and slave agents respectively, hierarchical master-slave processing solutions and corresponding evaluation information are positively generated. Since the update process of the master-slave processing solution is to use the slave agent and the master agent in turn to provide step-by-step feedback and optimization of the master and slave processing solutions, the positive quality evaluation of the processing solution and the downstream feedback triggering update mechanism are realized, the full-process solution generation and update link is constructed, and the dynamic generation and balance of the upstream and downstream agent decisions are realized, which makes the role division of the master and slave agents clearer and further meets the needs of complex code generation tasks.
[0029] Figure 1 An application scenario diagram of the multi-agent-based code generation method, apparatus, device, medium, and program product according to an embodiment of the present invention is shown.
[0030] like Figure 1 As shown, the application scenario according to this embodiment may include a terminal device 101, a network 102, and a server 103. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired or wireless communication links or optical fiber cables.
[0031] A user can use a terminal device 101 to interact with a server 103 via a network 102 to receive or send messages, etc. The terminal device 101 can be any electronic device with a display screen and supporting web browsing, including but not limited to a smartphone, a tablet computer, a laptop computer, a desktop computer, and the like.
[0032] An application for code generation may be installed on the terminal device 101. For example, a user inputs code generation requirement information, such as text or natural language instructions describing the required functions, through a specific interface (such as a command line tool, a graphical interface application, etc.) on the terminal device 101.
[0033] For example, the application on the terminal device 101 can perform necessary preprocessing on the code generation requirement information input by the user, such as formatting and verifying the input content, and then package the requirement information into an appropriate format through a network transmission protocol and send it to the server 103.
[0034] The server 103 may be a server that provides various services. For example, after receiving a user request from the network, the server 103 parses the request and extracts the code generation requirement information therein. The server 103 may run a specific backend service or application to process these requests.
[0035] For example, server 103 can invoke a multi-agent (large language model) to generate code based on the parsed user requirements. The user's requirements can be input into the model as prompts, and the model generates the corresponding code based on its training knowledge and algorithms. The code can also be subjected to syntax checking and logic verification to improve the usability of the generated code.
[0036] It should be noted that the multi-agent-based code generation method provided in the embodiment of the present invention can generally be executed by the server 103. Accordingly, the multi-agent-based code generation device provided in the embodiment of the present invention can generally be set in the server 103. The multi-agent-based code generation method provided in the embodiment of the present invention can also be executed by a server or server cluster that is different from the server 103 and can communicate with the terminal device 101 and / or the server 103. Accordingly, the multi-agent-based code generation device provided in the embodiment of the present invention can also be set in a server or server cluster that is different from the server 103 and can communicate with the terminal device 101 and / or the server 103.
[0037] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0038] Figure 2 A flowchart of a multi-agent based code generation method according to an embodiment of the present invention is shown.
[0039] like Figure 2 As shown, the multi-agent includes a master agent and a slave agent. The multi-agent-based code generation method of this embodiment may include operations S210 to S230.
[0040] In operation S210, in response to receiving the code generation requirement information input by the user, first evaluation information corresponding to the first processing solution generated by the main agent based on the first strategy is determined, and second evaluation information corresponding to the second processing solution generated by the slave agent based on the second strategy is determined, wherein the first processing solution is the main solution generated for the requirement information, and the second processing solution is the slave solution after refinement of the first processing solution.
[0041] In an embodiment of the present invention, the first strategy may represent the strategy of the master agent to process demand information based on the expected processing solution and corresponding evaluation information of the predicted slave agent. The second strategy may represent the strategy of the slave agent to refine the solution based on the first processing solution according to the evaluation information of at least one of the adjacent agents. It should be understood that the slave agent may be a downstream agent of the master agent in the code generation process. According to the actual needs of the code generation process, there may be multiple master agents and slave agents. The master agent and the slave agent are relative. A certain agent may correspond to the master agent in a certain scenario and to the slave agent in another scenario.
[0042] For example, after receiving the demand information input by the user through the terminal device, the master agent can generate a first processing solution corresponding to the demand information according to the first strategy. On this basis, the slave agent can refine and split each part of the first processing solution to obtain a refined second processing solution, thereby determining the first evaluation information including multiple dimensions corresponding to the first processing solution and the second evaluation information corresponding to the second processing solution.
[0043] In operation S220, when the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, the second processing solution is updated by the slave agent and the first processing solution is updated by the master agent in sequence to obtain an updated solution.
[0044] In an embodiment of the present invention, the preset evaluation condition may include an evaluation threshold and an error evaluation condition corresponding to the first evaluation information and the second evaluation information respectively.
[0045] For example, when updating the first processing plan and the second processing plan, the second processing plan can be updated first by the slave agent based on the downstream feedback mechanism to obtain the updated second processing plan; then the master agent can use the updated second processing plan to update the first processing plan to obtain an updated plan.
[0046] In operation S230 , when the update evaluation information corresponding to the update plan meets a preset update condition, a code corresponding to the requirement information is generated.
[0047] In an embodiment of the present invention, the update evaluation information may be evaluation information determined for the update scheme. The preset update condition may include an update condition determined by the difference between update schemes at different times and a threshold corresponding to the number of updates.
[0048] It is understood that the master agent and slave agents in this embodiment can each be different functional modules in the code generation framework. Each module can correspond to a large language model, which can decompose user requirements into a specific function list to achieve automatic code generation based on the collaboration between different functional modules. The type of large language model can be determined according to actual needs and is not limited here.
[0049] According to an embodiment of the present invention, through the multi-role collaboration of the master agent and the slave agent, for the code generation requirement information, based on the processing strategies corresponding to the master and slave agents respectively, hierarchical master-slave processing solutions and corresponding evaluation information are positively generated. Since the update process of the master-slave processing solution is to use the slave agent and the master agent in turn to provide step-by-step feedback and optimization of the master and slave processing solutions, the positive quality evaluation of the processing solution and the downstream feedback triggering update mechanism are realized, the full-process solution generation and update link is constructed, and the dynamic generation and balance of the upstream and downstream agent decisions are realized, which makes the role division of the master and slave agents clearer and further meets the needs of complex code generation tasks.
[0050] It can be understood that the above has already described how to generate the code corresponding to the demand information, and the following will describe how to determine the second evaluation information.
[0051] According to an embodiment of the present invention, the second evaluation information includes the second actual evaluation information of the adjacent intelligent agent of the slave intelligent agent, and the second strategy includes the processing strategy of the initial solution generated by the slave intelligent agent; determining the second evaluation information corresponding to the second processing solution generated by the slave intelligent agent based on the second strategy includes: using preset weights to perform weighted processing on the second actual evaluation information to obtain a second weighted result; processing the second weighted result based on the processing strategy to obtain a second processing solution, and generating second evaluation information corresponding to the second processing solution, wherein the processing strategy is determined by the role information of the slave intelligent agent.
[0052] In an embodiment of the present invention, the adjacent agent may include at least one of an upstream agent and a downstream agent corresponding to the agent. The preset weight may include multiple weights corresponding to different slave agents. The second actual evaluation information may be actual evaluation information corresponding to multiple processing schemes obtained from the upstream agent and / or downstream agent of the slave agent. The second processing scheme may include multiple processing schemes based on different role types of the slave agent. The processing strategy may include a maximization processing strategy and a minimization processing strategy based on the different slave agent role information.
[0053] For example, based on a hierarchical decision-making strategy, multiple weights corresponding to different slave agents can be used to weight the actual evaluation information corresponding to each of the multiple processing solutions to obtain a second weighted result; thereby maximizing or minimizing the second weighted result to obtain multiple processing solutions corresponding to different slave agents; and then generating evaluation information corresponding to the multiple processing solutions, and combining the multiple evaluation information to obtain the second evaluation information.
[0054] According to an embodiment of the present invention, the slave agents include at least one of the following: a design agent, an allocation agent, a generation agent and a test agent, and the preset weights include at least one of the following: a design analysis weight and a design allocation weight corresponding to the design agent, a granularity weight and a rationality weight corresponding to the allocation agent, a realization weight and an error weight corresponding to the generation agent, and a coverage weight and an efficiency weight corresponding to the test agent.
[0055] Preferably, the second actual evaluation information is weighted using preset weights to obtain a second weighted result, including at least one of the following: using the design analysis weight and the design allocation weight to weight the analysis evaluation information and the allocation evaluation information in the second actual evaluation information respectively, to obtain a second design weighted result corresponding to the design agent in the second weighted result; using the granularity weight and the rationality weight to weight the granularity evaluation information and the rationality evaluation information in the second actual evaluation information respectively, to obtain a second allocation weighted result corresponding to the allocation agent in the second weighted result; using the realization weight and the error weight to weight the realization evaluation information and the error information in the second actual evaluation information respectively, to obtain a second generation weighted result corresponding to the generation agent in the second weighted result; using the coverage weight and the efficiency weight to weight the test coverage and the defect detection efficiency in the second actual evaluation information respectively, to obtain a second test weighted result corresponding to the test agent in the second weighted result.
[0056] In an embodiment of the present invention, the role of the design agent can be an architect, who can generate an architecture design plan and output an architecture document; the architecture design plan can include module division and technology selection. The role of the allocation agent can be a project manager, who can generate a task splitting plan based on the architecture design plan and output a task list; the architecture design plan can include work task dependencies and resource allocation. The role of the generation agent can be an engineer, who can implement code generation and output code based on the architecture design plan; code generation can include code style and framework selection. The role of the test agent can be a tester, who can design test cases based on the generated code and output a test case set; the test case design can include coverage paths and boundary conditions.
[0057] In an embodiment of the present invention, the analysis and evaluation information may be the functional design support evaluation value of the initial solution generated by the design agent by the upstream agent (i.e., the analysis agent) of the design agent, and the allocation evaluation information may be the scalability evaluation value of the initial solution generated by the design agent by the downstream agent (i.e., the allocation agent) of the design agent.
[0058] For example, the functional design support evaluation value may be weighted using the design analysis weight, and the scalability evaluation value may be weighted using the design allocation weight to obtain a second design weighted result.
[0059] In an embodiment of the present invention, granularity evaluation information can be a comprehensive evaluation of the task split granularity and functional dependency rationality of the initial solution generated by the assigning agent by multiple downstream agents (i.e., the generating agent and the testing agent). The task split granularity and functional dependency rationality can be evaluated by the generating agent and the testing agent, and the average value can be obtained.
[0060] For example, the granularity weight may be used to weight the task splitting granularity, and the rationality weight may be used to weight the rationality of the functional dependency to obtain a second allocation weighted result.
[0061] In embodiments of the present invention, achievement evaluation information can be the degree to which the generated code achieves the task, which can be obtained by checking function point coverage using static code analysis tools. Error information can be the number of vulnerabilities (bugs) per unit line of code, which can be obtained by testing with a test agent. It should be noted that the specific methods for determining achievement and error information are not limited herein.
[0062] For example, the realization degree may be weighted by the realization degree weight, and the number of bugs may be weighted by the error weight, to obtain a second generated weighted result.
[0063] In an embodiment of the present invention, the test coverage can be calculated by a unit test tool, and the defect detection efficiency can be determined by the number of valid bugs detected and the number of bugs detected by the test case. It should be noted that the specific form of bug detection is not limited here.
[0064] For example, the test coverage may be weighted using the coverage weight, and the defect detection efficiency may be weighted using the efficiency weight, thereby obtaining a second test weighted result.
[0065] In a feasible embodiment, multiple test agents (such as programmers, test designers, and test execution agents) can be used to generate test cases based on actual test requirements, including basic tests, edge tests, and large-scale input tests. The test execution agent can execute code and test cases in a local environment and feed back the results to the programmer agent. If the test case fails, the error information will be fed back to the programmer agent for iterative correction.
[0066] According to an embodiment of the present invention, by dividing the work and cooperating among multiple test agents and testing the code from different angles, problems in the code can be discovered more comprehensively and the test coverage can be improved. At the same time, the process of iterative optimization of multiple agents can help to timely discover and correct code defects and improve code quality.
[0067] According to an embodiment of the present invention, during the code generation process, each intelligent agent verifies and optimizes its own processing solution from multiple angles based on the predicted evaluation information of upstream and downstream intelligent agents, which can form a multi-layer protection mechanism. This collaborative verification and optimization method can more comprehensively discover problems in the code and reduce the risk of failure after the code is launched.
[0068] According to an embodiment of the present invention, the second weighted result is processed based on the processing strategy to obtain a second processing scheme, and second evaluation information corresponding to the second processing scheme is generated, including: processing the second test weighted result based on the test strategy corresponding to the test agent to obtain a second test scheme; processing the second generation weighted result based on the generation strategy corresponding to the generation agent to obtain a second generation scheme; processing the second allocation weighted result based on the allocation strategy corresponding to the allocation agent to obtain a second allocation scheme; processing the second design weighted result based on the design strategy corresponding to the design agent to obtain a second design scheme; combining multiple evaluation information of the second design scheme, the second allocation scheme, the second generation scheme and the second test scheme to obtain second evaluation information.
[0069] In an embodiment of the present invention, the second processing solution may include a second testing solution, a second generation solution, a second allocation solution, and a second design solution. The testing strategy may be a method that maximizes test coverage and defect detection efficiency. The generation strategy may be a method that maximizes the match between code implementation and tasks while minimizing the defect rate. The allocation strategy may be a method that maximizes the rationality of task splitting. The design strategy may be a method that maximizes the support of the architecture for functional design while minimizing technical debt.
[0070] For example, the second test scenario can maximize test coverage by and defect detection efficiency To determine, the specific formula is as follows (1):
[0071] (1);
[0072] Among them, Q Test It can be the second test plan, that is, the test decision of the test agent. and can be coverage weight and efficiency weight respectively, It can be the test coverage, calculated by the unit testing tool; Can improve defect detection efficiency.
[0073] The second generation scheme can be determined by maximizing the matching degree between the code implementation and the task while minimizing the defect rate, as shown in the following formula (2):
[0074] (2);
[0075] in, The second generation scheme can be represented, that is, the generation decision of the generation agent. It can indicate the degree of implementation of the code for the task. It can be expressed as the number of bugs per unit line of code. and They can be realization weight and error weight respectively.
[0076] The second allocation scheme can be determined by maximizing the rationality of task splitting, as shown in the following formula (3):
[0077] (3);
[0078] in, The second allocation scheme can be expressed as the allocation decision of the allocation agent. It can represent the task splitting granularity, It can express the rationality of functional dependency, and It can be granularity weight or rationality weight.
[0079] The second design solution can be determined by maximizing the support of the architecture for functional design while minimizing the technical debt, as shown in the following formula (4):
[0080] (4);
[0081] in, The second design solution can be to design the architecture strategy of the intelligent agent; and They can represent design analysis weight and design allocation weight respectively; It can represent the functional design support degree evaluated by its upstream agent (i.e., analysis agent), Represents the scalability score evaluated by its downstream agent (i.e., the allocation agent).
[0082] In a feasible embodiment, the analysis plan of the analysis agent in the master agent can be determined by maximizing the demand coverage: ,in, It can represent the actual evaluation value of the user on the initial analysis plan generated by the analysis agent.
[0083] According to an embodiment of the present invention, by considering the collaborative work of each intelligent agent from the overall system level, each intelligent agent will optimize and update the initial plan after receiving evaluation feedback from upstream and downstream intelligent agents, so that different intelligent agents can collaborate more closely and efficiently, thereby enhancing the functional integrity of code generation.
[0084] According to an embodiment of the present invention, the method further includes: obtaining multiple test results for the initial test plan generated for the test agent; and determining the ratio between the total number of errors and the number of use cases in the multiple test results as the defect detection efficiency.
[0085] The total number of errors can be the total number of valid bugs for the initial test plan. The total number of errors is the number of bugs detected by the test case plus the number of bugs detected by the code detection tool.
[0086] According to an embodiment of the present invention, the first evaluation information includes the first actual evaluation information and expected information of the adjacent intelligent agents of the main intelligent agent, and the first strategy includes weight change information corresponding to the expected information; determining the first evaluation information corresponding to the first processing scheme generated by the main intelligent agent based on the first strategy includes: determining the expected information corresponding to the initial scheme generated by the main intelligent agent; using the weight change information to weightedly process the expected information to obtain a first weighted result; combining the first weighted result and the first actual evaluation information to obtain the first evaluation information.
[0087] The expected information can be the expected processing strategy of the slave agent based on the guidance information currently obtained by the master agent. The guidance information can be the requirements or strategy information provided by the user or upstream agent. The weight change information can be the weight change coefficient.
[0088] For example, according to the obtained strategy information corresponding to the main agent A1 and the main agent B, the expected processing strategies A1' and B' corresponding to the initial solutions generated by the main agent A1 and the main agent B are determined respectively, so as to use the weight change coefficient W A 、W B Perform weighted processing on the expected processing strategies A1' and B' to obtain multiple weighted results W A A1' and W B B'.
[0089] According to an embodiment of the present invention, the main agent includes at least one of the following: an analysis agent, a design agent, an allocation agent and a generation agent; determining the expected information corresponding to the initial plan generated by the main agent includes: obtaining probability-related information and distribution characteristics corresponding to the analysis agent, the design agent, the allocation agent and the generation agent respectively; and determining the expected information based on the probability-related information and distribution characteristics.
[0090] The role of the analysis agent can be a product manager. Based on the requirements input by the user, it can generate a requirements analysis plan and output functional documentation. The requirements analysis plan can include a feature list and priority ranking information. The priority ranking information can be the priority ranking of different features in the feature list. The method for determining expected information can be determined based on the type of random variable. It can include the expected value of a discrete random variable or the expected value of a continuous random variable. Probability-related information can represent the probability density result of the random variable.
[0091] For example, considering that the distribution characteristics of the initial plans generated by the analysis agent, design agent, allocation agent and generation agent are continuous random variables, the method of determining the expected information may include: assuming that the initial plan obeys a uniform distribution in the interval [a, b], then the probability density function of the initial plan can be calculated, and then the expected information can be calculated using the probability density function.
[0092] According to an embodiment of the present invention, the expected information corresponding to the initial plan generated by the main agent is determined, including: determining the current expected evaluation plan of the design agent relative to the current analysis plan generated by the analysis agent at the current moment, the current expected allocation plan of the allocation agent relative to the current design plan generated by the design agent, the current expected generation plan of the generation agent relative to the current allocation plan generated by the allocation agent, and the current expected test plan of the test agent relative to the current generation plan generated by the generation agent.
[0093] The expected information may include an expected evaluation plan, an expected allocation plan, an expected generation plan, and an expected testing plan.
[0094] For example, the expected evaluation scheme can be to analyze the agent based on the current requirement document at the current moment The expected decision result of the architect is given below. The current expected allocation scheme can be used to design the agent based on the current architecture document at the current moment. The expected decision result of the project manager is given below. The current expected generation scheme can assign agents based on the current task list at the current moment. The expected engineer decision results. The current expected test plan can generate an agent based on the current task list at the current moment. The expected outcome of the engineer's decision.
[0095] According to an embodiment of the present invention, the weight change information includes at least one of the following: analysis weight change corresponding to the analysis agent, design weight change corresponding to the design agent, allocation weight change corresponding to the allocation agent, and generation weight change corresponding to the generation agent.
[0096] Preferably, the expected information is weighted using the weight change information to obtain a first weighted result, including at least one of the following: using the analysis weight change to weight the current expected evaluation scheme to obtain a first analysis weighted result; using the design weight change to weight the current expected allocation scheme to obtain a first design weighted result; using the allocation weight change to weight the current expected generation scheme to obtain a first allocation weighted result; using the generation weight change to weight the current expected test scheme to obtain a first generation weighted result.
[0097] The weight change information may characterize a weight decay coefficient affected by downstream decisions, and may include at least one of analyzing weight changes, designing weight changes, allocating weight changes, and generating weight changes.
[0098] For example, the analysis weight change γ can be determined according to the actual code generation requirements. PM , design weight change γ Arch , distribution weight change γ Mgr and generate weight changes γ Eng , γ PM , γ Arch , γ Mgr and γ Eng The specific values can be the same, or they can be determined to be different values according to different actual scores; PM , γ Arch , γ Mgr and γ EngThe expected evaluation scheme, the expected allocation scheme, the expected generation scheme, and the expected test scheme are weighted respectively to obtain a first analysis weighted result, a first design weighted result, a first allocation weighted result, and a first generation weighted result.
[0099] According to an embodiment of the present invention, the first weighted result and the first actual evaluation information are combined to obtain the first evaluation information, including at least one of the following: the acquired analysis evaluation value is combined with the first analysis weighted result to obtain the first analysis evaluation value corresponding to the analysis agent; the second design weighted result is combined with the first design weighted result to obtain the first design evaluation value corresponding to the design agent; the second allocation weighted result is combined with the first allocation weighted result to obtain the first allocation evaluation value corresponding to the allocation agent; the second generation weighted result is combined with the first generation weighted result to obtain the first generation evaluation value corresponding to the generation agent.
[0100] In an embodiment of the present invention, the analysis evaluation value may be an evaluation value determined by the user for the initial analysis plan of the analysis agent. The first analysis evaluation value may be the decision result of the analysis agent affected by the decision of the downstream agent (architect); the first design evaluation value may be the decision result of the design agent affected by the decision of the downstream (project manager); the first allocation evaluation value may be the decision result of the allocation agent affected by the decision of the downstream (engineer); the first generation evaluation value may be the generation agent's decision in the current code. The expected test decision results.
[0101] For example, by analyzing the decision-making process of the intelligent agent (product manager), the architect's reaction can be predicted as shown in the following formula (5):
[0102] (5);
[0103] in, can represent decision outcomes that are affected by downstream (architect) decisions, γ PM It can represent the weight attenuation coefficient affected by downstream decisions, Can be expressed in the current requirements document The expected outcomes of the architect's decisions.
[0104] During the architect’s decision-making process, the project manager’s reaction can be predicted as shown in the following formula (6):
[0105] (6);
[0106] in, It can represent the decision result of the architect affected by the decision of the downstream (project manager), γ Arch It can represent the weight attenuation coefficient affected by downstream decisions, Can be expressed in the current architecture document The expected outcomes of project managers’ decisions.
[0107] During the project manager's decision-making process, the engineer's reaction can be predicted, as shown in the following formula (7):
[0108] (7);
[0109] in, It can represent the decision results affected by downstream (engineer) decisions, γ Mgr It can represent the weight attenuation coefficient affected by downstream decisions, Indicates that the current task list The expected outcome of the engineer's decision.
[0110] During the engineer's decision-making process, the test response can be predicted as shown in the following formula (8):
[0111] (8);
[0112] in, can represent the decision results affected by downstream (test) decisions, γ Eng It can represent the weight attenuation coefficient affected by downstream decisions, Indicates that in the current code The expected outcome of the engineer's decision.
[0113] For example, by predicting the responses of slave agents based on a dynamic master-slave game mechanism, decision paths and action plans can be planned in advance, making the agents' own decisions more forward-looking and targeted, and reducing errors and repeated revisions caused by information asymmetry or blind decisions. Through dynamic prediction and balancing, the decisions of upstream and downstream agents can form an orderly decision sequence, working together to achieve the goals of the code generation system.
[0114] According to an embodiment of the present invention, the preset evaluation conditions include a first threshold corresponding to the first evaluation information, and the first threshold includes a first analysis threshold, a first design threshold, a first allocation threshold and a first generation threshold corresponding to the analysis agent, the design agent, the allocation agent and the generation agent respectively.
[0115] Preferably, when the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, the second processing scheme is updated in sequence by the slave agent and the first processing scheme is updated by the master agent to obtain an updated scheme, including at least one of the following: when the first generation evaluation value is less than the first generation threshold and the second test scheme meets the test error condition, the second generation scheme and the first generation scheme are updated in sequence to obtain a test update scheme in the updated scheme; when the first allocation evaluation value is less than the first allocation threshold and the number of updates of the second generation scheme is greater than the generation update threshold, the second allocation scheme and the first allocation scheme are updated in sequence to obtain an allocation update scheme in the updated scheme; when the first design evaluation value is less than the first design threshold and the second allocation scheme meets the allocation error condition, the second design scheme and the first design scheme are updated in sequence to obtain a design update scheme in the updated scheme; when the first analysis evaluation value is less than the first analysis threshold and the number of updates of the second design scheme is greater than the design update threshold, the second analysis scheme and the first analysis scheme are updated in sequence to obtain an analysis update scheme in the updated scheme.
[0116] The update scheme can be multiple update schemes from the downstream agent to the upstream agent, such as the test update scheme, the allocation update scheme, the design update scheme, and the analysis update scheme. The quality evaluation vector of the processing scheme in the expected feedback process can be defined as Q*, , and the quality assessment vector Q during back propagation, , when a value in the vector is lower than a given threshold, the scheme is updated (k in the following expression can represent the first The update process of the update scheme can include expected feedback and downstream feedback.
[0117] For example, the test update solution can be the solution obtained after the engineer updates the code, and the expected feedback can be: Less than the first generation threshold , can trigger code modification and regenerate code; downstream feedback can be: when testing Or when a fatal defect is found (detected by code detection tools), the test can generate bug correction instructions (which can be recorded as ΔC) and feedback to the engineer, requiring code rework , where C k The code generated for the current moment, C k+1 It can be the code after the update (at a later time).
[0118] For example, the allocation update plan can be the solution obtained by the project manager re-splitting the task. Less than the first allocation threshold , can trigger task re-splitting; downstream feedback can be: if the number of code reworks exceeds the threshold , which can trigger the project manager to re-split tasks , Can be expressed according to The generated task re-splitting prompt words. Among them, T k A task list can be generated for the current moment, C k The code generated for the current moment, TE k It can be the test case at the current moment. k+1 It can be an updated task list.
[0119] For example, the design update solution can be the solution obtained by the architect's architecture consistency check. The expected feedback can be: Less than the first design threshold , which can trigger the architecture update instruction; the downstream feedback can be: after each round of task splitting by the project manager, the architect can re-check the consistency of the architecture (design plan) and the requirements (analysis plan) and generate an architecture patch (which can be recorded as ΔA), that is Among them, A k+1 Can be updated architecture document, A k The architecture documentation that can be generated for the current moment.
[0120] For example, the analysis and update plan can be the solution obtained by the product manager when he changes the requirements. The expected feedback can be: Less than the first analysis threshold Or when the user actively requests it, the demand update instruction can be triggered; downstream feedback can be: the cumulative number of updates or revisions at the architecture layer Greater than the update threshold The capability document can be re-evaluated when , generate the required patch (which can be recorded as ΔF), that is Among them, F k The function document generated for the current moment, F k+1 Can be updated function documentation.
[0121] According to embodiments of the present invention, an automated process correction link can improve information sharing and collaborative work between master and slave agents. Data and information between agents involved in analysis, design, allocation, generation, and testing can flow in real time, allowing each agent to promptly understand each other's progress, problems, and solutions. This avoids information silos, improves code generation efficiency, and enhances collaboration. Based on positive decision quality assessment vectors and downstream feedback triggering mechanisms (such as test defect feedback driving code corrections and architecture patch generation), an automated correction link for the entire process, from requirements to testing, is established. This reduces manual intervention, lowers rework costs, mitigates the impact of conflicting objectives, and improves the consistency of requirements, architecture, and code.
[0122] According to an embodiment of the present invention, the preset update condition includes at least one of the following: the difference between the current update evaluation value of the update scheme at the current moment and the previous update evaluation value of the update scheme at the previous moment is less than the preset evaluation threshold; the number of updates of the update scheme at the current moment is greater than the preset iteration threshold.
[0123] In an embodiment of the present invention, the preset update condition may be an iterative termination condition for code generation. For example, the previous update evaluation value at the previous moment and the current update evaluation value at the current moment may be obtained, thereby calculating the difference between the current update evaluation value and the previous update evaluation value, and comparing the difference with a preset evaluation threshold. If the difference is less than the preset evaluation threshold, code generation is completed and the code is output and returned to the user. The current update evaluation value may be denoted as Q k+1 , the updated evaluation value is recorded as Q k , the preset evaluation threshold is recorded as ,when or number of iterations Greater than the specified number of iterations When , stop the solution update and complete code generation.
[0124] For example, the update count of the current solution update can be determined and compared with a preset iteration threshold. If the update count threshold is greater than the preset iteration threshold, the solution update can be stopped and code generation can be completed.
[0125] Figure 3 A flowchart of another multi-agent-based code generation method according to an embodiment of the present invention is shown.
[0126] like Figure 3 As shown, the multi-agent may include an analysis agent, a design agent, an allocation agent, a generation agent, and a test agent. The multi-agent-based code generation method may include operations S301 to S313.
[0127] In operation S301, a user inputs a code to generate demand information through a terminal device.
[0128] In operation S302 , the analysis agent determines an initial analysis plan and initial analysis evaluation information corresponding to the initial analysis plan based on the received demand information and the processing strategy.
[0129] In operation S303 , the design agent refines the initial analysis plan to obtain an initial design plan and initial design evaluation information corresponding to the initial design.
[0130] In operation S304 , the allocation agent refines the initial design solution to obtain an initial allocation solution and initial allocation evaluation information corresponding to the initial allocation solution.
[0131] In operation S305 , the generating agent refines the initial allocation plan to obtain an initial generating plan and initial generating evaluation information corresponding to the initial generating plan.
[0132] In operation S306 , the test agent refines the initial generation plan to obtain an initial test plan and initial test evaluation information corresponding to the initial test plan.
[0133] In operation S307 , when the initial test evaluation information does not meet the preset evaluation conditions, the test agent is used to update the initial test plan to obtain an intermediate test plan, and a plan update instruction is triggered.
[0134] In operation S308, the generating agent updates the initial generating plan according to the intermediate testing plan to obtain an intermediate generating plan.
[0135] In operation S309 , the allocation agent updates the initial allocation plan according to the intermediate generation plan to obtain an intermediate allocation plan.
[0136] In operation S310 , the design agent updates the initial design solution according to the intermediate allocation solution to obtain an intermediate design solution.
[0137] In operation S311 , the analysis agent updates the initial analysis plan according to the intermediate design plan to obtain an intermediate analysis plan.
[0138] In operation S312 , it is determined whether the intermediate evaluation information corresponding to the intermediate solution meets the preset update condition. If not, the process returns to operation S307 to continue the solution update.
[0139] In operation S313 , when the updated evaluation information corresponding to the intermediate test plan, the intermediate generation plan, the intermediate allocation plan, the intermediate design plan, and the intermediate analysis plan meets the preset update condition, code generation is completed and the generated code is sent to the user.
[0140] It should be noted that when any of the intermediate testing plans, intermediate generation plans, intermediate allocation plans, intermediate design plans and intermediate analysis plans does not meet the preset update conditions, targeted updates can be made based on the intermediate plan, continuing to trigger the update mechanism and provide feedback to the upstream intelligent body.
[0141] Based on the above-mentioned multi-agent based code generation method, the present invention also provides a multi-agent based code generation device. Figure 4 The device is described in detail.
[0142] Figure 4 Shown is a structural block diagram of a multi-agent based code generation device according to an embodiment of the present invention.
[0143] like Figure 4 As shown, the multi-agent-based code generation device 400 of this embodiment includes an evaluation information determination module 410 , an update module 420 and a code generation module 430 .
[0144] Evaluation information determination module 410 is configured to determine, in response to receiving code generation requirement information input by a user, first evaluation information corresponding to a first processing solution generated by a master agent based on a first strategy, and second evaluation information corresponding to a second processing solution generated by a slave agent based on a second strategy, wherein the first processing solution is a master solution generated in response to the requirement information, and the second processing solution is a slave solution that is a refinement of the first processing solution. In one embodiment, evaluation information determination module 410 can be used to perform operation S210 described above, which will not be repeated here.
[0145] Update module 420 is configured to, if the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, sequentially update the second processing solution using the slave agent and the first processing solution using the master agent to obtain an updated solution. In one embodiment, update module 420 can be configured to perform operation S220 described above, which will not be further described here.
[0146] The code generation module 430 is used to generate code corresponding to the requirement information when the update evaluation information corresponding to the update plan meets the preset update conditions. In one embodiment, the code generation module 430 can be used to perform the operation S230 described above, which will not be repeated here.
[0147] According to an embodiment of the present invention, through the evaluation information determination module 410, the update module 420 and the code generation module 430 in the multi-agent-based code generation device 400, through the multi-role collaboration of the master agent and the slave agent, for the code generation requirement information, based on the processing strategies corresponding to the master and slave agents respectively, hierarchical master-slave processing solutions and corresponding evaluation information are positively generated. Since the update process of the master-slave processing solution is to use the slave agent and the master agent in turn to provide step-by-step feedback and optimization of the master and slave processing solutions, the positive quality evaluation of the processing solution and the downstream feedback triggering update mechanism are realized, a full-process solution generation and update link is constructed, and the dynamic generation and balance of the upstream and downstream agent decisions are realized, making the role division of the master and slave agents clearer, and further meeting the needs of complex code generation task scenarios.
[0148] According to an embodiment of the present invention, the second evaluation information includes second actual evaluation information of a neighboring agent of the slave agent, and the second strategy includes a processing strategy for an initial solution generated by the slave agent. The evaluation information determination module 410 includes a weighting submodule and an evaluation information generation submodule. The weighting submodule is configured to weight the second actual evaluation information using a preset weight to obtain a second weighted result; and the evaluation information generation submodule is configured to process the second weighted result based on the processing strategy to obtain a second processing solution, and generate second evaluation information corresponding to the second processing solution, wherein the processing strategy is determined by the role information of the slave agent.
[0149] According to an embodiment of the present invention, the weighting submodule includes at least one of the following: a design weighting unit, an allocation weighting unit, a generation weighting unit, and a test weighting unit. The design weighting unit is used to weight the analysis evaluation information and the allocation evaluation information in the second actual evaluation information using the design analysis weight and the design allocation weight, respectively, to obtain a second design weighted result corresponding to the design agent in the second weighted result; the allocation weighting unit is used to weight the granularity evaluation information and the rationality evaluation information in the second actual evaluation information using the granularity weight and the rationality weight, respectively, to obtain a second allocation weighted result corresponding to the allocation agent in the second weighted result; the generation weighting unit is used to weight the implementation evaluation information and the error information in the second actual evaluation information using the implementation weight and the error weight, respectively, to obtain a second generation weighted result corresponding to the generation agent in the second weighted result; the test weighting unit is used to weight the test coverage and the defect detection efficiency in the second actual evaluation information using the coverage weight and the efficiency weight, respectively, to obtain a second test weighted result corresponding to the test agent in the second weighted result.
[0150] According to an embodiment of the present invention, the evaluation information generation submodule includes: a test processing unit, a generation processing unit, an allocation processing unit, a design processing unit, and a combination unit. The test processing unit is used to process the second test weighted result based on the test strategy corresponding to the test agent to obtain a second test solution; the generation processing unit is used to process the second generation weighted result based on the generation strategy corresponding to the generation agent to obtain a second generation solution; the allocation processing unit is used to process the second allocation weighted result based on the allocation strategy corresponding to the allocation agent to obtain a second allocation solution; the design processing unit is used to process the second design weighted result based on the design strategy corresponding to the design agent to obtain a second design solution; and the combination unit is used to combine multiple evaluation information of the second design solution, the second allocation solution, the second generation solution, and the second test solution to obtain second evaluation information.
[0151] According to an embodiment of the present invention, the apparatus further includes: a result acquisition module configured to acquire multiple test results for an initial test plan generated by a test agent; and an efficiency determination module configured to determine the defect detection efficiency as the ratio of the total number of errors to the number of use cases in the multiple test results.
[0152] According to an embodiment of the present invention, the main agent includes at least one of the following: an analysis agent, a design agent, an allocation agent, and a generation agent; and the evaluation information determination submodule includes a feature acquisition unit and an evaluation information determination unit. The feature acquisition unit is used to acquire probability-related information and distribution features corresponding to the analysis agent, the design agent, the allocation agent, and the generation agent, respectively; and the evaluation information determination unit is used to determine expected information based on the probability-related information and distribution features.
[0153] According to an embodiment of the present invention, the information determination submodule includes: a scheme determination module, which is used to determine the current analysis scheme generated by the analysis agent at the current moment for the current expected evaluation scheme of the design agent, the current design scheme generated by the design agent for the current expected allocation scheme of the allocation agent, the current allocation scheme generated by the allocation agent for the current expected generation scheme of the generation agent, and the current generation scheme generated by the generation agent for the current expected test scheme of the test agent.
[0154] According to an embodiment of the present invention, the weighted processing submodule includes at least one of the following: an evaluation weighting unit, an allocation weighting unit, a generation weighting unit, and a test weighting unit. The evaluation weighting unit is used to weight the current expected evaluation scheme using the analysis weight change to obtain a first analysis weighted result; the allocation weighting unit is used to weight the current expected allocation scheme using the design weight change to obtain a first design weighted result; the generation weighting unit is used to weight the current expected generation scheme using the allocation weight change to obtain a first allocation weighted result; the test weighting unit is used to weight the current expected test scheme using the generation weight change to obtain a first generation weighted result.
[0155] According to an embodiment of the present invention, the information combination submodule includes at least one of the following: an analysis combination unit, used to combine the acquired analysis evaluation value with the first analysis weighted result to obtain a first analysis evaluation value corresponding to the analysis agent; a design combination unit, used to combine the second design weighted result with the first design weighted result to obtain a first design evaluation value corresponding to the design agent; an allocation combination unit, used to combine the second allocation weighted result with the first allocation weighted result to obtain a first allocation evaluation value corresponding to the allocation agent; a generation combination unit, used to combine the second generation weighted result with the first generation weighted result to obtain a first generation evaluation value corresponding to the generation agent.
[0156] According to an embodiment of the present invention, the update module 420 includes at least one of the following: a test update submodule, an allocation update submodule, a design update submodule, and an analysis update submodule. The test update submodule is configured to update the second generation scheme and the first generation scheme in sequence when the first generation evaluation value is less than the first generation threshold and the second test scheme meets the test error condition, thereby obtaining a test update scheme in the update scheme; the allocation update submodule is configured to update the second allocation scheme and the first allocation scheme in sequence when the first allocation evaluation value is less than the first allocation threshold and the number of updates of the second generation scheme is greater than the generation update threshold, thereby obtaining an allocation update scheme in the update scheme; the design update submodule is configured to update the second design scheme and the first design scheme in sequence when the first design evaluation value is less than the first design threshold and the second allocation scheme meets the allocation error condition, thereby obtaining a design update scheme in the update scheme; and the analysis update submodule is configured to update the second analysis scheme and the first analysis scheme in sequence when the first analysis evaluation value is less than the first analysis threshold and the number of updates of the second design scheme is greater than the design update threshold, thereby obtaining an analysis update scheme in the update scheme.
[0157] According to embodiments of the present invention, any multiple modules among the evaluation information determination module 410, the update module 420, and the code generation module 430 may be combined into a single module, or any one of these modules may be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of other modules and implemented in a single module. According to embodiments of the present invention, at least one of the evaluation information determination module 410, the update module 420, and the code generation module 430 may be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or may be implemented in hardware or firmware through any other reasonable means of circuit integration or packaging, or may be implemented in any one of the three implementation methods of software, hardware, and firmware, or any appropriate combination of these. Alternatively, at least one of the evaluation information determination module 410, the update module 420, and the code generation module 430 may be at least partially implemented as a computer program module that, when executed, performs the corresponding functionality.
[0158] Figure 5 A block diagram of an electronic device that executes a multi-agent-based code generation method according to an embodiment of the present invention is shown.
[0159] like Figure 5 As shown, the electronic device 500 includes: a memory 510 and a processor 520, and the processor 520 is configured to execute the above-mentioned multi-agent-based code generation method according to the instructions and data stored in the memory.
[0160] In an embodiment of the present invention, the memory 510 can store different types of data or instructions, such as code generation requirement information input by a user, processing solutions generated by master and slave agents, and solution update instructions.
[0161] Figure 6 A block diagram of an electronic device suitable for implementing a multi-agent based code generation method according to an embodiment of the present invention is shown.
[0162] like Figure 6As shown, an electronic device 600 according to an embodiment of the present invention includes a first processor 601, which can perform various appropriate actions and processes based on a program stored in a read-only memory (ROM) 602 or a program loaded from a storage unit 608 into a random access memory (RAM) 603. The first processor 601 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor, and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)). The first processor 601 may also include onboard memory for caching purposes. The first processor 601 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.
[0163] The RAM 603 stores various programs and data required for the operation of the electronic device 600. The processor 601, ROM 602, and RAM 603 are connected to each other via a bus 604. The first processor 601 executes the programs in the ROM 602 and / or RAM 603 to perform various operations according to the method flow of the embodiment of the present invention. It should be noted that the programs may also be stored in one or more memories other than the ROM 602 and RAM 603. The first processor 601 may also execute the programs stored in the one or more memories to perform various operations according to the method flow of the embodiment of the present invention.
[0164] According to an embodiment of the present invention, electronic device 600 may further include an input / output (I / O) interface 605, which is also connected to bus 604. Electronic device 600 may also include one or more of the following components connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including devices such as a cathode ray tube (CRT), liquid crystal display (LCD), and speakers; a storage section 608 including a hard disk; and a communication section 609 including a network interface card such as a LAN card or modem. Communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. Removable media 611, such as a magnetic disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed in drive 610 as needed, so that computer programs read from the removable media can be installed into storage section 608 as needed.
[0165] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments, or may exist independently and not incorporated into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of the present invention.
[0166] According to an embodiment of the present invention, a computer-readable storage medium may be a non-volatile computer-readable storage medium, and may include, for example, but not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to an embodiment of the present invention, a computer-readable storage medium may include the ROM 602 and / or RAM 603 described above, and / or one or more memories other than ROM 602 and RAM 603.
[0167] The embodiments of the present invention further include a computer program product, which includes a computer program containing program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to cause the computer system to implement the method provided by the embodiments of the present invention.
[0168] The computer program executes the above functions defined in the system / device of the embodiment of the present invention when the first processor 601 executes the computer program. According to the embodiment of the present invention, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0169] In one embodiment, the computer program may be stored on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may be transmitted and distributed in the form of a signal on a network medium, downloaded and installed via the communication portion 609, and / or installed from a removable medium 611. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to wireless, wired, or any suitable combination thereof.
[0170] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609 and / or installed from a removable medium 611. When the computer program is executed by the first processor 601, the above-described functions defined in the system of the embodiment of the present invention are performed. According to the embodiment of the present invention, the systems, devices, means, modules, units, etc. described above can be implemented by computer program modules.
[0171] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages. Specifically, these computer programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect via the Internet).
[0172] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0173] It will be understood by those skilled in the art that the features described in the various embodiments of the present invention may be combined and / or coupled in various ways, even if such combinations or couplings are not explicitly described in the present invention. In particular, the features described in the various embodiments of the present invention may be combined and / or coupled in various ways without departing from the spirit and teachings of the present invention. All such combinations and / or couplings fall within the scope of the present invention.
[0174] The above describes embodiments of the present invention. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present invention. Although each embodiment has been described separately above, this does not mean that the measures in each embodiment cannot be advantageously used in combination. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.
Claims
1. A multi-agent based code generation method, characterized in that: The multi-agent comprises a master agent and a slave agent; the method comprises: In response to receiving code generation requirement information input by a user, determining first evaluation information corresponding to a first processing solution generated by the master agent based on a first strategy, and weighting the second actual evaluation information using a preset weight to obtain a second weighted result; processing the second weighted result based on the processing strategy to obtain a second processing solution, and generating second evaluation information corresponding to the second processing solution, wherein the processing strategy is determined by the role information of the slave agent, wherein the first processing solution is a master solution generated for the requirement information, the second processing solution is a slave solution obtained after refinement and splitting of the first processing solution, and the second evaluation information includes second actual evaluation information of adjacent agents of the slave agent; When the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, the second processing solution is updated by the slave agent and the first processing solution is updated by the master agent in sequence to obtain an updated solution; generating a code corresponding to the requirement information when the update evaluation information corresponding to the update plan meets a preset update condition; The slave agents include at least one of the following: a design agent, an allocation agent, a generation agent, and a test agent; and the preset weights include at least one of the following: a design analysis weight and a design allocation weight corresponding to the design agent, a granularity weight and a rationality weight corresponding to the allocation agent, a realization weight and an error weight corresponding to the generation agent, and a coverage weight and an efficiency weight corresponding to the test agent. The second actual evaluation information is weighted using a preset weight to obtain a second weighted result, including at least one of the following: weighting the analysis evaluation information and the allocation evaluation information in the second actual evaluation information by using the design analysis weight and the design allocation weight, respectively, to obtain a second design weighted result corresponding to the design agent in the second weighted result; Using the granularity weight and the rationality weight to weight the granularity evaluation information and the rationality evaluation information in the second actual evaluation information, respectively, to obtain a second allocation weighted result corresponding to the allocation agent in the second weighted result; Using the realization weight and the error weight to weight the realization evaluation information and the error information in the second actual evaluation information respectively, to obtain a second generated weighted result corresponding to the generated intelligent agent in the second weighted result; The coverage weight and the efficiency weight are used to weight the test coverage and the defect detection efficiency in the second actual evaluation information respectively, to obtain a second test weighted result corresponding to the test agent in the second weighted result.
2. The method according to claim 1, characterized in that Processing the second weighted result based on the processing strategy to obtain the second processing solution, and generating second evaluation information corresponding to the second processing solution, including: Processing the second test weighted result based on the test strategy corresponding to the test agent to obtain a second test plan; Processing the second generation weighted result based on the generation strategy corresponding to the generation agent to obtain a second generation solution; Processing the second allocation weighted result based on the allocation strategy corresponding to the allocation agent to obtain a second allocation plan; Processing the second design weighted result based on the design strategy corresponding to the design agent to obtain a second design solution; The second evaluation information is obtained by combining the plurality of evaluation information of the second design solution, the second allocation solution, the second generation solution and the second test solution.
3. The method according to claim 1, characterized in that The method further comprises: Obtaining a plurality of test results for an initial test scenario generated for the test agent; The defect detection efficiency is determined as a ratio between the total number of errors in the plurality of detection results and the number of use cases.
4. The method according to claim 2, characterized in that The first evaluation information includes first actual evaluation information and expected evaluation information of the neighboring agents of the master agent, the first strategy includes weight change information corresponding to the expected information, the second processing scheme also includes a second analysis scheme, and the first processing scheme includes at least one of the following: a first generation scheme, a first allocation scheme, a first design scheme, and a first analysis scheme; Determining first evaluation information corresponding to a first processing solution generated by the master agent based on the first strategy includes: determining expected information corresponding to an initial solution generated by the master agent; Performing weighted processing on the expected information using the weight change information to obtain a first weighted result; The first weighted result and the first actual evaluation information are combined to obtain the first evaluation information.
5. The method according to claim 4, characterized in that The main agent includes at least one of the following: an analysis agent, the design agent, the allocation agent, and the generation agent; Determining expected information corresponding to the initial solution generated by the master agent, including: Obtaining probability-related information and distribution characteristics corresponding to the analysis agent, the design agent, the allocation agent, and the generation agent, respectively; Based on the probability-related information and the distribution characteristics, the expected information is determined.
6. The method according to claim 5, characterized in that Determine the expected information corresponding to the initial solution generated by the master agent, including: Determine the current analysis solution generated by the analysis agent at the current moment for the current expected evaluation solution of the design agent, the current design solution generated by the design agent for the current expected allocation solution of the allocation agent, the current allocation solution generated by the allocation agent for the current expected generation solution of the generation agent, and the current generation solution generated by the generation agent for the current expected test solution of the test agent.
7. The method according to claim 6, characterized in that The weight change information includes at least one of the following: an analysis weight change corresponding to the analysis agent, a design weight change corresponding to the design agent, an allocation weight change corresponding to the allocation agent, and a generation weight change corresponding to the generation agent; The expected information is weighted using the weight change information to obtain a first weighted result, including at least one of the following: Weighting the current expected evaluation scheme using the analysis weight change to obtain a first analysis weighted result; weighting the current expected allocation scheme using the design weight change to obtain a first design weighted result; weighting the current expected generation scheme using the allocation weight change to obtain a first allocation weighted result; The current expected test scenario is weighted using the generation weight change to obtain a first generation weighted result.
8. The method according to claim 7, characterized in that Combining the first weighted result and the first actual evaluation information to obtain the first evaluation information includes at least one of the following: Combining the acquired analysis evaluation value with the first analysis weighted result to obtain a first analysis evaluation value corresponding to the analysis agent; combining the second design weighted result with the first design weighted result to obtain a first design evaluation value corresponding to the design agent; combining the second allocation weighted result with the first allocation weighted result to obtain a first allocation evaluation value corresponding to the allocation agent; The second generation weighted result is combined with the first generation weighted result to obtain a first generation evaluation value corresponding to the generation agent.
9. The method according to claim 8, characterized in that The preset evaluation condition includes a first threshold corresponding to the first evaluation information, wherein the first threshold includes a first analysis threshold, a first design threshold, a first allocation threshold, and a first generation threshold corresponding to the analysis agent, the design agent, the allocation agent, and the generation agent, respectively; If the first evaluation information and the second evaluation information do not meet the preset evaluation conditions, the second processing solution is updated by the slave agent and the first processing solution is updated by the master agent in sequence to obtain an updated solution, including at least one of the following: When the first generation evaluation value is less than the first generation threshold and the second test solution meets the test error condition, the second generation solution and the first generation solution are sequentially updated to obtain a test update solution in the updated solution; When the first allocation evaluation value is less than the first allocation threshold and the number of updates of the second generated plan is greater than the generation update threshold, the second allocation plan and the first allocation plan are updated in sequence to obtain an allocation update plan in the updated plan; When the first design evaluation value is less than the first design threshold and the second allocation scheme satisfies an allocation error condition, sequentially updating the second design scheme and the first design scheme to obtain a design update scheme in the updated scheme; When the first analysis evaluation value is less than the first analysis threshold and the update times of the second design solution is greater than the design update threshold, the second analysis solution and the first analysis solution are updated in sequence to obtain an analysis update solution in the update solution.
10. The method according to any one of claims 1 to 9, characterized in that The preset update condition includes at least one of the following: The difference between the current update evaluation value of the update solution at the current moment and the previous update evaluation value of the update solution at the previous moment is less than a preset evaluation threshold; The number of updates of the update scheme at the current moment is greater than a preset iteration threshold.
11. An electronic device comprising: Memory; A processor configured to execute the method according to any one of claims 1 to 10 according to the instructions and data stored in the memory.
12. A computer-readable storage medium having a computer program or instruction stored thereon, characterized in that: When the computer program or instructions are executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instructions are executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Multi-index extensible multi-agent code generation evaluation system and method
CN118838629A
Code generation method and system based on heterogeneous multi-agent cooperation and electronic equipment
CN119829038A