Code generation method and device

A multi-agent system for code generation improves accuracy and efficiency by analyzing source code libraries and performing thorough dependency analysis to generate high-quality code that meets user requirements.

CN119149015APending Publication Date: 2024-12-17CHINA UNIONPAY
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411125314.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-15
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Existing automatic code generation systems using Large Language Models (LLM) often produce poor-quality code that requires significant manual correction and resource allocation due to insufficient training data or deviations, leading to inefficiencies.

Method used

A method and system utilizing multiple intelligent agents to parse user requirements, analyze source code libraries, determine dependency relationships, and modify code accurately, incorporating a test and audit process to ensure quality and compliance.

Benefits of technology

Enhances code generation accuracy and reduces manual correction efforts by precisely mapping requirements to code modifications, ensuring seamless integration and reducing debugging workloads.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149015A_ABST
    Figure CN119149015A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code generation method and device, the method and device are applied to a code generation system comprising a plurality of agents with different functions, and the method comprises the steps that a first demand of a user side is analyzed through a demand analysis agent, and a target demand is obtained; analyzing each file in a source code file library associated with the target demand through an engineering analysis agent group, and determining a dependency relationship corresponding to the source code file library; determining to-be-modified information corresponding to the target demand through the dependency relationship; and through the code modification agent, determining a target code according to the to-be-modified information. Through cooperative work of a plurality of agents, multi-level code analysis from microcosmic to macroscopic is realized, and the modification accuracy and the code speed are ensured. In the scheme, the target code is generated based on the source code, seamless integration of the target code and an existing system can be ensured, and the workload of later debugging and reconstruction can be remarkably reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for generating codes. Background Art

[0002] With the development of software technology, automatic code generation has become a way to reduce the repetitive work of developers. After years of development, for different programming languages ​​and scenarios, various developers have developed automatic code generation tools that are adapted to various application scenarios to meet the needs.

[0003] At present, the requirements are generally parsed through the Large Language Model (LLM) model tool to generate the corresponding front-end code. However, the accuracy of the generated code is highly dependent on the training effect of the LLM model. In the case of insufficient training data or large deviations, the LLM model may not be able to accurately understand and implement user requirements, resulting in poor quality of generated code, which requires a lot of manpower and material resources to manually correct and adjust the problem.

[0004] In summary, how to achieve accurate automatic code generation is a technical problem that needs to be solved urgently. Summary of the invention

[0005] The embodiment of the present invention provides a method and device for generating codes, so as to solve the problem in the prior art that the codes generated by the LLM model are of poor quality and require a lot of manpower and material resources to be manually corrected and adjusted.

[0006] In a first aspect, an embodiment of the present invention provides a method for generating code, which is applied to a code generation system including multiple intelligent agents with different functions, including: parsing a first requirement of a user end through a requirement analysis agent to obtain a target requirement; parsing each file in a source code file library associated with the target requirement through an engineering analysis agent group to determine the dependency relationship corresponding to the source code file library; determining information to be modified corresponding to the target requirement through the dependency relationship; and determining the target code according to the information to be modified through a code modification agent.

[0007] Optionally, each file in the source code file library associated with the target requirement is parsed through the engineering parsing agent group to determine the dependency relationship corresponding to the source code file library, including: parsing each file in the source code file library associated with the target requirement through the file parsing agent in the engineering parsing agent group to obtain file parsing information; determining the dependency relationship corresponding to the source code file library according to the file parsing information through the dependency agent in the engineering parsing agent group; determining the information to be modified corresponding to the target requirement through the dependency relationship, including: determining the information to be modified corresponding to the target requirement according to the target requirement and the dependency relationship through the requirement mapping agent in the engineering parsing agent group.

[0008] Optionally, the file parsing information includes the role information of the file, the definition information of all classes or functions in the file, the global variables or constants information in the file, and the import relationship of the file; the dependency relationship includes the calling relationship between components, the data flow between components, the core component information, the core path information, the potential problem information of the component, and the architecture information of the component; any file includes at least one component; through the dependency agent in the engineering parsing agent group, the dependency relationship corresponding to the source code file library is determined according to the file parsing information, including: the dependency agent determines the calling relationship between components and the data flow between components according to the definition information of all classes or functions in the file, the global variables or constants information in the file and the import relationship of the file; the dependency agent determines the core component information and the core path information according to the role information of the file, the definition information of all classes or functions, and the global variables or constants in the file; the dependency agent determines the potential problem information of the component according to the calling relationship between components, the data flow between components, and the definition information of all classes or functions in the file; the dependency agent determines the architecture information of the component according to the calling relationship between components, the data flow between components, the core component information, the core path information, and the potential problem information of the component.

[0009] Optionally, the information to be modified includes the association relationship between the demand point and the source code, the scope of the code to be modified, and key components; the key components include newly added components or components with a modification degree greater than a set threshold; the demand mapping agent in the engineering analysis agent group determines the information to be modified according to the target demand and the dependency relationship, including: the demand mapping agent determines the association relationship between the demand point and the source code according to the target demand and the dependency relationship; the demand mapping agent determines the scope of the code to be modified according to the association relationship between the demand point and the source code; the demand mapping agent determines the key components according to the association relationship between the demand point and the source code, the scope of the code to be modified and the dependency relationship.

[0010] Optionally, the code generation system also includes a test agent and an audit agent; the target code is determined according to the information to be modified through the code modification agent, including: the code modification agent modifies the source code according to the information to be modified, determines the code to be audited and sends it to the test agent; the test agent performs functional tests on key components in the code to be audited, and if the test passes, sends the code to be audited to the audit agent; the audit agent audits the code to be audited according to the audit conditions, and if the audit passes, determines the code to be audited as the target code.

