Multi-agent code generation method and system, storage medium and equipment
By constructing a four-stage closed-loop evolutionary framework for multi-agent code generation, the problems of policy rigidity and insufficient utilization of experience in existing technologies are solved, realizing the autonomous evolution and optimization of policies and improving the adaptability and performance of the code generation system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- UNIV OF ELECTRONICS SCI & TECH OF CHINA
- Filing Date
- 2026-01-19
- Publication Date
- 2026-05-08
AI Technical Summary
Existing technologies suffer from rigid strategies, insufficient utilization of experience, and limited evolutionary capabilities in code generation. In particular, the lack of deep integration and optimization in multi-agent collaborative scenarios makes the generated code prone to getting stuck in local optima and unable to adapt to complex problems.
A four-stage closed-loop evolutionary framework is constructed, including meta-policy initialization, meta-policy evolution, meta-policy implementation, and meta-policy causal reflection. Through multi-agent collaboration and dynamic threshold adjustment, the autonomous evolution and optimization of policies are achieved.
It improved the efficiency of strategy optimization, enhanced the adaptability and performance of the code generation system under complex problems, increased the pass rate from the traditional 20% to 82.3%, and improved the efficiency of strategy optimization by 2.4 times.
Smart Images

Figure CN121998086A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated code generation, and more particularly to a multi-agent code generation method, system, storage medium, and device. Background Technology
[0002] In the field of automated code generation, with the rapid development of large language model technology, code generation systems based on large language models have demonstrated tremendous potential. However, existing methods generally adopt a static linear reasoning model, limiting their attention to solving a single task while neglecting continuous optimization and iterative improvement at the strategy level. This limitation often leads to repeated failures when facing complex algorithmic problems, preventing them from evolving strategies through experience like human programmers. The performance bottleneck of existing methods is particularly evident when dealing with competitive programming challenges, making it difficult to achieve self-improvement and adaptive improvement at the strategy level.
[0003] Existing technical solutions have significant shortcomings in policy optimization mechanisms, mainly manifested in insufficient utilization of failure experience and superficial policy improvements. Traditional methods typically treat each code generation as an independent event, lacking a systematic experience accumulation and transformation mechanism. When errors occur in the generated code, the system often can only perform simple retries or local adjustments, failing to conduct deep policy reflection and refactoring. This policy rigidity problem severely restricts the system's adaptability to new and complex problems and is the fundamental reason why current technologies struggle to overcome performance bottlenecks. Especially in multi-agent collaborative scenarios, interactions between agents often remain at the execution level, lacking deep integration and optimization at the policy level, causing the generated code to easily get trapped in local optima.
[0004] Therefore, there is an urgent need for a code generation method that can enable continuous strategy evolution, make deep use of failure experience, and support multi-agent collaborative optimization, so as to break through the performance bottlenecks and adaptability limitations of existing technologies. Summary of the Invention
[0005] The purpose of this invention is to overcome the problems of policy rigidity, insufficient utilization of experience and limited evolutionary capability in the prior art. It provides a multi-agent code generation method, system, storage medium and device. By taking the code generation strategy itself as a learnable object, a four-stage closed-loop evolutionary framework including meta-policy initialization, meta-policy evolution, meta-policy implementation and meta-policy causal reflection is constructed, realizing the autonomous evolution capability of the strategy from primary to advanced.
[0006] The objective of this invention is achieved through the following technical solution: Firstly, a multi-agent code generation method is provided, such as... Figure 1 As shown, it includes the following steps: S1. Meta-policy initialization phase: The agent generates an initial meta-policy through deep problem understanding and constructs a meta-experience pool and a candidate policy pool; S2. Meta-policy Evolution Stage: The meta-policy is iteratively optimized through multi-agent collaboration to obtain the final meta-policy; S3. Meta-strategy Implementation Phase: The final meta-strategy is converted into executable code and test cases and verified. If the verification is successful, the final code is output; if the verification fails, proceed to step S4. S4. Meta-policy Causal Reflection Phase: Achieve closed-loop optimization of the meta-policy through causal analysis, update the experience to the meta-experience pool, and update the policy to the candidate policy pool.
[0007] As a preferred technical solution, the initialization agent generates an initial meta-policy through deep problem understanding, including: The initial meta-policy is represented using a triplet structure: in, Indicates the initial meta-policy. This represents the defense focus set, identifying key risk areas in the algorithm implementation (such as functional correctness, boundary handling, and input validation), and satisfying... , Represents the quality attribute weight vector, satisfying and Quantify the priority of each quality attribute (such as performance, readability, robustness), The implementation framework is represented; it is defined as an ordered sequence of steps. This guides the code generation process.
[0008] As a preferred technical solution, in step S1, the meta-experience pool constructed in this stage... A structured storage format is used to store historical failure experiences and improvement information. The format is as follows: Each failure experience record Includes quintuple information: .
[0009] in, Indicate the reason for failure (such as logical error, boundary omission). Indicates the meta-policy used when failure occurs. Indicates the generated error code, Indicates the test cases that failed and Indicate suggestions for improvement.
[0010] The candidate strategy pool built in this stage It also uses a structured storage format to store tested and validated successful strategies, with the following format: Each candidate strategy Includes quadruple information: .
[0011] in This is represented as a successful strategy. For the generated correct code, To test the pass rate, A record of reflections on the strategy optimization process.
[0012] Candidate strategy pool A dynamic sorting mechanism is used; when the pass rate of a new strategy exceeds the minimum value in the pool, a replacement is triggered. Pool capacity... The dynamic update rules can be adjusted according to the complexity of the problem and satisfy the following: As a preferred technical solution, in step S1, the weighted BM25 algorithm is used in the initialization stage to achieve efficient retrieval of the meta-experience pool, and its scoring function is designed as follows: in, .
[0013] As a preferred technical solution, in step S1, in order to control the iteration process, an iteration round variable is defined. and iterative budget ,in Represents the current evolutionary cycle, initial value Execute after each round of evolution ; This represents the maximum evolutionary stage, preset by the user.
[0014] As a preferred technical solution, the iterative optimization of the meta-policy through multi-agent cooperation includes: Define the policy with the highest pass rate in the candidate policy pool as the historically optimal meta-policy. (If there is no historical strategy in the initial stage, it will not be selected.) In order to overcome the limitations of traditional single-inference, the evolutionary agent is based on the historical best strategy. and current meta-policy Generate basic evolutionary strategies ; The basic evolutionary meta-policy is decomposed into multiple independently optimizable sub-policies. Specifically, to reduce optimization complexity and support local fine-tuning, the modular agent will... Decomposed into Each sub-strategy can be optimized independently. Each sub-strategy uses a structured storage format, which is as follows: in, This indicates a focus on specific defense scenarios (such as input validation). Represented as executable atomic code fragments, This is expressed as a confidence level.
[0015] Multiple sub-policies are merged to generate the final meta-policy.
[0016] As a preferred technical solution, in step S2, variables are defined. The threshold representing the effectiveness of the strategy will be... This is represented as a confidence sub-policy. Since low-confidence sub-policies are the main source of error, refining the agent requires targeted optimization of low-confidence sub-policies to block error propagation.
[0017] As a preferred technical solution, the step of merging multiple sub-policies to generate a final meta-policy includes: The fusion agent sequentially performs consistency alignment, conflict resolution, module independence, and integrability verification on multiple sub-policies. Specifically, since implicit conflicts (such as resource contention and logical contradictions) may exist during the merging of sub-policies, the fusion agent integrates sub-policies by simulating information from the cerebral cortex, resolves conflicts between sub-policies, and generates the final meta-policy. The fusion process involves the following steps: (1) Consistent alignment: Ensure semantic and structural consistency between sub-strategies and coordinate overlapping components.
[0018] (2) Conflict resolution: When a conflict arises, choose the variant with the highest confidence while maintaining strategic integrity.
[0019] (3) Module independence: Retain innovations that provide orthogonal improvements without introducing conflicting dependencies.
[0020] (4) Integration verification: Reorganize all modules into a coherent strategy with consistent processes, complete logic and implementation feasibility.
[0021] As a preferred technical solution, in step S3, the test agent generates an enhanced test set, whose test cases cover basic test cases and policy special cases, used to verify the correctness of the generated executable code. For basic test cases, the set mainly covers regular input and output. For policy special cases, the set mainly covers cases targeting specific defense focuses. Boundary testing.
[0022] As a preferred technical solution, in step S3, the enhanced test set verification code is executed. If the pass rate... If the value is 1, output the final code. Otherwise, proceed to step S4 and record a failure report. The pass rate calculation rule is as follows: Here, passed_cases represents the test cases that have passed, and total_cases represents all test cases in the enhanced test suite.
[0023] As a preferred technical solution, the closed-loop optimization of the meta-strategy through causal analysis includes: By analyzing the agent, the reasons for failure were diagnosed from three dimensions: lack of defense focus, failure of sub-policies, and imbalance of quality weights. By reflecting on the agent, the causal relationship between policy and performance was summarized from three dimensions: policy performance evaluation, exposure of weaknesses, and improvement directions.
[0024] Specifically, in step S4, the number of iterations ,when Output the final code at that time The iteration ends. The analytical agent diagnoses the root causes of failures based on the failure reports and generates improvement suggestions. Among these, the lack of defense focus is used to check whether the failed use cases belong to those not addressed. Coverage scenarios; sub-policy failure is used to locate low-confidence sub-policies. ( (code snippet) With failed use cases The correlation; the imbalance of quality weights is used to verify the weights of quality attributes. Does this result in key attributes (such as robustness) not being prioritized for optimization? The output experience E is updated in the experience pool. The agent reflects on the causal relationship between policy and performance. Policy performance evaluation is used to quantify the policy. The effectiveness of the strategy is assessed; weaknesses are exposed to identify shortcomings in areas such as defense focus coverage and sub-strategy coordination; and improvement directions are used to generate specific optimization objectives. The output strategy summary updates the candidate strategy pool. Then proceed to step S2, and repeat this process until the final code is output.
[0025] Secondly, a multi-agent code generation system is provided, comprising the following steps: The meta-policy initialization module is used to initialize the agent to generate an initial meta-policy through deep problem understanding, and to build a meta-experience pool and a candidate policy pool. The meta-policy evolution module is used to iteratively optimize the meta-policy through multi-agent collaboration to obtain the final meta-policy. The meta-strategy implementation module is used to convert the final meta-strategy into executable code and test cases and verify it. If the verification is successful, the final code is output; if the verification fails, the meta-strategy cause-and-effect reflection module is entered. The meta-policy causal reflection module is used to achieve closed-loop optimization of meta-policies through causal analysis, update the experience to the meta-experience pool, and update the policy to the candidate policy pool.
[0026] Thirdly, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, which, when executed by a processor, implements the multi-agent code generation method described in the first aspect.
[0027] Fourthly, an electronic device is provided, including a memory and a processor, wherein the memory stores computer instructions that can be executed on the processor, and the processor executes the multi-agent code generation method described in the first aspect when executing the computer instructions.
[0028] It should be further noted that the technical features corresponding to the above-mentioned options and embodiments can be combined or substituted with each other to form new technical solutions without conflict.
[0029] Compared with the prior art, the beneficial effects of the present invention are: 1. This invention utilizes a self-evolving framework based on meta-policy learning. By explicitly modeling the code generation policy as a learnable object, it overcomes the limitation of traditional methods that treat policies as "black boxes," achieving continuous evolution at the policy level. Experiments show that this mechanism, based on the GPT-o3 large language model, achieves a 95.7% pass rate on the HumanEval benchmark, a 13.2% improvement compared to traditional single-step linear inference methods, validating the effectiveness of policy self-evolution. 2. This invention introduces a four-stage closed-loop evolution mechanism, with "initialization → meta-policy evolution → meta-policy implementation → meta-causal reflection" as the core process, constructing a complete closed loop of "generation-verification-improvement". This mechanism increases the utilization rate of failure experience from less than 20% in the traditional way to 82.3%, improves the efficiency of policy optimization by 2.4 times, and completely solves the dilemma of "repeated failure-ineffective retry" caused by policy solidification in traditional methods; 3. This invention employs multi-agent collaboration and dynamic threshold adjustment technology. Through multi-agent division of labor covering strategy optimization, the evolutionary agent is responsible for global strategy improvement, the modular agent decomposes complex strategies into optimizable sub-modules, the refining agent verifies the technology stack and resolves conflicts for low-confidence sub-strategies, and the fusion agent reassembles sub-strategies into a collaboratively executed final strategy by simulating cortical signal integration. Simultaneously, the dynamic threshold adjustment mechanism adaptively adjusts the sub-strategy effectiveness judgment criteria based on problem complexity, avoiding "over-optimization" or "under-optimization" caused by fixed thresholds. Attached Figure Description
[0030] Figure 1 This is a flowchart of a multi-agent code generation method according to the present invention; Figure 2 This is a schematic diagram showing the comparison of the meta-policy before and after learning in this invention; Figure 3 This is a schematic diagram of the meta-strategy evolution of the present invention; Figure 4 This is a flowchart of the overall program for the multi-agent code generation method of the present invention. Detailed Implementation
[0031] The technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] It should be noted that the defects in the solutions in the prior art are all the results of the inventors' practice and careful research. Therefore, the discovery process of the above problems and the solutions proposed by the embodiments of this application in the following text should be the inventors' contributions to this application in the process of invention and creation, and should not be understood as technical content known to those skilled in the art.
[0033] Based on the above statements, and since this embodiment involves code generation-related technologies, the following explanations are provided to clarify the objectives, technical solutions, and advantages of this application embodiment: 1. Temperature: In Large Language Modeling (LLM), temperature is a hyperparameter that controls the randomness and determinism of text generation. Its core function is to balance the creativity and accuracy of the generated results by adjusting the probability distribution of token prediction. Specifically, when predicting the next token, the model adjusts the original probability distribution... Convert to adjusted distribution Its format is: Among them, when When the distribution degenerates into deterministic selection (only retaining the token with the highest probability), the generation result is highly conservative but may lack flexibility; when When the distribution approaches a uniform distribution, the generated results are highly diverse but may deviate from the semantics; in this invention, the temperature is set to... This forces the model to select the token with the highest probability, ensuring that the generated code strictly follows the optimal pattern in the training data, thereby improving the correctness and stability of the code.
[0034] 2. Kernel Sampling: Kernel sampling is a sampling strategy that dynamically adjusts the number of candidate tokens by setting a probability threshold. (Kernel size) is used to control the diversity of generation. In this invention, kernel sampling is set to... This means that only the top 95% of high-probability tokens are retained based on cumulative probability. This setting balances the reliability and flexibility of the generated code, ensuring that the generated code conforms to semantic specifications while adapting to subtle differences in different input scenarios.
[0035] In view of the technical problems pointed out in the background art, the present invention provides the following embodiments: In one exemplary embodiment, an automated code generation system is built based on the GPT-o3 large language model (temperature set to 0, kernel sampling set to 0.95), and the system runs on a high-performance computing server equipped with an NVIDIA 3090 GPU. The input problem in this embodiment is: determine whether a given number n can be represented as the sum of exactly four positive even numbers.
[0036] like Figure 2-4 As shown, the specific implementation steps of the present invention are as follows: Step 1: Initialize the agent. Generate an initial meta-policy through deep problem understanding, with the following format: in To defend against focal sets, identify key risk areas in the algorithm implementation (such as functional correctness, boundary handling, and input validation) and meet the requirements. The definition for this problem is... ,satisfy (Covering all potential risks). For example Corresponding to "if" The defense logic is to "return False if the number is odd"; Let be the quality attribute weight vector, satisfying and This involves quantifying the priority of various quality attributes (such as performance, readability, and robustness). For this problem, it is defined as... F represents the implementation framework, defining an ordered sequence of steps for this problem. This guides the code generation process. This is to verify the validity of the input. This is represented as generating candidate combinations. This is expressed as a verification combination sum. This indicates the returned result.
[0037] Step 2: Construct the meta-experience pool using a structured storage format It is used to store historical failure experiences and improvement information, and its format is: Each failure experience record Includes quintuple information: .
[0038] in, Indicate the reason for failure (such as logical error, boundary omission). Indicates the meta-policy used when failure occurs. Indicates the generated error code, Indicates the test cases that failed and Indicate suggestions for improvement.
[0039] Step 3: Construct a candidate strategy pool using a structured storage format. It is used to store tested and verified successful strategies, and its format is: Each candidate strategy Includes quadruple information: .
[0040] in This is represented as a successful strategy. For the generated correct code, To test the pass rate, A record of reflections on the strategy optimization process.
[0041] Candidate strategy pool A dynamic sorting mechanism is used; when the pass rate of a new strategy exceeds the minimum value in the pool, a replacement is triggered. Pool capacity... The dynamic update rules can be adjusted according to the complexity of the problem and satisfy the following: Candidate strategy pool A weighted BM25 algorithm is used to achieve efficient retrieval of the meta-experience pool. Its scoring function is designed as follows: in, .
[0042] Step 4: To control the iteration process, define the iteration round variable. and iterative budget ,in Represents the current evolutionary cycle, initial value Execute after each round of evolution ; This represents the maximum evolutionary stage, preset by the user.
[0043] Step 5: Define the strategy with the highest pass rate in the candidate strategy pool as the historical best strategy. (If there is no historical strategy in the initial stage, it will not be selected.) In order to overcome the limitations of traditional single-inference, the evolutionary agent is based on the historical best strategy. and current meta-policy Generate basic evolutionary strategies .
[0044] Step 6: To reduce optimization complexity and support fine-tuning in localized areas, the modular intelligent agent will... Decomposed into Each sub-strategy can be optimized independently. Each sub-strategy uses a structured storage format, which is as follows: in, This indicates a focus on specific defense scenarios (such as input validation). Represented as executable atomic code fragments, this issue has... of" ”; This represents the confidence level, which is defined as 0.7 for this problem.
[0045] Step 7: Define variables The threshold representing the effectiveness of the strategy will be... This is represented as a confidence-based sub-policy. Since low-confidence sub-policies are the primary source of error, the refining agent needs to specifically optimize these low-confidence sub-policies to prevent error propagation. To address this problem, the refining agent needs to target... ( ), supplementing boundary handling logic After optimization, the confidence level was increased to This prevents the spread of errors.
[0046] Step 8: Due to implicit conflicts (such as resource competition and logical contradictions) that may exist during the merging of sub-policies, the fusion agent integrates sub-policies by simulating information from the cerebral cortex, resolving conflicts between sub-policies and generating the final policy. The fusion process steps are as follows: (1) Consistent alignment: Ensure semantic and structural consistency between sub-strategies, coordinate overlapping components, and unify the alignment for this problem. and The input and output formats.
[0047] (2) Conflict resolution: When a conflict arises, select the variant with the highest confidence while maintaining strategic integrity. For this problem, the execution order of "generating combinations" and "verifying the minimum value" needs to be selected by weighting the confidence levels.
[0048] (3) Module independence: Preserve innovations that provide orthogonal improvements without introducing conflicting dependencies. To address this issue, it is necessary to ensure that the "combination deduplication" module is independent of the "and verification" module.
[0049] (4) Integration verification: Reorganize all modules into a coherent strategy with consistent processes, complete logic, and implementation feasibility. Regarding this issue, It includes checking for odd numbers, checking for the minimum value, generating combinations, deduplication verification, and returning the results.
[0050] Step 9: Encode the agent based on the final meta-policy Generate executable code. The code generated for this problem is as follows: Figure 1 As shown.
[0051] Step 10: The test agent generates an enhanced test suite, covering basic test cases and policy special cases, to verify the code. For basic test cases, it primarily covers regular input and output. For policy special cases, it primarily covers those targeting specific defense focuses. Boundary testing.
[0052] Step 11: Execute the enhanced test suite to verify the code. If the pass rate is... If the value is 1, output the final code. Otherwise, proceed to step 12 and record a failure report. The pass rate calculation rule is as follows: Here, `passed_cases` represents the passed test cases, and `total_cases` represents all test cases in the enhanced test suite. For this problem, the number of basic test cases is 2, the number of policy special cases is 3, and the final pass rate is 80%. If the result is not 1, proceed to step 12 and record a failure report. .
[0053] Step 12: Number of iterations ,when Output the final code at that time End the iteration. Number of iterations for this problem. Proceed to step 13.
[0054] Step 13: Analyze the agent's failure reports to diagnose root causes and generate improvement suggestions. The diagnostic dimensions are: missing defense focus, sub-strategy failure, and quality weight imbalance. Specifically, missing defense focus is used to check whether failed use cases belong to those not addressed by the defense agent. In the covered scenarios, for this problem, test cases n=20 resulted in false positives due to repeated combinations (it should actually return True), but... Not included (Combined deduplication) indicates a lack of defensive focus; sub-strategy failure is used to locate low-confidence sub-strategies. ( (code snippet) With failed use cases The relevance of this issue, Confidence of (combined generation of sub-strategies) And its code snippet " "Failure to remove duplicates led to misjudgment of multiple solutions when n=20; the imbalance of quality weights was used to verify the weights of quality attributes." Does this result in key attributes (such as robustness) not being prioritized for optimization? To address this issue, If the failure stems from a logical error, then the quality weights are deemed unbalanced. The output experience E is then updated in the experience pool.
[0055] Step 14: Reflect on the agent and summarize the causal relationship between policy and performance. The diagnostic dimensions include policy performance evaluation, exposed weaknesses, and improvement directions. Policy performance evaluation is used to quantify the policy... The effectiveness of the strategy is assessed; weaknesses are exposed to identify shortcomings in areas such as defense focus coverage and sub-strategy coordination; improvement directions are used to generate specific optimization objectives. For this problem, the optimization objectives include expanding the defense focus, adjusting quality weights, and optimizing sub-strategies. The output strategy summary updates the candidate strategy pool. Then proceed to step 5, and repeat this process until the final code is output.
[0056] In another exemplary embodiment, based on the same inventive concept as the method embodiment, a multi-agent code generation system is provided, comprising the following steps: The meta-policy initialization module is used to initialize the agent to generate an initial meta-policy through deep problem understanding, and to build a meta-experience pool and a candidate policy pool. The meta-policy evolution module is used to iteratively optimize the meta-policy through multi-agent collaboration to obtain the final meta-policy. The meta-strategy implementation module is used to convert the final meta-strategy into executable code and test cases and verify it. If the verification is successful, the final code is output; if the verification fails, the meta-strategy cause-and-effect reflection module is entered. The meta-policy causal reflection module is used to achieve closed-loop optimization of meta-policies through causal analysis, update the experience to the meta-experience pool, and update the policy to the candidate policy pool.
[0057] In another exemplary embodiment, based on the same inventive concept as the method embodiment, a computer-readable storage medium is provided. This computer-readable storage medium stores a computer program, which, when executed by a processor, implements the multi-agent code generation method provided in this embodiment of the invention. Based on this understanding, the technical solution of this embodiment, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0058] In another exemplary embodiment, based on the same inventive concept as the method embodiment, an electronic device is provided, including a memory and a processor. The memory stores computer instructions that can be executed on the processor. When the processor executes the computer instructions, it performs the multi-agent code generation method provided in the embodiment of the present invention.
[0059] The processor may be a single-core or multi-core central processing unit or a specific integrated circuit, or one or more integrated circuits configured to implement the present invention.
[0060] The embodiments of the subject matter and functional operation described in this specification can be implemented in: tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or combinations thereof. Embodiments of the subject matter described in this specification can be implemented as one or more computer programs, i.e., one or more modules of computer program instructions encoded on a tangible, non-transitory program carrier for execution by a data processing device or for controlling the operation of a data processing device. Alternatively or additionally, the program instructions may be encoded on artificially generated propagation signals, such as machine-generated electrical, optical, or electromagnetic signals, which are generated to encode information and transmit it to a suitable receiving device for execution by the data processing device.
[0061] The processing and logic flow described in this specification can be executed by one or more programmable computers that execute one or more computer programs to perform corresponding functions by operating on input data and generating output. The processing and logic flow can also be executed by dedicated logic circuitry—such as FPGAs (Field-Programmable Gate Arrays) or ASICs (Application-Specific Integrated Circuits), and the device can also be implemented as dedicated logic circuitry.
[0062] Suitable processors for executing computer programs include, for example, general-purpose and / or special-purpose microprocessors, or any other type of central processing unit. Typically, the central processing unit receives instructions and data from read-only memory and / or random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, a computer will also include one or more mass storage devices for storing data, such as disks, magneto-optical disks, or optical disks, or the computer will be operatively coupled to such mass storage devices to receive data from or transfer data to them, or both. However, a computer is not required to have such devices. Furthermore, a computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0063] It should be understood that each block in a flowchart or block diagram can represent a module, segment, or portion of code, which 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 blocks may occur in a different order than those shown in the figures. For example, two consecutive blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0064] The above detailed embodiments are a description of the present invention. It should not be considered that the specific embodiments of the present invention are limited to these descriptions. For those skilled in the art, several simple deductions and substitutions can be made without departing from the concept of the present invention, and all of these should be considered to fall within the protection scope of the present invention.
Claims
1. A multi-agent code generation method, characterized in that, Includes the following steps: S1. Meta-policy initialization phase: The agent generates an initial meta-policy through deep problem understanding and constructs a meta-experience pool and a candidate policy pool; S2. Meta-policy Evolution Stage: The meta-policy is iteratively optimized through multi-agent collaboration to obtain the final meta-policy; S3. Meta-strategy Implementation Phase: The final meta-strategy is converted into executable code and test cases and verified. If the verification is successful, the final code is output; if the verification fails, proceed to step S4. S4. Meta-policy Causal Reflection Phase: Achieve closed-loop optimization of the meta-policy through causal analysis, update the experience to the meta-experience pool, and update the policy to the candidate policy pool.
2. The multi-agent code generation method according to claim 1, characterized in that, The initial meta-policy is represented using a triplet structure: in, Indicates the initial meta-policy. Represents the quality attribute weight vector. Indicates the focus of defense. Indicates the implementation framework; Both the meta-experience pool and the candidate strategy pool adopt a structured storage format.
3. The multi-agent code generation method according to claim 2, characterized in that, The candidate strategy pool adopts a dynamic sorting mechanism, and a replacement is triggered when the pass rate of a new strategy is higher than the minimum value in the pool; the meta-strategy initialization stage uses a weighted BM25 algorithm to retrieve the meta-experience pool.
4. The multi-agent code generation method according to claim 1, characterized in that, The iterative optimization of the meta-policy through multi-agent cooperation includes: The policy with the highest pass rate in the candidate policy pool is defined as the historical best meta-policy. The evolutionary agent generates a basic evolutionary meta-policy based on the historical best meta-policy and the current meta-policy. The modular intelligent agent decomposes the basic evolutionary meta-policy into multiple independently optimizable sub-policies; The fusion agent merges multiple sub-policies to generate a final meta-policy.
5. The multi-agent code generation method according to claim 4, characterized in that, The step of merging multiple sub-policies to generate a final meta-policy includes: The fusion agent sequentially performs consistency alignment, conflict resolution, module independence, and integrability verification on multiple sub-policies.
6. The multi-agent code generation method according to claim 1, characterized in that, The test cases cover basic test cases and strategy special cases, and are used to verify the correctness of the generated executable code.
7. The multi-agent code generation method according to claim 1, characterized in that, The closed-loop optimization of the meta-strategy through causal analysis includes: By analyzing the agent, the reasons for failure were diagnosed from three dimensions: lack of defense focus, failure of sub-policies, and imbalance of quality weights. By reflecting on the agent, the causal relationship between policy and performance was summarized from three dimensions: policy performance evaluation, exposure of weaknesses, and improvement directions.
8. A multi-agent code generation system, characterized in that, Includes the following steps: The meta-policy initialization module is used to initialize the agent to generate an initial meta-policy through deep problem understanding, and to build a meta-experience pool and a candidate policy pool. The meta-policy evolution module is used to iteratively optimize the meta-policy through multi-agent collaboration to obtain the final meta-policy. The meta-strategy implementation module is used to convert the final meta-strategy into executable code and test cases and verify it. If the verification is successful, the final code is output; if the verification fails, the meta-strategy cause-and-effect reflection module is entered. The meta-policy causal reflection module is used to achieve closed-loop optimization of meta-policies through causal analysis, update the experience to the meta-experience pool, and update the policy to the candidate policy pool.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the multi-agent code generation method according to any one of claims 1-7.
10. An electronic device comprising a memory and a processor, wherein the memory stores computer instructions executable by the processor, characterized in that, The processor executes the multi-agent code generation method according to any one of claims 1-7 when running computer instructions.