A code generation method, device and equipment based on multi-agent language system
Through the code generation method based on multi-agent language system, complex tasks are disassembled, automated code generation and integration, as well as code testing and correction, the efficiency and resource problems of complex code generation tasks are solved, and high-quality and efficient code generation is achieved. .
Patent Information
- Application Number
- CN202411561436.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-11-04
AI Technical Summary
The prior art has poor results in complex code generation tasks, excessive computing resources are consumed, and the hallucination problem of large language models has not been solved.
Using a code generation method based on a multi-agent language system, the code writing agent uses NLP technology to generate Python code sequences, the code integration agent integrates code blocks into standard running functions, and the code test agent performs static Analyze, performance testing and security audits to correct code.
It improves code generation efficiency, reduces manual intervention and repeated calculations, optimizes the use of computing resources, ensures the quality and reliability of generated codes, and reduces subsequent maintenance costs.
Smart Images

Figure CN119065650B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code generation method, device and equipment based on a multi-agent language system. Background Art
[0002] Code generation is a key component in the field of modern software development, promoting technological innovation and rapid prototyping. It can assist software developers to improve productivity by reducing the need for manual coding and reducing fatigue and errors in repetitive and routine programming tasks. By automating code generation, companies can shorten development cycles, respond quickly to market changes, and reduce development costs. Automatically generated code reduces dependence on senior developers, allowing junior developers to effectively contribute to complex projects, thereby optimizing human resource allocation. The development of code generation has been promoted with the emergence of large language models. These large language models meet basic code generation needs through extensive pre-training on a large number of code-related data sets.
[0003] Existing methods can only handle simple code generation. However, the hallucination problem of large language models, excessive consumption of computing resources, and poor performance on complex code generation tasks have not yet been solved. Summary of the invention
[0004] Based on this, it is necessary to provide a code generation method, device and equipment based on a multi-agent language system that can improve the code generation efficiency on an intelligent language model in response to the above technical problems.
[0005] A code generation method based on a multi-agent language system is applied to the multi-agent language system, wherein the multi-agent language system includes: a server and an agent agent. The agent agent includes: a planning engineer, a code writing agent, a code integration agent, and a code testing agent.
[0006] The method comprises:
[0007] Get the user's code generation task. The code generation task includes: code task information and execution parameters of the code task information.
[0008] The code task information is disassembled and judged by planning engineers according to the complexity of the code generation task and the results of semantic understanding to generate multiple sub-code tasks.
[0009] After the sub-code task is converted into a Python code sequence by the code writing agent, the sub-code blocks of the Python code sequence are integrated into a standard running function by the code integration agent.
[0010] According to the standard run function, each Python code sequence is executed and the standard code is generated.
[0011] After the standard code is corrected by the code testing agent, the corrected standard code is transmitted back to the user.
[0012] In one of the embodiments, the method further includes: after receiving the user's code generation requirement through the server, placing the code generation requirement into a task processing queue to obtain a code generation task.
[0013] In one of the embodiments, it also includes: after the code task information is executed by the planning engineer, the decomposable result of the code task information is determined, and if the decomposable result is yes, the code task information is decomposed into multiple sub-code tasks according to the order of execution time.
[0014] In one embodiment, the sub-code task is processed by the conversion function of the code writing agent, and each sub-code task is converted into a Python code sequence to generate a code snippet set. The code snippet set is integrated into a standard operation function by the code integration agent. The standard operation function includes: interface operation, conflict handling and code merging.
[0015] In one of the embodiments, it also includes: traversing and executing each Python code sequence according to a standard running function, evaluating the functional boundary of each code fragment through a code integration agent to obtain an evaluation result, reconstructing the Python code sequence according to the evaluation result, and generating a standard code.
[0016] In one embodiment, the code testing agent includes: a static code analysis module, a performance testing module, and a security audit module. It also includes: the standard code is identified by the static code analysis module for compilation errors to obtain code compilation problems. The standard code is isolated and tested on the standard running function by the performance testing module to obtain isolated code that meets the code design specifications. The code compilation problem and the isolated code are input into the security audit module for code correction to obtain the corrected standard code, and the corrected standard code is transmitted back to the user.
[0017] In one embodiment, the code testing agent integrates all modules in the multi-agent language system to execute the corrected standard code to complete the integrated test to obtain the test report and the corrected standard code.
[0018] A code generation device based on a multi-agent language system, the device comprising:
[0019] The task acquisition module is used to acquire the user's code generation task. The code generation task includes: code task information and execution parameters of the code task information.
[0020] The task decomposition module is used to decompose and judge the code task information by planning engineers according to the complexity of the code generation task and the results of semantic understanding to generate multiple sub-code tasks.
[0021] The standard operation function unified module is used for converting the sub-code task into a Python code sequence through the code writing agent, and then integrating the sub-code blocks of the Python code sequence into a standard operation function through the code integration agent.
[0022] The standard code generation module is used to traverse and execute each Python code sequence according to the standard running function to generate standard code.
[0023] A code calibration module is generated, which is used to return the corrected standard code to the user after the standard code is corrected by the code testing agent.
[0024] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0025] Get the user's code generation task. The code generation task includes: code task information and execution parameters of the code task information.
[0026] The code task information is disassembled and judged by planning engineers according to the complexity of the code generation task and the results of semantic understanding to generate multiple sub-code tasks.
[0027] After the sub-code task is converted into a Python code sequence by the code writing agent, the sub-code blocks of the Python code sequence are integrated into a standard running function by the code integration agent.
[0028] According to the standard run function, each Python code sequence is executed and the standard code is generated.
[0029] After the standard code is corrected by the code testing agent, the corrected standard code is sent back to the user.
[0030] The above-mentioned code generation method, device and equipment based on a multi-agent language system, first, the planning engineer disassembles and judges the code task information, and decomposes the complex code generation task into multiple subtasks. This can simplify the overall task and improve efficiency through parallel processing. Then, the code writing agent uses natural language processing (NLP) technology and code generation models (such as GPT-4) to convert each subtask into a Python code sequence. This step automatically generates code and reduces manual intervention. Then, the code integration agent integrates these sub-code blocks into a standard running function, and uses code analysis and refactoring technology to ensure that the generated code blocks can be seamlessly integrated to avoid the generation of repeated and redundant code. The standard running function generates standard code by traversing and executing each Python code sequence. This step involves dynamic code execution and result verification technology to ensure the correctness and integrity of the code function. Finally, the code testing agent tests and corrects the generated standard code to ensure the correctness and efficiency of the final code. In this process, automated testing technology and error diagnosis and repair technology are used. Through these steps, the solution solves technical problems such as complex code task decomposition and parallel processing, automated code generation and integration, code correctness and consistency, thereby improving code generation efficiency. Automated code generation and integration reduces manual intervention and repetitive calculations, optimizes the use of computing resources, and automated testing and correction ensures the quality and reliability of the generated code, reduces subsequent maintenance costs, and achieves the technical effect of improving code generation efficiency under large language models and reducing computing resource overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a flowchart of a code generation method based on a multi-agent language system in one embodiment;
[0032] Figure 2 A schematic diagram of a code generation step based on a multi-agent language system in one embodiment;
[0033] Figure 3 A code generation framework based on a multi-agent language system in one embodiment;
[0034] Figure 4 is a structural block diagram of a code generation device based on a large language model and multiple agents in one embodiment;
[0035] Figure 5 is a structural block diagram of a code generation device based on a multi-agent language system in one embodiment;
[0036] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0038] The code generation method based on a multi-agent language system provided in this application can be applied to a multi-agent language system. These models are selected for their excellent understanding, thinking and expression capabilities. These include: servers and agent agents. This enables the agent to not only understand complex programming requirements, but also to autonomously generate high-quality code. At the same time, the system defines four agent agents that collaborate in sequence according to the waterfall model. Each agent is responsible for code development tasks at different stages, reducing overlaps in responsibilities and functions to ensure efficient and high-quality execution of the code generation process. Agent agents include: planning engineers , Code Writing Agent , Code Integration Agent And code testing agent , plays a dual role in the system of interpreting and generating code. The selection of appropriate models, such as GPT-3 and CodeBERT, depends on their ability to handle specific types of programming languages and tasks. Using their unique understanding, thinking and expression capabilities, they act as the decision-making part of multi-agents, giving the agents a certain degree of intelligence and autonomy to perform various code generation tasks.
[0039] In one embodiment, Figure 1 As shown, a code generation method based on a multi-agent language system is provided, and the method is applied to the above system as an example for explanation, including the following steps:
[0040] Step 102: Obtain the user's code generation task.
[0041] The code generation task includes: code task information and execution parameters of the code task information.
[0042] Specifically, the server receives detailed code generation requests from users through a network interface and records user requirements. Typically contains user-submitted code generation task instructions, Indicates the description information of the code task. Indicates additional parameters for executing the task. Receive from user Request , that is, complete , and then put the request R into the task processing queue In, it is completed .
[0043] Step 104: The code task information is decomposed and judged by the planning engineer according to the complexity of the code generation task and the semantic understanding result to generate multiple sub-code tasks.
[0044] Specifically, request From the queue is taken out for processing, i.e. , Planning Engineer Receive Tasks , and analyze and disassemble it. The disassembled subtasks can be expressed as , expressed as . A set of output subtasks.
[0045] Step 106, after the sub-code task is converted into a Python code sequence by the code writing agent, the sub-code blocks of the Python code sequence are integrated into a standard running function by the code integration agent.
[0046] Specifically, code writing agent Received from Project Engineer A collection of subtasks , Through the conversion function Each subtask Convert to Python code . Expressed as This process involves the syntax of the programming language, the implementation of logic, and possible code optimization. The generated code snippet collection Contains the code corresponding to all subtasks, that is .
[0047] Step 108, traverse and execute each Python code sequence according to the standard running function to generate standard code.
[0048] Specifically, the code integrates the agent Receive code from the agent A collection of code snippets .
[0049] By integrating the function Will gather All the code snippets in the code are combined into a single runnable unified function , expressed as Right now .
[0050] Step 110: After the standard code is corrected by the code testing agent, the corrected standard code is sent back to the user.
[0051] Specifically, the code testing agent Receive code integration agent Generated integration code . implement And test its running results to verify whether the code meets the predetermined functional and performance requirements. Use the test function To determine the code Whether all test cases are passed, represented by ,in Contains test results. If There are errors or tests that fail. The necessary modifications will be made. The modified function is expressed as ,in is from List of errors identified in the modified code is defined as the final output, i.e. .
[0052] Furthermore, the server Receive data from the code testing agent Final code . Server pair Format it and convert it to JSON format for storage. The server will convert the JSON data Stored in logical storage system In ,in Is the function that writes data to the storage system.
[0053] Furthermore, the server Will Send to user ,Right now .
[0054] In the above-mentioned code generation method based on a multi-agent language system, first, the planning engineer disassembles and judges the code task information and decomposes the complex code generation task into multiple subtasks. This can simplify the overall task and improve efficiency through parallel processing. Then, the code writing agent uses natural language processing (NLP) technology and code generation models (such as GPT-4) to convert each subtask into a Python code sequence. This step automatically generates code and reduces manual intervention. Then, the code integration agent integrates these sub-code blocks into standard running functions, and uses code analysis and refactoring technology to ensure that the generated code blocks can be seamlessly integrated to avoid the generation of duplicate and redundant code. The standard running function generates standard code by traversing and executing each Python code sequence. This step involves dynamic code execution and result verification technology to ensure the correctness and integrity of the code function. Finally, the code testing agent tests and corrects the generated standard code to ensure the correctness and efficiency of the final code. Automated testing technology and error diagnosis and repair technology are used in this process. Through these steps, the solution solves technical problems such as complex code task decomposition and parallel processing, automated code generation and integration, code correctness and consistency, thereby improving code generation efficiency. Automated code generation and integration reduces manual intervention and repetitive calculations, optimizes the use of computing resources, and automated testing and correction ensures the quality and reliability of the generated code, reduces subsequent maintenance costs, and achieves the technical effect of improving code generation efficiency under large language models and reducing computing resource overhead.
[0055] In one of the embodiments, after receiving the code generation requirement of the user through the server, the code generation requirement is put into the task processing queue to obtain the code generation task.
[0056] In one of the embodiments, after the code task information is executed by the planning engineer with execution parameters, the decomposability of the code task information is determined based on the complexity of the code generation task and the semantic understanding result. If the decomposability is yes, the code task information is decomposed into multiple sub-code tasks according to the order of execution time.
[0057] It is worth noting that planning engineers Responsible for receiving and analyzing code generation requirements from users, breaking down complex project requirements into more specific and manageable subtasks. It uses advanced algorithms and data analysis techniques to assess the complexity of tasks and develop detailed development plans based on the characteristics of the requirements. The output is a specific subtask list. , each subtask There are clear goals and expected results so that subsequent agents can execute directly.
[0058] In one embodiment, the sub-code task is processed by the conversion function of the code writing agent, and each sub-code task is converted into a Python code sequence to generate a code snippet set. The code snippet set is integrated into a standard operation function by the code integration agent. The standard operation function includes: interface operation, conflict handling and code merging.
[0059] It is worth noting that the code writing agent First, for each subtask received from the planning engineer Conduct in-depth analysis, which includes understanding the specific requirements of the subtask, the expected functions, and any performance indicators, and using natural language processing technology to parse key information in the task description, such as input, output, expected effect, and business logic. The agent then designs the appropriate code structure to meet the requirements of the subtask. This involves selecting appropriate data structures, algorithms, and design patterns to ensure that the code not only achieves the intended functions, but also achieves the best performance and maintainability.
[0060] In addition, the agent uses its expert knowledge of the programming language and the assistance of the machine learning model to automatically write high-quality Python code. The code is initially optimized during the writing process, such as improving execution efficiency through loop unrolling, memory management optimization, and multi-threading or asynchronous programming techniques. The output is the code block generated for each subtask , these code blocks are logically complete and ready to be integrated into a larger project.
[0061] In one embodiment, each Python code sequence is executed according to a standard running function traversal, and the functional boundary of each code fragment is evaluated by a code integration agent to obtain an evaluation result, and the Python code sequence is reconstructed according to the evaluation result to generate a standard code.
[0062] It is worth noting that the code integrates the agent It integrates code blocks produced by multiple coding agents into a single, fully functional software application or library. It handles all issues related to code merging, including resolving possible conflicts, ensuring interface consistency and data flow correctness, and performing a comprehensive review of all received sub-code blocks. Perform a comprehensive analysis to identify dependencies between code blocks and potential conflict points. This includes analyzing global variables, function dependencies, and API calls. The agent evaluates the functional boundaries of each code block to ensure that the individual functions are maintained during the integration process. After determining the interfaces and interactions of all code blocks, Necessary code refactoring will be performed, including modifying function signatures, unifying variable naming rules, and optimizing data structures and algorithms to improve execution efficiency. The code will also be optimized according to the overall application architecture, for example, by introducing design patterns, improving the modularity and testability of the code. This will output a complete, tested and verified program that can run normally. .
[0063] In one embodiment, the code testing agent includes: a static code analysis module, a performance testing module, and a security audit module. The standard code is identified by the static code analysis module for compilation errors to obtain code compilation problems. The standard code is isolated and tested on the standard running function by the performance testing module to obtain isolated code that meets the code design specifications. The code compilation problem and the isolated code are input into the security audit module for code correction to obtain the corrected standard code, and the corrected standard code is transmitted back to the user.
[0064] It is worth noting that the code testing agent Responsible for the detailed inspection and testing of the integrated code, including static code analysis, performance testing and security auditing. This agent uses a combination of automated testing tools and manual review to ensure that the code is defect-free and meets industry quality standards.
[0065] 1) Static code analysis. Before the code is executed, the inspection agent uses static analysis tools to check the code and identify common programming errors such as syntax errors, type errors, memory leaks, unused variables, accessibility issues, etc. Static analysis helps to find potential problems early and reduce the cost of later debugging.
[0066] 2) Unit testing. Perform isolation tests on each function or module to verify whether their functions meet the design specifications. The inspection agent ensures that sufficient unit test cases are written for all key functions.
[0067] 3) Integration testing. With the gradual integration of various modules, Responsible for integration testing to ensure that the interfaces between modules are correct and that the modules can work together to perform their intended tasks. This involves testing the path of data flow through the entire system, checking data integrity and functional collaboration.
[0068] Output is test report and modified code All problems found will be corrected to ensure the quality and stability of the final product.
[0069] In one embodiment, the code testing agent integrates all modules in the multi-agent language system to execute the corrected standard code to complete the integrated test to obtain the test report and the corrected standard code.
[0070] It is worth noting that the server first receives code data from the output of the code generation system. This data is usually generated by multiple agents in collaboration, including the codes of various modules and functional units. The server ensures the security and integrity of the data during transmission through a secure network connection. The server performs preliminary verification of the received code data. This includes checking the integrity of the data, the correctness of the format, and compliance with the predetermined code standards. This step is to ensure the smooth progress of subsequent processing and prevent erroneous data from affecting system performance.
[0071] Then, the received code data is converted into JSON format. JSON is a lightweight data exchange format that is easy for people to read and write, and easy for machines to parse and generate. The server uses a dedicated parser and serialization tool to convert the code data into a standard JSON object, which includes converting code blocks, function definitions, variable declarations, etc. into JSON key-value pairs.
[0072] Finally, after the code data is converted to JSON format, the server performs further structuring. This process involves organizing and indexing JSON data for easy storage, retrieval, and further processing. Structuring also includes establishing logical relationships and connections for code data, such as linking related functions and variables, marking dependencies in the code, etc. The structured JSON code data is stored in the server's database system. The server uses an efficient database management system to manage this data, including support for fast query, data backup and recovery, etc. In addition, the data will be indexed to optimize the performance of data retrieval and ensure that relevant code information can be quickly accessed when needed.
[0073] In one embodiment, if Figure 2 As shown, a code generation step based on a multi-agent language system is provided, which specifically includes:
[0074] S202, clarifies the identity of the large language model, uses its unique understanding, thinking and expression capabilities to act as the decision-making part of the multi-agent, so that the agent has a certain degree of intelligence and autonomy to perform various code generation tasks; clarifies the identity of the multi-agent, including the four agents working together according to the idea of sequential software development in the waterfall model; clarifies the task boundaries of each agent, and clearly defines the task stage that each agent is responsible for, reducing the overlap of responsibilities and functions.
[0075] S204, the planning engineer is responsible for determining whether the user's needs need to be decomposed, and is responsible for the decomposition of subsequent complex code generation tasks; the code writing agent is responsible for converting the subtasks decomposed by the planning engineer into Python code; the code integration expert is responsible for integrating the sub-code blocks generated by the writing agent into a unified function, paying attention to combining it with the code generation task; after the code generated by the code integration expert is executed, the checking agent is responsible for checking and correcting code errors according to the code generation task, referring to the correct code generation prompts.
[0076] S206, the server receives the final code result generated by the multi-agent language system and performs structured processing in JSON format to store the data logically. This includes verifying, formatting and indexing the code result to ensure the integrity and retrievability of the data. After completing these processes, the server responds to the user with the structured code data in standardized JSON format.
[0077] It is worth noting that by clarifying the roles and responsibilities of each agent, the system effectively reduces functional overlap and redundancy, ensuring work efficiency and accuracy. The server then receives code generation tasks from users, which are transmitted over a secure network connection and are preliminarily analyzed by the system.
[0078] In one embodiment, if Figure 3 As shown, a code generation framework based on a multi-agent language system is provided, which includes four major language models: planning engineering, code writing, code integration experts, and code checking. The user's code generation requirements are transmitted to the planning engineer through the server, and the planning engineer determines whether it needs to be decomposed into subtasks. If so, the code generation requirements are divided into N subtasks, and each subtask is translated, and the variables in the sub-function are extracted and input into the code writing for reconstruction. Next, after the sub-function is executed, the task function is merged by the code integration expert to obtain the sub-code set corresponding to the standard function. When executing this set, the code checking agent detects whether the code is wrong during the entire execution process. If there is no error, the executed code is sent back to the user through the server; otherwise, the code checking agent corrects it and re-transmits the corrected code to the next detection cycle until the code is correct and then sent back to the user.
[0079] In addition, if the engineer determines that the code does not need to be decomposed into subtasks, the original code generation requirement is directly input into the code writing for reconstruction. Next, the reconstructed task code is executed, and the code checking agent detects whether the code is incorrect during the entire execution process. If there is no error, the executed code is sent back to the user through the server; otherwise, the code checking agent corrects it and re-enters the corrected code for the next detection cycle until the code is correct and then sent back to the user.
[0080] It should be understood that although Figure 1-Figure 2 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1-Figure 2 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0081] In one embodiment, Figure 4 As shown, a code generation device based on a large language model and multiple agents is provided, including: an initialization and code generation task receiving module 402, a complex task disassembly module 404, a (sub) code generation module 406, a code integration module 408, a code checking and code modification module 410 and a code formatting storage and output module 412, wherein:
[0082] Initialization and code generation task receiving module 402 is used to process preliminary interaction and code generation requests from users. The main function of this module is to first establish a communication connection with the user to ensure the safe transmission of data, and then receive the code generation tasks submitted by the user. These tasks usually include detailed project descriptions, specific programming requirements and possible user-defined configurations. Once this information is received, the module will parse and format it and convert it into a format that the internal system can understand and operate. In addition, this module is also responsible for verifying the integrity and validity of the received data, eliminating any format errors or data inconsistencies, and ensuring that subsequent modules can smoothly perform task processing. And it is also used to provide a solid foundation and entry point for the smooth operation of the entire code generation system, so that the system can efficiently handle diverse requests from different users.
[0083] The complex task decomposition module 404 is used to analyze the complex programming tasks from the initialization and code generation task receiving module and systematically decompose them into multiple subtasks that are easier to manage. By evaluating the requirements and possible technical challenges of the tasks in detail, the module uses artificial intelligence algorithms to identify the boundaries of each subtask, so that subsequent code development is more targeted and efficient.
[0084] The (sub)code generation module 406 is responsible for generating the corresponding code based on each subtask after decomposition. This module uses a large language model, such as GPT-3 or CodeBERT, to ensure that the generated code not only accurately implements the functional requirements, but also meets high standards in coding style, efficiency and maintainability. This module is also responsible for optimizing the structure of the code to improve its operating efficiency and security.
[0085] The code integration module 408 is used to integrate all independently generated sub-code blocks into a complete software application or library. This process includes coordinating the interfaces between the various sub-modules, resolving conflicts, and ensuring the consistency and efficiency of the data flow and control flow of the entire system. During the integration process, the module will also perform necessary reconstruction to optimize the overall architecture and performance.
[0086] The code inspection and code modification module 410 is used to conduct comprehensive testing and review of the integrated code, including functional testing, performance testing and security testing, to identify and fix potential defects and security vulnerabilities. This module uses automated testing tools to ensure the reliability of the code and compliance with industry standards, and any problems found will be quickly corrected.
[0087] The code formatting storage and output module 412 is used to output the reviewed and modified code in a standardized format, and commonly used formats include JSON, which facilitates the logical storage of data and future accessibility. This module ensures the neatness and organization of the code, making it easy for end users or other systems to understand and integrate the code.
[0088] In one embodiment, Figure 5 As shown, a code generation device based on a multi-agent language system is provided, comprising: a task acquisition module 502, a task decomposition module 504, a standard operation function unification module 506, a standard code generation module 508 and a generated code calibration module 510, wherein:
[0089] The task acquisition module 502 is used to acquire the user's code generation task. The code generation task includes: code task information and execution parameters of the code task information.
[0090] The task decomposition module 504 is used for decomposing and judging the code task information by the planning engineer according to the complexity of the code generation task and the semantic understanding result to generate multiple sub-code tasks.
[0091] The standard operation function unification module 506 is used to integrate the sub-code blocks of the Python code sequence into a standard operation function through the code integration agent after the sub-code task is converted into a Python code sequence by the code writing agent.
[0092] The standard code generation module 508 is used to traverse and execute each Python code sequence according to the standard running function to generate standard code.
[0093] The code calibration module 510 is generated to transmit the corrected standard code back to the user after the standard code is corrected by the code testing agent.
[0094] For the specific definition of a code generation device based on a multi-agent language system, please refer to the definition of a code generation method based on a multi-agent language system in the above text, which will not be repeated here. Each module in the above-mentioned code generation device based on a multi-agent language system can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0095] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a code generation method based on a multi-agent language system is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0096] Those skilled in the art will understand that Figure 4-Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0097] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0098] Get the user's code generation task. The code generation task includes: code task information and execution parameters of the code task information.
[0099] The code task information is disassembled and judged by planning engineers according to the complexity of the code generation task and the results of semantic understanding to generate multiple sub-code tasks.
[0100] After the sub-code task is converted into a Python code sequence by the code writing agent, the sub-code blocks of the Python code sequence are integrated into a standard running function by the code integration agent.
[0101] According to the standard run function, each Python code sequence is executed and the standard code is generated.
[0102] After the standard code is corrected by the code testing agent, the corrected standard code is sent back to the user.
[0103] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0104] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0105] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A code generation method based on a multi-agent language system, characterized in that: Applied to a multi-agent language system, the multi-agent language system includes: a server and an agent agent; the agent agent includes: a planning engineer, a code writing agent, a code integration agent and a code testing agent; The method comprises: Obtaining a code generation task of a user; the code generation task includes: code task information and execution parameters of the code task information; The code task information is decomposed and judged by the planning engineer according to the complexity of the code generation task and the semantic understanding result to generate multiple sub-code tasks, specifically including: after the code task information is executed by the planning engineer according to the complexity of the code generation task and the semantic understanding result, the decomposable result of the code task information is judged, and if the decomposable result is yes, the code task information is decomposed into multiple sub-code tasks according to the order of execution time; After the sub-code task is converted into a Python code sequence by the code writing agent, the sub-code blocks of the Python code sequence are integrated into a standard operation function by the code integration agent, which specifically includes: the sub-code task is processed by the conversion function of the code writing agent, and each sub-code task is converted into a Python code sequence to generate a code snippet set; the code snippet set is integrated into a standard operation function by the code integration agent, and the standard operation function includes: interface operation, conflict handling and code merging; The code integration agent is used to execute each of the Python code sequences according to the standard running function, evaluate the functional boundary of each code fragment through the code integration agent, obtain the evaluation result, reconstruct the Python code sequence according to the evaluation result, and generate the standard code; the code integration agent is used to execute each of the Python code sequences according to the standard running function, evaluate the functional boundary of each code fragment through the code integration agent, obtain the evaluation result, reconstruct the Python code sequence according to the evaluation result, and generate the standard code; Integrate the code blocks produced by multiple coding agents into a single, fully functional software application or library to handle all issues related to code merging, including: resolving possible conflicts, ensuring interface consistency and correct data flow; Perform a comprehensive analysis to identify dependencies and potential conflicts between each of the code blocks; the comprehensive analysis includes analyzing global variables, function dependencies, and API calls; After the standard code is corrected by the code testing agent, the corrected standard code is transmitted back to the user; the code testing agent includes: a static code analysis module, a performance testing module and a security audit module; After the standard code is corrected by the code testing agent, the corrected standard code is returned to the user, including: the standard code is compiled through the static code analysis module to identify compilation errors to obtain code compilation problems; the standard code is isolated and tested on the standard running function through the performance testing module to obtain isolated code that meets the code design specifications; the code compilation problem and the isolated code are input into the security audit module for code correction to obtain the corrected standard code, and the corrected standard code is returned to the user. Before the step of returning the corrected standard code to the user, it also includes: the code testing agent integrates all modules in the multi-agent language system to execute the corrected standard code to complete the integration test to obtain a test report and the corrected standard code.
2. The method according to claim 1, characterized in that Get the user's code generation tasks, including: After receiving the user's code generation requirement through the server, the code generation requirement is put into the task processing queue to obtain the code generation task.
3. A code generation device based on a multi-agent language system, characterized in that: The device comprises: A task acquisition module is used to acquire a user's code generation task; the code generation task includes: code task information and execution parameters of the code task information; The task decomposition module is used for the code task information to be decomposed and judged by the planning engineer according to the complexity of the code generation task and the semantic understanding result to generate multiple sub-code tasks, specifically comprising: after the code task information is executed by the planning engineer according to the complexity of the code generation task and the semantic understanding result, the decomposable result of the code task information is judged, if the decomposable result is yes, the code task information is decomposed into multiple sub-code tasks according to the order of execution time; The standard operation function unification module is used for converting the sub-code task into a Python code sequence through a code integration agent, and then integrating the sub-code blocks of the Python code sequence into a standard operation function through a code integration agent. Specifically, the sub-code task is processed by the conversion function of the code writing agent, and each sub-code task is converted into a Python code sequence to generate a code snippet set; the code snippet set is integrated into a standard operation function through the code integration agent, and the standard operation function includes: interface operation, conflict handling and code merging; A standard code generation module is used to traverse and execute each of the Python code sequences according to the standard running function, evaluate the functional boundary of each code fragment through the code integration agent, obtain an evaluation result, reconstruct the Python code sequence according to the evaluation result, and generate standard code; a code integration agent intelligent body Integrate the code blocks produced by multiple coding agents into a single, fully functional software application or library to handle all issues related to code merging, including: resolving possible conflicts, ensuring interface consistency and correct data flow; Perform a comprehensive analysis to identify dependencies and potential conflicts between each of the code blocks; the comprehensive analysis includes analyzing global variables, function dependencies, and API calls; Generate a code calibration module, which is used to return the corrected standard code to the user after the standard code is corrected by the code testing agent; the code testing agent includes: a static code analysis module, a performance testing module and a security audit module; After the standard code is corrected by the code testing agent, the corrected standard code is returned to the user, including: the standard code is compiled through the static code analysis module to identify compilation errors to obtain code compilation problems; the standard code is isolated and tested on the standard running function through the performance testing module to obtain isolated code that meets the code design specifications; the code compilation problem and the isolated code are input into the security audit module for code correction to obtain the corrected standard code, and the corrected standard code is returned to the user. Before the step of returning the corrected standard code to the user, it also includes: the code testing agent integrates all modules in the multi-agent language system to execute the corrected standard code to complete the integration test to obtain a test report and the corrected standard code.
4. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
Model-based code generation method and device, storage medium and electronic equipment
CN117873453A
Automatic generation method of C language code conforming to AUTOSAR standard
CN117971179A
Code generation method and device, electronic equipment and medium
CN118170382A