[0011] Optionally, a target code is determined according to the information to be modified through a code modification agent, including: the code modification agent retrieves code generation rules based on retrieval enhancement generation RAG, and determines the target code according to the information to be modified, and the code generation rules include at least one of coding standard conditions, security coding conditions, performance conditions and quality conditions.

[0012] Optionally, the audit conditions include compliance audit, security audit, performance audit and quality audit; the audit agent audits the code to be audited according to the audit conditions, including: the audit agent performs compliance audit, security audit, performance audit and quality audit on the code to be audited in turn, and if the audit fails, generates an audit result and sends it to the code modification agent; the code modification agent modifies the code to be audited according to the audit result, obtains the reprocessed code and sends it to the test agent; the test agent performs functional testing on key components in the reprocessed code until the test passes, and then sends the reprocessed code to the audit agent; the audit agent audits the reprocessed code according to the audit conditions until the audit passes, and then determines the reprocessed code as the target code.

[0013] In a second aspect, an embodiment of the present invention provides a code generation system, including a requirement analysis agent, an engineering parsing agent group and a code modification agent; the requirement analysis agent is used to parse a first requirement of a user terminal, obtain a target requirement and send the target requirement to the engineering parsing agent group; the engineering parsing agent group is used to parse each file in a source code file library associated with the target requirement, and determine the dependency relationship corresponding to the source code file library; through the dependency relationship, determine the information to be modified corresponding to the target requirement, and send the information to be modified corresponding to the target requirement to the code modification agent; the code modification agent is used to determine the target code according to the information to be modified.

[0014] In a third aspect, an embodiment of the present invention provides a device for generating code, which is applied to a code generation system including multiple intelligent agents with different functions, including: an acquisition unit is used to parse a first requirement of a user terminal through a requirement analysis agent to obtain a target requirement; a processing unit is used to parse each file in a source code file library associated with the target requirement through an engineering analysis agent group to determine the dependency relationship corresponding to the source code file library; through the dependency relationship, determine the information to be modified corresponding to the target requirement; through a code modification agent, determine the target code according to the information to be modified.

[0015] Optionally, the processing unit is specifically used to: parse each file in the source code file library associated with the target requirement through the file parsing agent in the engineering parsing agent group to obtain file parsing information; determine the dependency corresponding to the source code file library according to the file parsing information through the dependency agent in the engineering parsing agent group; determine the information to be modified corresponding to the target requirement through the dependency, including: determine the information to be modified corresponding to the target requirement according to the target requirement and the dependency through the requirement mapping agent in the engineering parsing agent group.

[0016] Optionally, the file parsing information includes the role information of the file, the definition information of all classes or functions in the file, the global variables or constants information in the file, and the import relationship of the file; the dependency relationship includes the calling relationship between components, the data flow between components, the core component information, the core path information, the potential problem information of the component, and the architecture information of the component; any file includes at least one component; the processing unit is specifically used for: the dependency agent determines the calling relationship between components and the data flow between components according to the definition information of all classes or functions in the file, the global variables or constants information in the file and the import relationship of the file; the dependency agent determines the core component information and the core path information according to the role information of the file, the definition information of all classes or functions, and the global variables or constants information in the file; the dependency agent determines the potential problem information of the component according to the calling relationship between components, the data flow between components, and the definition information of all classes or functions in the file; the dependency agent determines the architecture information of the component according to the calling relationship between components, the data flow between components, the core component information, the core path information, and the potential problem information of the component.

[0017] Optionally, the information to be modified includes the association between the demand point and the source code, the scope of the code to be modified, and key components; the key components include newly added components or components whose modification degree is greater than a set threshold; the processing unit is specifically used for: the demand mapping agent determines the association between the demand point and the source code according to the target demand and dependency relationship; the demand mapping agent determines the scope of the code to be modified according to the association between the demand point and the source code; the demand mapping agent determines the key components according to the association between the demand point and the source code, the scope of the code to be modified and the dependency relationship.

[0018] Optionally, the code generation system also includes a test agent and an audit agent; the processing unit is specifically used for: the code modification agent modifies the source code according to the information to be modified, determines the code to be audited and sends it to the test agent; the test agent performs functional testing on key components in the code to be audited, and if the test passes, sends the code to be audited to the audit agent; the audit agent audits the code to be audited according to the audit conditions, and if the audit passes, determines the code to be audited as the target code.

[0019] Optionally, the processing unit is specifically used for: the code modification agent retrieves code generation rules based on the retrieval enhancement generation RAG, determines the target code according to the information to be modified, and the code generation rules include at least one of coding standard conditions, security coding conditions, performance conditions and quality conditions.

[0020] Optionally, the audit conditions include compliance audit, security audit, performance audit and quality audit; the processing unit is specifically used for: the audit agent performs compliance audit, security audit, performance audit and quality audit on the audited code in turn, and if the audit fails, generates an audit result and sends it to the code modification agent; the code modification agent modifies the audited code according to the audit result, obtains the reprocessed code and sends it to the test agent; the test agent performs functional testing on key components in the reprocessed code until the test passes, and then sends the reprocessed code to the audit agent; the audit agent audits the reprocessed code according to the audit conditions until the audit passes, and then determines the reprocessed code as the target code.

[0021] In a fourth aspect, an embodiment of the present application further provides a computing device, comprising: a memory for storing programs; a processor for calling the programs stored in the memory, and executing a method for generating code as in the first aspect according to the obtained program.

[0022] In a fifth aspect, an embodiment of the present application further provides a computer-readable non-volatile storage medium, comprising a computer-readable program. When a computer reads and executes the computer-readable program, the computer executes a method for generating code as in the first aspect.

[0023] In a sixth aspect, an embodiment of the present application provides a computer program product, the computer program product comprising a computer program stored on a computer-readable storage medium, the computer program comprising program instructions, and when the program instructions are executed by a computer device, the computer device executes the steps of a method for generating code in the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0025] Figure 1 A schematic diagram of the structure of a code generation system provided by an embodiment of the present invention;

[0026] Figure 2 A flow chart of a method for generating code provided by an embodiment of the present invention;

[0027] Figure 3 A flow chart of a method for determining information to be modified corresponding to a target requirement provided by an embodiment of the present invention;

[0028] Figure 4 A flow chart of a method for determining dependency relationships corresponding to a source code file library provided by an embodiment of the present invention;

[0029] Figure 5 A flowchart of a method for modifying information corresponding to a target requirement provided by an embodiment of the present invention;

[0030] Figure 6 A flow chart of a method for generating a modification report provided by an embodiment of the present invention;

[0031] Figure 7 A flow chart of a method for generating a code to be reviewed provided by an embodiment of the present invention;

[0032] Figure 8 A schematic diagram of the structure of a code generation device provided by an embodiment of the present invention;

[0033] Fig. 9 A schematic diagram of the structure of a computing device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0034] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0035] like Figure 1 As shown, it is a structural diagram of a code generation system provided by an embodiment of the present invention. The code generation system 100 includes: a requirement analysis agent 110, an engineering analysis agent group 120 and a code modification agent 130. The requirement analysis agent 110 is used to analyze the first requirement of the user end, obtain the target requirement and send the target requirement to the engineering analysis agent group 120. The engineering analysis agent group 120 is used to analyze each file in the source code file library associated with the target requirement, determine the dependency relationship corresponding to the source code file library; determine the information to be modified corresponding to the target requirement through the dependency relationship, and send the information to be modified corresponding to the target requirement to the code modification agent 130. The code modification agent 130 is used to determine the target code according to the information to be modified.

[0036] In the embodiment of the present invention, the code generation system is composed of a plurality of agents with different functions. The target requirements can be determined by the requirements analysis agent. The engineering analysis agent group determines the dependency relationship corresponding to the source code file from the source code file library according to the target requirements. The code that needs to be modified or the newly added code corresponding to the target requirements is determined through the dependency relationship. Then, the code modification agent processes the source code according to the code that needs to be modified or the newly added code to obtain the target code.

[0037] like Figure 2 FIG. 1 is a flow chart of a method for generating a code provided by an embodiment of the present invention, the method comprising the following steps:

[0038] Step 201: Analyze the first demand of the user end through the demand analysis agent to obtain the target demand.

[0039] In an embodiment of the present invention, a first demand sent by a user terminal is received, wherein the first demand is a natural language input by the user. The first demand of the user terminal is parsed by a demand analysis agent, and the agent interacts with the user terminal to obtain the user's complete demand, that is, the target demand. For example, the user inputs the first demand on the user terminal, which is to adjust the font of web page A to font size 5. After the demand analysis agent receives the first demand from the user terminal, it will parse it according to the first demand and interact with the user terminal. For example, the demand analysis agent will send a question to the user terminal, asking which module of web page A needs to be adjusted to font size 5. Then the user sends module b to the demand analysis agent through the user terminal. The demand analysis agent then parses the response to the user until the user's complete demand, that is, the target demand, is obtained. The target demand in this example is to adjust all fonts of module b of web page A to font size 5.

[0040] Step 202: parse each file in the source code file library associated with the target requirement through the engineering parsing agent group to determine the dependency relationship corresponding to the source code file library; and determine the information to be modified corresponding to the target requirement through the dependency relationship.

[0041] In the embodiment of the present invention, since the present application is to modify or add to the source code to generate the target code corresponding to the target requirement, the engineering analysis agent group will analyze each file in the source code file library associated with the target requirement, determine the dependency relationship corresponding to the source code file library, and then facilitate the subsequent determination of the information to be modified that needs to be modified in the source code through the dependency relationship.

[0042] Step 203: determine the target code according to the information to be modified through the code modification agent.

[0043] In the embodiment of the present invention, after determining the information to be modified that needs to be modified in the source code, the code modification agent determines the target code according to the information to be modified and the source code, wherein the target code is obtained based on the modification or addition of the source code.

[0044] It can be seen from the above steps 201 to 203 that, through the collaborative work of multiple agents, based on a deeper understanding of the existing source code file library, it is possible to more accurately map the target requirements to the specific code modification location, thereby achieving multi-level code analysis from micro to macro in the subsequent code generation process, ensuring the accuracy and operability of the modification, and accelerating the speed of code generation. Moreover, in this solution, since the target code is obtained based on the source code modification, this modification method can ensure the seamless integration of the target code with the existing system, which can significantly reduce the workload of later debugging and reconstruction.

[0045] Optionally, the engineering analysis agent group includes a file analysis agent, a dependency agent, and a requirement mapping agent. The file analysis agent, dependency agent, and requirement mapping agent in the engineering analysis agent group work together to enable the code generation system to quickly understand the existing source code file library and achieve accurate mapping between target requirements and codes, so that the information to be modified corresponding to the target requirements can be obtained more accurately and quickly. The following describes how the engineering analysis agent group determines the information to be modified corresponding to the target requirements.

[0046] like Figure 3 As shown, it is a flow chart of a method for determining information to be modified corresponding to a target requirement provided by an embodiment of the present invention, and the method comprises the following steps:

[0047] Step 301 , using a file parsing agent in the engineering parsing agent group, parses each file in a source code file library associated with a target requirement to obtain file parsing information.

[0048] In an embodiment of the present invention, when a user terminal sends a first requirement to a code generation system, it triggers the start of a file agent in an engineering analysis agent group, wherein the requirement analysis agent and the file agent are started synchronously, wherein the file agent parses each file in a source code file library associated with a target requirement, and obtains file parsing information corresponding to each file, wherein the file parsing information includes the role information of the file, the definition information of all classes or functions in the file, the global variable or constant information in the file, and the import relationship of the file.

[0049] The role information of the file is used to characterize the role of the file in the entire source code. Since any file includes at least one component, the import relationship of the file is used to characterize the import relationship between multiple components within the file. For example, file A includes component 1 and component 2, where component 1 is the imported component and component 2 is the component imported by component 1. Therefore, the import relationship of file A is used to characterize the import relationship between component 1 and component 2. The definition information of all classes or functions in the file is the signature and brief description of all classes or functions in the file. It should be noted that the file parsing information can be in the form of a report or other forms, which are not limited here.

[0050] Optionally, the file agent receives a file parsing instruction and parses each file in the source code file library associated with the target requirement to obtain file parsing information. The file parsing instruction includes an instruction for obtaining the role information of the file, an instruction for obtaining the definition information of all classes or functions in the file, an instruction for obtaining the global variable or constant information in the file, and an instruction for obtaining the import relationship of the file.

[0051] Optionally, the file agent itself is set up with a program for obtaining the file's function information, definition information of all classes or functions in the file, global variable or constant information in the file, and the file's import relationship from the source code file library. When the file agent starts working, it will execute the set program to parse each file in the source code file library associated with the target requirement to obtain file parsing information.

[0052] It should be noted that any agent in the present application can execute tasks by receiving instructions or according to its own set program, which is the same as the execution logic of the file agent. It is not limited here and will not be repeated later.

[0053] Step 302: Determine the dependency relationship corresponding to the source code file library according to the file parsing information through the dependency relationship agent in the engineering parsing agent group.

[0054] In an embodiment of the present invention, a dependency agent receives file parsing information sent from a file agent, and determines dependencies corresponding to a source code file library, wherein the dependencies include calling relationships between components, data flows between components, core component information, core path information, potential problem information of components, and architecture information of components.

[0055] The following describes how to determine the dependencies corresponding to the source code file library.

[0056] like Figure 4 FIG. 1 is a flow chart of a method for determining a dependency relationship corresponding to a source code file library provided by an embodiment of the present invention. The method comprises the following steps:

[0057] Step 401, the dependency agent determines the calling relationship between components and the data flow between components according to the definition information of all classes or functions in the file, the global variables or constant information in the file and the import relationship of the file.

[0058] In the embodiment of the present invention, since the source code file library includes multiple files, and the file includes at least one component, the dependency agent receives the file parsing information of the file agent, and then outputs the calling relationship between components and the data flow between components according to the definition information of all classes or functions in the file in the file parsing information, the global variables or constant information in the file, and the import relationship of the file.

[0059] Step 402, the dependency agent determines the core component information and the core path information according to the role information of the file, the definition information of all classes or functions, and the global variable or constant information in the file.

[0060] In an embodiment of the present invention, the dependency agent can determine the core component information and core path information in the source code file library based on the role information of the file, the definition information of all classes or functions, and the global variable or constant information in the file, wherein the core path information includes the components involved in the core path.

[0061] Step 403, the dependency agent determines potential problem information of the component according to the calling relationship between components, the data flow between components, and the definition information of all classes or functions in the file.

[0062] In an embodiment of the present invention, the dependency agent determines potential problem information of components based on the calling relationship between components, the data flow between components and the definition information of all classes or functions in the file, wherein the potential problem information of components can be circular dependencies or potential problems between components, which are not limited here.

[0063] Step 404 , the dependency agent determines the architecture information of the components according to the calling relationship between the components, the data flow between the components, the core component information, the core path information, and the potential problem information of the components.

[0064] In the embodiment of the present invention, the dependency agent can construct a relationship dependency architecture between components, that is, the architecture information of the components, based on the calling relationships between components, the data flows between components, the core component information, the core path information and the potential problem information of the components.

[0065] It can be seen from the above steps 401 to 404 that, by receiving the file parsing information sent by the file agent, the dependency agent further understands the dependencies between components within the file based on the file parsing information, obtains the relationship dependency architecture between components, and highlights the core components and core paths, thereby enabling a deeper understanding of the source code file library, which in turn facilitates more accurate demand mapping in the future.

[0066] Step 303 , through the requirement mapping agent in the engineering analysis agent group, according to the target requirement and the dependency relationship, determine the information to be modified corresponding to the target requirement.

[0067] In the embodiment of the present invention, the architecture information of the component is determined in step 302, which enables a deeper understanding of the source code file library, thereby improving the accuracy of the demand mapping. The following specifically describes how to determine the information to be modified corresponding to the target demand, wherein the information to be modified includes the association between the demand point and the source code, the scope of the code to be modified, and the key components.

[0068] like Figure 5As shown, it is a flow chart of a method for modifying information corresponding to a target requirement provided by an embodiment of the present invention, and the method includes the following steps:

[0069] Step 501: The requirement mapping agent determines the association relationship between the requirement point and the source code according to the target requirement and the dependency relationship.

[0070] In an embodiment of the present invention, the requirement analysis agent analyzes the first requirement of the user end to obtain the target requirement, which is sent to the requirement mapping agent. The requirement mapping agent then analyzes the target requirement and combines the dependency relationship to match the requirement point with the source code. It can determine which codes in the source code need to be modified, that is, to determine which codes in the source code correspond to the requirement point, thereby determining the association relationship between the requirement point and the source code.

[0071] Step 502: The requirement mapping agent determines the scope of the code to be modified according to the association relationship between the requirement point and the source code.

[0072] In the embodiment of the present invention, the requirement mapping agent preliminarily determines the components and functions that need to be modified based on the association between the requirement points and the source code. That is, the requirement mapping agent can determine the scope of the code that needs to be modified in the source code corresponding to the target requirement, that is, the scope of the code to be modified, based on the association between the requirement points and the source code. The scope of the code to be modified is composed of all the code that needs to be modified, deleted, or added.

[0073] Step 503: the requirement mapping agent determines the key components according to the association between the requirement points and the source code, the scope of the code to be modified and the dependency relationship.

[0074] In the embodiment of the present invention, the requirement mapping agent can determine the key components according to the association between the requirement point and the source code, the scope of the code to be modified and the dependency sent by the dependency agent, wherein the key components include newly added components or components whose modification degree is greater than a set threshold. The key components are the components that need to be focused on in the code to be modified. The key components will be subsequently subjected to targeted functional testing to quickly determine whether the modified code can be used normally.

[0075] It can be seen from the above steps 501 to 503 that by receiving dependencies, the dependencies between components in the source code file library can be understood more deeply, and then the dependencies between components and the target requirements can be used to associate the various requirements points in the target requirements with the components, determine the scope of the code to be modified and the key components that need to be focused on, and thus achieve more accurate demand mapping.

[0076] It can be seen from the above steps 301 to 303 that the file agent, the dependency agent and the requirement mapping agent work together to quickly and deeply understand the source code folder and implement requirement mapping more accurately.

[0077] Optionally, the requirement mapping agent sends the information to be modified to the code modification agent, and then the code modification agent determines the target code according to the information to be modified.

[0078] Optionally, the engineering analysis agent group includes a summary agent, where the summary agent is used to integrate the information output by the file agent, the dependency agent, and the requirement mapping agent and generate a modification report, which is used to provide more complete and rich code modification suggestions to the code modification agent, and then the code modification agent determines the target code based on the modification report. The following specifically introduces how to generate a modification report.

[0079] like Figure 6 FIG. 1 is a flow chart of a method for generating a modification report provided by an embodiment of the present invention, the method comprising the following steps:

[0080] Step 601: the summary agent in the engineering analysis agent group determines the code information to be modified involved in the information to be modified.

[0081] In an embodiment of the present invention, the report to be modified includes code information to be modified corresponding to any requirement, the complexity of any information to be modified, the potential impact of any information to be modified, and the risk information of the information to be modified. The summary agent receives the file parsing information sent by the file agent, the dependency sent by the dependency agent, and the information to be modified sent by the requirement mapping agent, and then the summary agent determines the code information to be modified involved in the information to be modified based on the information to be modified, wherein the code information to be modified involved in the information to be modified is used to accurately locate the code position involved in each requirement point.

[0082] Step 602 : the summary agent determines the complexity of the information to be modified and the potential impact of the information to be modified according to the core component information, the core path information and the potential problem information of the component.

[0083] Step 603 , the summary agent determines the risk information of the information to be modified according to the code information to be modified, the complexity of the information to be modified and the potential impact of the information to be modified.

[0084] It can be seen from the above steps 601 to 603 that by integrating the file parsing information, dependency relationships and information to be modified, the code location that needs to be modified can be accurately located, and a more complete and comprehensive report to be modified can be obtained, which is convenient for the subsequent code modification agent to modify the code more accurately according to the report to be modified to obtain the target code.

[0085] Optionally, the requirement mapping agent determines preliminary suggestion information according to the association between the requirement point and the source code, the scope of the code to be modified, and the key agent.

[0086] Optionally, the summary agent determines modification suggestions for any information to be modified based on the preliminary suggestion information and dependencies. The modification suggestions for any information to be modified are used to assist the code modification agent in modifying the code. The modification suggestions for any information to be modified will sort the modified code information corresponding to the demand point according to the priority and dependency, so as to determine the modification order of the subsequent code modification agent. The priority can be determined according to the difficulty of modifying the code information, the scope of the modified code information, or other methods, which are not limited here. The modification suggestions can be code refactoring, integration points for new functions, or other modification suggestions, which are not limited here.

[0087] In the embodiment of the present invention, the agents in the engineering analysis agent group work together to understand the source code file library more comprehensively and deeply, and map the target requirements to specific code modification locations. This far exceeds the capabilities of a single large model, because this solution realizes multi-level code analysis from micro to macro by realizing the division of labor and cooperation among multiple agents according to functions, and determines the accuracy and operability of the information to be modified.

[0088] Optionally, the code generation system also includes a test agent and an audit agent. After the code location that needs to be modified in the source code is determined, the code modification agent will generate the audited code according to the information to be modified corresponding to the target requirement, and then the audited code needs to be audited by the audit agent, and the audited code is determined as the target code.

[0089] The following describes how the code modification agent generates target code based on the information to be modified corresponding to the target requirements.

[0090] like Figure 7 FIG. 1 is a flow chart of a method for generating a code to be reviewed provided by an embodiment of the present invention, the method comprising the following steps:

[0091] Step 701: The code modification agent modifies the source code according to the information to be modified, determines the code to be reviewed and sends it to the test agent.

[0092] In the embodiment of the present invention, since the agent can only obtain data from the source code file library and the input during the agent training process, and cannot directly obtain the required data from other places, the code modification agent in this solution will automatically retrieve SDK documents related to the source code and other code libraries based on the retrieval enhancement generation RAG, so that the subsequent generation of the code to be reviewed can be accelerated and more accurate. For example, the target SDK and code library can be used preferentially based on the retrieval enhancement generation RAG, where the target SDK and target code library can be the internal data of Company A.

[0093] The code modification agent retrieves the code generation rules based on the search enhancement generation RAG, determines the target code according to the information to be modified, and the code generation rules include at least one of the coding standard conditions, security coding conditions, performance conditions and quality conditions. The source code is modified according to the information to be modified, the code to be reviewed is determined, and sent to the test agent for functional testing. Among them, the coding standard conditions include but are not limited to: using clear naming conventions, such as camel case naming functions, uppercase naming constants, etc., adding detailed comments, explaining complex logic, maintaining the single responsibility principle of functions, etc. Due to space limitations, they are not listed here. The security coding conditions include but are not limited to: not hard-coding any sensitive information in the code, such as passwords, API keys, strictly validating and cleaning user input, using parameterized queries to prevent SQL injection, implementing appropriate error handling, avoiding exposing system information, etc. The performance condition is that the performance must meet the preset value when processing a large amount of data. If it does not meet the performance, it needs to be optimized. The quality condition is that the generated code should contain detailed comments to explain the implementation logic and any important decisions.

[0094] In step 702 , the test agent performs functional testing on key components in the code to be reviewed to determine whether the test passes. If so, step 703 is executed; if not, step 704 is executed.

[0095] In the embodiment of the present invention, the test agent receives the key components sent by the requirement mapping agent. Since the key components are used to detect whether the code to be reviewed can realize the functions corresponding to the target requirements, the test agent performs functional tests on the key components in the code to be reviewed to determine whether the test passes. If the test passes, it means that the code to be reviewed can realize the functions required by the target requirements. If the test fails, it means that the code to be reviewed cannot realize the functions required by the target requirements and needs to return to the code modification agent for modification.

[0096] Step 703: The test agent sends the code to be reviewed to the review agent.

[0097] In the embodiment of the present invention, the test agent sends the code to be reviewed to the review agent for review.

[0098] Step 704: the testing agent sends the code to be reviewed to the code modification agent for modification.

[0099] In the embodiment of the present invention, due to the test failure, the test agent sends the code to be reviewed and the test result to the code modification agent for modification, and the code modification agent continues to send the modified code to be reviewed to the test agent for testing until the test passes. The test result includes the code range and reason corresponding to the test failure.

[0100] In step 705 , the audit agent audits the code to be audited according to the audit conditions to determine whether the audit is passed. If so, step 706 is executed; if not, step 707 is executed.

[0101] In the embodiment of the present invention, the audit agent audits the audit code according to the audit conditions, wherein the audit conditions include compliance audit, security audit, performance audit and quality audit, wherein the compliance audit includes but is not limited to: whether a clear naming convention is used, whether detailed comments are added to explain complex logic, whether the single responsibility principle of the function is maintained, whether the encryption function is correctly used to process sensitive data, and whether appropriate access control measures are implemented. The security audit includes but is not limited to: evaluating whether any sensitive information is hard-coded in the code, such as passwords, API keys, evaluating whether strict verification and cleaning of user input is performed, evaluating whether parameterized queries are used to prevent SQL injection, whether to avoid exposing system information, identifying possible input validation vulnerabilities, and checking whether errors and exceptions are correctly handled. The performance audit includes but is not limited to: identifying possible performance bottlenecks, such as unnecessary loops or database queries, and suggesting more efficient algorithms or data structures. The quality audit includes but is not limited to: evaluating the readability and maintainability of the code, checking whether the Don't Repeat Yourself (DRY) principle is followed, and suggesting possible refactoring to improve code quality. It should be noted that the contents of the above-mentioned compliance audit, security audit, performance audit and quality audit are only examples and are not limited to the contents of the above-mentioned examples. The compliance audit is conducted on the coding standard conditions in the code modification agent, so the code involved in the coding standard conditions and other conditions involved will be audited. Similarly, the security audit is conducted on the security coding conditions in the code modification agent, so the code involved in the security coding conditions and other conditions involved will be audited. The performance audit is conducted on the performance conditions in the code modification agent, so the performance conditions and other conditions involved will be audited. The quality audit is conducted on the quality conditions in the code modification agent, so the quality conditions and other conditions involved will be audited.

[0102] Step 706: the audit agent determines the code to be audited as the target code.

[0103] Step 707: the audit agent sends the code to be audited to the code modification agent for modification.

[0104] In an embodiment of the present invention, if the audit fails, the audit agent will send the code to be audited and the audit result to the code modification agent, and then the code modification agent will modify the code to be audited according to the audit result, obtain the reprocessed code and send it to the test agent; the test agent will perform functional tests on key components in the reprocessed code until the test passes, and then send the reprocessed code to the audit agent; the audit agent will audit the reprocessed code according to the audit conditions until the audit passes, and then determine the reprocessed code as the target code.

[0105] It can be seen from the above steps 701 to 707 that by performing functional testing and code review on the code to be reviewed generated by the code modification agent, it is possible to not only generate high-quality code that meets the set conditions, but also ensure the security and maintainability of the code.

[0106] Based on the same technical concept, the present application embodiment provides a device for generating a code, which can be seen in Figure 8 The device 800 for generating code is applied to a code generation system including multiple intelligent agents with different functions, including: an acquisition unit 801 is used to parse the first requirement of the user end through a requirement analysis agent to obtain a target requirement; a processing unit 802 is used to parse each file in the source code file library associated with the target requirement through an engineering analysis agent group to determine the dependency relationship corresponding to the source code file library; determine the information to be modified corresponding to the target requirement through the dependency relationship; and determine the target code according to the information to be modified through a code modification agent.

[0107] Optionally, the processing unit 802 is specifically used to: parse each file in the source code file library associated with the target requirement through the file parsing agent in the engineering parsing agent group to obtain file parsing information; determine the dependency corresponding to the source code file library according to the file parsing information through the dependency agent in the engineering parsing agent group; determine the information to be modified corresponding to the target requirement through the dependency, including: determine the information to be modified corresponding to the target requirement according to the target requirement and the dependency through the requirement mapping agent in the engineering parsing agent group.

[0108] Optionally, the file parsing information includes the role information of the file, the definition information of all classes or functions in the file, the global variables or constants information in the file, and the import relationship of the file; the dependency relationship includes the calling relationship between components, the data flow between components, the core component information, the core path information, the potential problem information of the component, and the architecture information of the component; any file includes at least one component; the processing unit 802 is specifically used for: the dependency agent determines the calling relationship between components and the data flow between components according to the definition information of all classes or functions in the file, the global variables or constants information in the file, and the import relationship of the file; the dependency agent determines the core component information and the core path information according to the role information of the file, the definition information of all classes or functions, and the global variables or constants information in the file; the dependency agent determines the potential problem information of the component according to the calling relationship between components, the data flow between components, and the definition information of all classes or functions in the file; the dependency agent determines the architecture information of the component according to the calling relationship between components, the data flow between components, the core component information, the core path information, and the potential problem information of the component.

[0109] Optionally, the information to be modified includes the association between the demand point and the source code, the scope of the code to be modified, and key components; the key components include newly added components or components whose modification degree is greater than a set threshold; the processing unit 802 is specifically used for: the demand mapping agent determines the association between the demand point and the source code according to the target demand and dependency relationship; the demand mapping agent determines the scope of the code to be modified according to the association between the demand point and the source code; the demand mapping agent determines the key components according to the association between the demand point and the source code, the scope of the code to be modified and the dependency relationship.

[0110] Optionally, the code generation system also includes a test agent and an audit agent; the processing unit 802 is specifically used for: the code modification agent modifies the source code according to the information to be modified, determines the code to be audited and sends it to the test agent; the test agent performs functional testing on key components in the code to be audited, and if the test passes, sends the code to be audited to the audit agent; the audit agent audits the code to be audited according to the audit conditions, and if the audit passes, determines the code to be audited as the target code.

[0111] Optionally, the processing unit 802 is specifically used for: the code modification agent retrieves code generation rules based on the retrieval enhancement generation RAG, determines the target code according to the information to be modified, and the code generation rules include at least one of the coding standard conditions, security coding conditions, performance conditions and quality conditions.

[0112] Optionally, the audit conditions include compliance audit, security audit, performance audit and quality audit; the processing unit 802 is specifically used for: the audit agent performs compliance audit, security audit, performance audit and quality audit on the audited code in turn, and if the audit fails, generates an audit result and sends it to the code modification agent; the code modification agent modifies the audited code according to the audit result, obtains the reprocessed code and sends it to the test agent; the test agent performs functional testing on key components in the reprocessed code until the test passes, and then sends the reprocessed code to the audit agent; the audit agent audits the reprocessed code according to the audit conditions until the audit passes, and then determines the reprocessed code as the target code.

[0113] Based on the same technical concept, the present application embodiment provides a computing device, such as Fig. 9 As shown, it includes at least one processor 901 and a memory 902 connected to the at least one processor. The specific connection medium between the processor 901 and the memory 902 is not limited in the embodiment of the present application. Fig. 9 For example, the processor 901 and the memory 902 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.

[0114] In the embodiment of the present application, the memory 902 stores instructions that can be executed by at least one processor 901, and the at least one processor 901 can perform the steps of the above-mentioned method for generating code by executing the instructions stored in the memory 902.

[0115] Among them, the processor 901 is the control center of the computing device, and can use various interfaces and lines to connect various parts of the computing device, and realize the processing of the method of generating code by running or executing instructions stored in the memory 902 and calling data stored in the memory 902. Optionally, the processor 901 may include one or more processing units, and the processor 901 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor can also be integrated into the processor 901. In some embodiments, the processor 901 and the memory 902 can be implemented on the same chip, and in some embodiments, they can also be implemented separately on independent chips.

[0116] Processor 901 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or can be executed by a combination of hardware and software modules in the processor.

[0117] The memory 902 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 902 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 902 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer device, but is not limited thereto. The memory 902 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0118] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned method for generating code.

[0119] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0120] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0121] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0122] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0123] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for generating code, It is characterized in that A code generation system for intelligent agents with different functions, including: The demand analysis agent analyzes the first demand of the user and obtains the target demand; Parsing each file in the source code file library associated with the target requirement through the engineering parsing agent group to determine the dependency relationship corresponding to the source code file library; determining the information to be modified corresponding to the target requirement through the dependency relationship; The target code is determined according to the information to be modified by the code modification agent.

2. The method according to claim 1, It is characterized in that Parsing each file in the source code file library associated with the target requirement through the engineering parsing agent group to determine the dependency relationship corresponding to the source code file library includes: By using the file parsing agent in the engineering parsing agent group, each file in the source code file library associated with the target requirement is parsed to obtain file parsing information; Determine the dependency relationship corresponding to the source code file library according to the file parsing information by using the dependency relationship agent in the engineering parsing agent group; Determining the information to be modified corresponding to the target requirement through the dependency relationship includes: The requirement mapping agent in the engineering analysis agent group determines the information to be modified corresponding to the target requirement according to the target requirement and the dependency relationship.

3. The method according to claim 2, It is characterized in that The file parsing information includes the role information of the file, the definition information of all classes or functions in the file, the global variables or constants in the file, and the import relationship of the file; the dependency relationship includes the calling relationship between components, the data flow between components, the core component information, the core path information, the potential problem information of the component, and the architecture information of the component; any file includes at least one component; The dependency agent in the engineering analysis agent group determines the dependency corresponding to the source code file library according to the file analysis information, including: The dependency agent determines the calling relationship between the components and the data flow between the components according to the definition information of all classes or functions in the file, the global variable or constant information in the file and the import relationship of the file; The dependency agent determines the core component information and the core path information according to the role information of the file in the file, the definition information of all classes or functions, and the global variable or constant information in the file; The dependency agent determines potential problem information of the component according to the calling relationship between the components, the data flow between the components, and the definition information of all classes or functions in the file; The dependency agent determines the architecture information of the component according to the calling relationship between the components, the data flow between the components, the core component information, the core path information, and the potential problem information of the component.

4. The method according to claim 2, It is characterized in that The information to be modified includes the association between the demand point and the source code, the scope of the code to be modified, and key components; the key components include newly added components or components whose modification degree is greater than a set threshold; Determine the information to be modified according to the target requirements and the dependency relationship through the requirement mapping agent in the engineering analysis agent group, including: The requirement mapping agent determines the association relationship between the requirement point and the source code according to the target requirement and the dependency relationship; The requirement mapping agent determines the scope of the code to be modified according to the association relationship between the requirement point and the source code; The requirement mapping agent determines the key component according to the association relationship between the requirement point and the source code, the scope of the code to be modified and the dependency relationship.

5. The method according to any one of claims 1 to 4, It is characterized in that The code generation system also includes a test agent and an audit agent; The code modification agent determines the target code according to the information to be modified, including: The code modification agent modifies the source code according to the information to be modified, determines the code to be reviewed and sends it to the test agent; The test agent performs functional testing on key components in the code to be reviewed, and if the test passes, the code to be reviewed is sent to the review agent; The audit agent audits the code to be audited according to the audit conditions, and if the audit passes, determines the code to be audited as the target code.

6. The method according to any one of claims 1 to 4, It is characterized in that The code modification agent determines the target code according to the information to be modified, including: The code modification agent retrieves code generation rules based on the retrieval enhancement generation RAG, and determines the target code according to the information to be modified. The code generation rules include at least one of a coding standard condition, a security coding condition, a performance condition, and a quality condition.

7. The method according to claim 6, It is characterized in that The audit conditions include compliance audit, security audit, performance audit and quality audit; The audit agent audits the code to be audited according to the audit conditions, including: The audit agent sequentially performs the compliance audit, the security audit, the performance audit and the quality audit on the code to be audited. If the audit fails, an audit result is generated and sent to the code modification agent; The code modification agent modifies the code to be audited according to the audit result, obtains a reprocessed code and sends it to the test agent; The test agent performs functional tests on key components in the reprocessed code until the test passes, and then sends the reprocessed code to the audit agent; The audit agent audits the reprocessed code according to the audit conditions until the audit passes, and then determines the reprocessed code as the target code.

8. A code generation system, It is characterized in that Includes demand analysis agent, engineering analysis agent group and code modification agent; The demand analysis agent is used to analyze the first demand of the user end, obtain the target demand and send the target demand to the engineering analysis agent group; The engineering analysis agent group is used to analyze each file in the source code file library associated with the target requirement to determine the dependency relationship corresponding to the source code file library; Determine the information to be modified corresponding to the target requirement through the dependency relationship, and send the information to be modified corresponding to the target requirement to the code modification agent; The code modification agent is used to determine the target code according to the information to be modified.

9. A device for generating a code, It is characterized in that A code generation system for intelligent agents with different functions, including: The acquisition unit is used to analyze the first demand of the user end through the demand analysis agent to obtain the target demand; The processing unit is used to parse each file in the source code file library associated with the target requirement through the engineering parsing agent group to determine the dependency relationship corresponding to the source code file library; determine the information to be modified corresponding to the target requirement through the dependency relationship; and determine the target code according to the information to be modified through the code modification agent.

10. A computer-readable non-volatile storage medium, It is characterized in that The method comprises computer-readable instructions, and when a computer reads and executes the computer-readable instructions, the computer executes the steps of the method according to any one of claims 1 to 7.

11. A computer device, It is characterized in that include: Memory for storing computer programs; A processor, configured to call a computer program stored in the memory, and execute the steps of the method according to any one of claims 1 to 7 according to the obtained program.

12. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to claim 1 are implemented.

Citation Information

Cited By

  • Game function development system and method based on natural language instruction

    CN120560648A

  • Method and apparatus for determining call relationship of generated code, and storage medium

    WO2026144483A1