Multi-agent code production method and system and electronic equipment

The multi-agent code production method overcomes the bottlenecks of traditional code production models by combining LLM deep analysis and multiple rounds of debugging with AST syntax tree verification and Tree-LSTM correction, achieving efficient and accurate code generation and quality assurance, and adapting to the needs of multi-technology stack and cross-language development.

CN120994180APending Publication Date: 2025-11-21吴东

Patent Information

Application Number
CN202511303119.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-12
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Traditional code production models suffer from bottlenecks such as reliance on manual intervention leading to deviations in requirement transformation, difficulty in ensuring code quality, challenges in cross-language adaptation, lack of quantitative support for architectural decisions, fragmented and difficult-to-reuse knowledge, weak customization of low-code platforms, and insufficient intelligent debugging.

Method used

A multi-agent code production method is adopted, which uses LLM for deep analysis to generate user intent and tool call requirements. Combined with knowledge base and tools, preliminary code is generated, and multiple rounds of debugging and compilation are carried out. AST syntax tree verification and Tree-LSTM correction are used to output the final code, realizing cross-language algorithm transfer and code quality assurance.

Benefits of technology

It significantly improves code generation accuracy, reduces human error, lowers development time, enhances overall development efficiency and code quality, adapts to multi-technology stack development needs, and covers multiple software development scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994180A_ABST
    Figure CN120994180A_ABST
Patent Text Reader

Abstract

The invention relates to a multi-agent code production method and system and electronic equipment. Firstly, on the basis of manually screened source codes and LLM, codes are partitioned according to logic units, and a code knowledge base and an available tool list are formed through deep analysis, classification and storage; based on the user demand, generating a user intention and a tool calling demand through LLM deep analysis; then calling a knowledge base and a tool to generate a preliminary code; and finally, performing multi-round debugging and compiling on the preliminary code by referring to the code knowledge base until no error exists, and outputting a final code. According to the method, the code generation accuracy is improved, compliance is guaranteed through multi-modal analysis, grammar verification and the like, and deviation is reduced; reducing iteration through multi-round debugging, and reducing time consumption; cross-language migration adapts to multiple scenes, and efficiency improvement and quality guarantee are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of software development, and in particular to a multi-agent code production method and system and an electronic device. BACKGROUND

[0002] In the current digital transformation, software development is the core competitiveness of enterprises, but the traditional code production mode and low-code / no-code platforms have many bottlenecks. The traditional mode relies on manual work, and the demand conversion is prone to deviation, code writing is repetitive, and small and medium-sized projects need 2-3 months to deliver. The quality of the code is difficult to guarantee, and manual errors are prone to occur, and cross-language adaptation is difficult. The architecture decision is based on experience, and lacks quantitative support, and the circular dependency detection is inefficient. The dispersed knowledge is difficult to reuse, and team collaboration relies on manual handover. Low-code platforms have weak customization, technology stack lock-in, and insufficient debugging intelligence. Therefore, a new intelligent code production method is needed to break through the bottlenecks. SUMMARY

[0003] Therefore, the present application proposes a multi-agent code production method, which comprises the following steps: According to the user demand, the LLM is used for deep analysis to generate the user intent and tool calling demand; According to the user intent and tool calling demand, the knowledge base and tool are called to generate the preliminary code; According to the preset code knowledge base and the preliminary code, multiple rounds of debugging and compiling are performed until the compiling and running are error-free, and the final code is output; The preset code knowledge base is obtained based on the source code screened by artificial selection and the LLM, and is divided into blocks according to the logic unit and stored in a classified manner; The available tool list is obtained based on the tool dependencies corresponding to the source code screened by artificial selection and the LLM, and is divided into tool types according to the whole code production process, and the tool functions, calling conditions and associated code scenarios are stored in a structured manner.

[0004] In one possible implementation, based on the user demand, the LLM is used for deep analysis to generate the user intent and tool calling demand, which comprises the following steps: Based on the user input demand, multi-modal analysis is performed for classification, and the user demand function points are generated through LLM semantic analysis, ASR conversion and CV recognition; The user demand function points are scored, and if the score is less than 0.8, a follow-up question is generated and the updated user demand function points are scored until the score is greater than or equal to 0.8; If the score is greater than or equal to 0.8, based on the demand structured engine, the user intent and tool calling demand SRS document are generated through BERT-CRF field extraction.

[0005] In a possible implementation, according to the user intention and tool invocation requirements, invoking the knowledge base and tools, generating the code architecture and preliminary code includes the steps of: Based on the user intention and tool invocation requirements SRS document, through requirement analysis, it is divided into functional requirements and non-functional requirements, the functional requirements are divided into modules, and the non-functional requirements are bound to the technology stack to generate technical decision input information; According to the technical decision input information, if the concurrency is greater than 1000, select the microservice architecture, and use Consul for service discovery, if the concurrency is less than or equal to 1000, select the monolithic architecture, and use SpringBoot as the framework; According to the selected architecture and technology stack, the Tarjan algorithm is used for circular dependency detection; If no circular dependency is detected, a component diagram is generated, the component diagram is converted to PlantUML format, and then the ADD document is output; If circular dependency is detected, roll back to monolithic mode, log alarm and trigger manual intervention.

[0006] In a possible implementation, according to the user intention and tool invocation requirements, invoking the knowledge base and tools, generating the code architecture and preliminary code further includes the steps of: Based on the SRS document and the ADD document, a file list is generated, and the dependency relationship is bound and input into the knowledge base for query, and the LLM generates keywords related to the files and dependencies; Based on the generated keywords, the knowledge graph is extended, and related content is obtained through Elasticsearch combined with BM25 sorting and ChromaDB combined with cosine similarity, respectively, the retrieved content is code fused, and the fused code is generated; The fused code is subjected to AST syntax tree verification, if the verification passes, the Google style formatting is performed and the preliminary code is output; If the verification fails, use Tree-LSTM to correct, and after correction, perform AST syntax tree verification again until the verification passes, then perform Google style formatting and output the preliminary code.

[0007] In a possible implementation, according to the code knowledge base and the preliminary code, the generated code is subjected to multiple rounds of debugging and compilation until the compilation and running are error-free, and the final code is output, including the steps of: Based on the preliminary code, incremental compilation is performed, if the incremental compilation has errors, the knowledge base is traced to locate defects, and repair suggestions are generated based on the defects through LLM, if the incremental compilation has no errors, path coverage testing is performed on the preliminary code, and test results are generated; According to the test result, if the test passes, output the preliminary code as the final code, if the test fails, perform error type analysis on the preliminary code to generate an analysis result; According to the analysis result, if the analysis result is a logical error, generate a repair suggestion through the LLM, if the analysis result is a performance problem, trigger a Prometheus alarm through resource monitoring; Based on the repair suggestion, modify the preliminary code, and repeat the above steps until the final code is generated.

[0008] In a possible implementation, the multi-modal analysis specifically includes text analysis, voice analysis and image analysis.

[0009] In a possible implementation, the SRS document describes the function, input and output, key algorithm, dependency relationship and use example of the code block.

[0010] The application also includes a multi-agent code production system for the above method, which comprises an agent module, an LLM module and a knowledge base module; The agent module comprises a product demand agent module, an architecture agent module, a code agent module and a test and compilation agent module, and the agent module is used for overall planning of the whole process, and the sub-modules are responsible for demand, architecture, code generation and testing; The LLM module is used for providing understanding, analysis and decision support to assist code generation optimization; The knowledge base module is used for storing and managing resources to support code generation and analysis.

[0011] In a possible implementation, the product demand agent module is used for interacting with the user to generate user demand; The architecture agent module is used for generating an architecture according to the user demand generated by the product demand module; The code agent module is used for calling the code resources in the knowledge base module according to the architecture generated by the architecture agent module, combining the analysis of the user's intention by the LLM module to generate a preliminary code; The test and compilation agent module is used for calling test code and compilation tools to perform testing and compilation on the preliminary code generated by the code agent module to generate a test report; if the code has errors, re-generation is triggered until there is no error, and the final code is output.

[0012] The application also includes a multi-agent code production electronic device for implementing the above method, comprising a processor and a memory; The processor is used for performing all computing tasks to implement the multi-agent code production method; The memory is used for storing processor executable instructions and static storage data.

[0013] The application has the following advantages: The method of the present application can significantly improve the code generation accuracy, accurately extract the demand function points through multi-modal analysis, combine AST syntax tree checking, Tree-LSTM correction and Google style formatting to ensure code syntax and format compliance and reduce manual writing bias; relying on multi-round debugging and path coverage testing, the number of debugging iterations is greatly reduced, and the development time is reduced. At the same time, with the help of cross-language resource storage of code knowledge base and LLM assisted analysis, cross-language algorithm migration is realized, which adapts to the development needs of multiple technology stacks, covers multiple scene software development, reduces the development threshold, and improves the overall development efficiency and code quality.

[0014] Other features and aspects of the present application will become apparent from the following detailed description of exemplary embodiments, taken in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS

[0015] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the present application and serve to explain the principles of the present application.

[0016] Figure 1A A multi-agent code production method flowchart of an embodiment of the present application is shown; Figure 1A A knowledge base information input flowchart of an embodiment of the present application is shown; Figure 1B A knowledge base reading flowchart of an embodiment of the present application is shown; Figure 1B A method flowchart for generating user intent and tool invocation requirements of an embodiment of the present application is shown; Figure 1C A method flowchart for generating code architecture of an embodiment of the present application is shown; Figure 1C A method flowchart for generating preliminary code of an embodiment of the present application is shown; Figure 2 A method flowchart for compiling and debugging preliminary code of an embodiment of the present application is shown; Figure 2 A structural diagram of a multi-agent code production system of an embodiment of the present application is shown; Figure 3 A working embodiment flowchart of an agent module of an embodiment of the present application is shown. DETAILED DESCRIPTION

[0017] Various exemplary embodiments, features, and aspects of the present application will be described in detail below with reference to the accompanying drawings. The same reference numbers in the drawings represent functionally identical or similar elements. Although various aspects of the embodiments are shown in the drawings, the drawings are not necessarily drawn to scale unless specifically indicated.

[0018] It should be understood that the terms "center", "longitudinal", "transverse", "length", "width", "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only used for the convenience of describing the present application or simplifying the description, and therefore cannot be understood as indicating or implying that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the present application.

[0019] In addition, the terms "first", "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise specifically limited.

[0020] The word "exemplary" here means "serving as an example, an implementation, or an illustration". Any embodiment described as "exemplary" here is not necessarily to be construed as preferred or advantageous over other embodiments.

[0021] In addition, in order to better illustrate the present application, a large number of specific details are given in the specific embodiments below. Those skilled in the art should understand that the present application can also be implemented without some specific details. In some examples, methods, means, elements and circuits well known to those skilled in the art are not described in detail, in order to highlight the main idea of the present application.

[0022] The application of the present application is a multi-agent code production method, system and electronic equipment, which is applied in enterprise-level software research and development, industrial software development, small and medium-sized enterprise lightweight development, low-code / no-code platform enhancement, programming education field / equipment, which plays a role in improving code production accuracy, reducing debugging iteration times, having cross-language algorithm migration capability, covering software development life cycle, reducing development threshold and improving development efficiency.

[0023] Method Specifically referring to Figure 3 , Figure 4 The multi-agent code production method flowchart of the embodiment of the present application is shown.

[0024] The application comprises a multi-agent code production method, which comprises the following steps: 101, according to user demand, deep analysis is carried out through an LLM to generate user intention and tool calling demand; 102, according to the user intention and the tool calling demand, a knowledge base and a tool are called to generate preliminary code; and 103, according to a preset code knowledge base and the preliminary code, multi-round debugging and compiling are carried out until no error is found in the compiling and running, and finally the output code is output. The preset code knowledge base is obtained by carrying out block division according to logical units and classified storage of code blocks based on manually screened source code and an LLM, and the available tool list is obtained by carrying out tool type division according to the whole code production process, and structured storage of tool functions, calling conditions and associated code scenes based on tool dependencies corresponding to the manually screened source code and the LLM. By constructing the code knowledge base and the tool list first, generating the preliminary code by analyzing the demand, and finally outputting the error-free code through multi-round debugging, the LLM and the knowledge base are integrated in the whole process, manual intervention is reduced, the problems of low efficiency and poor quality in the traditional mode are solved, the code production efficiency and quality are improved, and the multi-scene research and development demand is adapted.

[0025] In a specific embodiment, the manually screened code selects a high-quality open source code library recognized by the industry as a basic data source. It includes the operating system kernel, such as Linux Kernel, the compiler / interpreter, such as Clang, GCC, Rustc, CPython (Python interpreter), Java HotSpot VM, the virtual machine, such as QEMU, the database system, such as MySQL, PostgreSQL, and the excellent open source library / framework of the mainstream programming language, such as NumPy / Pandas of Python, SpringFramework of Java, Boost of C++, etc. The screening standards include code standardization, maintainability, performance, community activity, test coverage, etc.

[0026] In a specific embodiment, the selected source code is preprocessed, including cleaning irrelevant files (such as build scripts, documents), standardizing formats, and using LLM to intelligently block the source code according to logical units. In the block division process, the block granularity is targeted at “function completeness”, including independent functions / methods, classes with clear interfaces and responsibilities, modules / files implementing specific algorithms or functions, and standard implementation fragments of design patterns. In the block division process, necessary context information (such as the file, class, namespace, etc. to which it belongs) needs to be retained.

[0027] Specifically referring to Figure 4 , Figure 5A knowledge base information entry flowchart of an embodiment of the present application is shown. In a specific embodiment, the knowledge base is divided into a search engine, a vector database, and a knowledge graph. The search engine stores the code block itself, the generated explanation document, and related metadata (such as the source project, language) into a full-text search engine. An efficient index is established to support complex queries based on keywords, function descriptions, code snippets, etc. The vector database converts the explanation document (or code block itself) of the code block into a high-dimensional vector through an embedding model and stores it in the vector database. This enables the system to find related code based on semantic similarity. The knowledge graph constructs a knowledge graph from the extracted keywords and their relationships (such as co-occurrence relationships, hierarchical relationships, and functional associations). The graph is used to understand the connections between concepts and assist in more accurate code retrieval.

[0028] With specific reference to Figure 5 , Figure 6 A knowledge base reading flowchart of an embodiment of the present application is shown. Specifically, for reading the above-mentioned database, in the case of code searching and generating requirements, first submit the code requirements to the large language model, and based on the requirements, the large language model generates a series of keywords, finds related keywords in the knowledge graph based on these keywords, and then submits these keywords and code requirements to the large language model to obtain search terms for the search engine and query requirements for the vector database. Based on the search results of the search engine, add the search results of the vector database and the code requirements to submit to the large language model, and on this basis, the large language model generates the required code.

[0029] With specific reference to Figure 6 , Figure 7 A method flowchart for generating user intent and tool invocation requirements of an embodiment of the present application is shown.

[0030] In one possible implementation, based on user requirements, the LLM performs deep analysis to generate user intent and tool invocation requirements, including step 201, based on user input requirements, through multi-modal analysis for classification, and through LLM semantic analysis, ASR conversion, and CV recognition, to generate user requirement function points. Step 202, score the user requirement function points, if the score is less than 0.8, generate follow-up questions and score the updated user requirement function points until the score is greater than or equal to 0.8. And step 203, if the score is greater than or equal to 0.8, based on the requirement structured engine, through BERT-CRF field extraction, to generate user intent and tool invocation requirement SRS document. Through multi-modal analysis and LLM semantic analysis, etc. to extract requirement function points, combined with the scoring mechanism to complete the requirements, and then generate SRS document. Effectively avoid demand understanding deviation, ensure the completeness and accuracy of the demand function points, provide accurate basis for subsequent code generation, and reduce the research and development rework caused by demand problems.

[0031] With specific referenceFigure 7 , ​ A flow chart of a method for generating a code architecture according to an embodiment of the present application is shown.

[0032] In a possible implementation, according to the user intent and tool invocation requirements, invoking the knowledge base and the tool, generating the code architecture and the preliminary code includes the following steps. Step 301, based on the user intent and the tool invocation requirements SRS document, the requirements are parsed into functional requirements and non-functional requirements, the functional requirements are divided into modules, the non-functional requirements are bound to the technology stack, and the technical decision input information is generated. Step 302, according to the technical decision input information, if the concurrency is greater than 1000, the microservice architecture is selected, and Consul is used for service discovery, if the concurrency is less than or equal to 1000, the monolithic architecture is selected, and SpringBoot is used as the framework. Step 303, according to the selected architecture and technology stack, the Tarjan algorithm is used for circular dependency detection. Step 304, if no circular dependency is detected, a component diagram is generated, the component diagram is converted into PlantUML format, and then an ADD document is output. And step 305, if circular dependency is detected, rollback to monolithic mode, log alarm and trigger manual intervention. By dividing the functional and non-functional requirements according to the requirements, selecting the architecture according to the concurrency, and detecting the circular dependency by using the Tarjan algorithm, the quantitative science of architecture decision is realized, the disadvantages of experience decision are avoided, the architecture defects are checked in time, the rationality and stability of the architecture are ensured, and the subsequent architecture reconstruction cost is reduced.

[0033] In a specific embodiment, the agent receives inputs, which can include natural language requirements directly proposed by the user, a list of available tools and their function descriptions (such as calling a compiler, running a test, accessing a database, calling an external API, etc.), existing structured documents (such as requirement documents, architecture design documents), and requests or intermediate results from other agents.

[0034] Specifically referring to ​ , ​ A flow chart of a method for generating a preliminary code according to an embodiment of the present application is shown.

[0035] In a possible implementation, according to the user intention and the tool calling requirement, calling the knowledge base and the tool to generate the code architecture and the preliminary code further includes the following steps: 401, based on the SRS document and the ADD document, generating a file list and performing dependency binding and inputting the knowledge base for querying, and generating keywords related to the files and the dependencies through the LLM. 402, based on the generated keywords, extending the knowledge graph, and respectively acquiring related content through Elasticsearch combined with BM25 sorting and ChromaDB combined with cosine similarity, and performing code fusion on the acquired content to generate fused code. 403, performing AST syntax tree checking on the fused code, and if the checking is passed, performing Google style formatting to output the preliminary code. And 404, if the checking is not passed, performing correction using Tree-LSTM, and performing AST syntax tree checking again after the correction, until the checking is passed, and then performing Google style formatting and outputting the preliminary code. Through the fused code combined with multiple tools, the preliminary code is output after AST syntax tree checking and Tree-LSTM correction and then formatting. The code syntax correctness and the format standardization are greatly improved, the code basic errors are reduced, the pressure for subsequent debugging is reduced, and the preliminary code quality is improved.

[0036] With specific reference ​ , ​ A flowchart of a method for compiling and debugging the preliminary code according to an embodiment of the present application is shown.

[0037] In a possible implementation, according to the code knowledge base and the preliminary code, the generated code is subjected to multiple rounds of debugging and compiling until the code is compiled and run without errors, and the final code is output, including the following steps: 501, based on the preliminary code, performing incremental compilation, if the incremental compilation has errors, locating the defects through the knowledge base, and based on the defects, generating repair suggestions through the LLM, if the incremental compilation has no errors, performing path coverage testing on the preliminary code to generate a test result. 502, according to the test result, if the test is passed, outputting the preliminary code as the final code, if the test is not passed, performing error type analysis on the preliminary code to generate an analysis result. 503, according to the analysis result, if the analysis result is a logical error, generating repair suggestions through the LLM, if the analysis result is a performance problem, triggering a Prometheus alarm through resource monitoring. And 504, based on the repair suggestions, modifying the preliminary code, and repeating the above steps until the final code is generated. Through incremental compilation and path coverage testing to troubleshoot errors, repair suggestions or alarms are generated according to error types. The code problem is accurately located and efficiently repaired, the number of debugging iterations is reduced, the research and development cycle is shortened, and the final output code is error-free and performance meets the standards.

[0038] In a possible implementation, the multi-modal analysis specifically includes text analysis, speech analysis, and image analysis. In the implementation of multi-modal analysis (including text, speech, and image analysis), the product demand intelligent agent can efficiently process various inputs from the user: key information in the demand document is extracted through text analysis, speech analysis (combined with ASR conversion) is used to process voice demands, and image analysis (combined with CV recognition) is used to interpret sketches / prototypes. After LLM semantic analysis, the function points are accurately extracted, and the completeness of the demand is evaluated, reducing information omission, laying the foundation for generating a standard SRS document, and improving the efficiency and accuracy of demand analysis.

[0039] In a possible implementation, the SRS document describes the functions, input and output, key algorithms, dependencies, and usage examples of the code block. In this implementation, the explicit description of the functions, input and output, and other key information of the code block in the SRS document provides accurate design basis for the architecture intelligent agent, helping it to reasonably select the technology stack and plan the architecture; at the same time, the code intelligent agent accurately matches the demand when generating code, reducing the deviation caused by ambiguous information. It also helps the test and compilation intelligent agent to clearly define the test standards, improves the test targeting, and ultimately improves the accuracy of code generation and reduces the number of debugging iterations.

[0040] System Referring specifically to ​ , ​ The structure diagram of the multi-agent code production system of the embodiment of the application is shown.

[0041] The application also includes a multi-agent code production system for the above method, which includes an intelligent agent module 601, an LLM module 602, and a knowledge base module 603. The intelligent agent module 601 includes a product demand intelligent agent module 601-1, an architecture intelligent agent module 601-2, a code intelligent agent module 601-3, and a test and compilation intelligent agent module 601-4. The intelligent agent module is used to plan the whole process, and each sub-module is responsible for demand, architecture, code generation, and testing. The LLM module 602 is used to provide understanding, analysis, and decision support to assist code generation optimization. The knowledge base module 603 is used to store and manage resources to support code generation and analysis.

[0042] In a possible implementation, the product demand intelligent agent module 601-1 is used to interact with the user and generate user demand.

[0043] In particular, the working principle of the product demand intelligent agent module 601-1 is as follows: first, the user's demand is analyzed and the functional points are extracted. According to the user's input demand, multi-modal analysis means are used for classification. In this process, LLM semantic analysis, ASR conversion, and CV recognition technologies are used to accurately extract the functional points in the user's demand. Then, the demand functional points are evaluated and improved. The extracted user demand functional points are scored. If the score is less than 0.8, a follow-up question is generated to guide the user to supplement the information, and then the updated user demand functional points are rescored until the score reaches 0.8 or above.

[0044] Finally, the user's intent and tool call demand are generated. When the score reaches 0.8 or above, relying on the demand structuring engine, the BERT-CRF field extraction technology is used to generate an SRS file containing the user's intent and tool call demand.

[0045] In a specific embodiment, the product demand intelligent agent module 601-1 is responsible for interacting with users or product managers to clarify, refine, and standardize software requirements. This module receives the original requirements provided by users through natural language, sketches, prototypes, or existing documents, clarifies ambiguities, identifies potential contradictions, and actively asks questions to obtain missing information through multiple rounds of dialogue driven by the LLM in the module. Then the module structures the collected information, distinguishes between functional and non-functional requirements, identifies user stories or use cases, and prioritizes the requirements. Finally, the module writes an SRS file in Markdown or a specific format document file and notifies the architecture intelligent agent module 601-2. The output is a standardized SRS file. The SRS file format includes project overview, user role definition, detailed description, input and output, business rules, functional requirement list, non-functional requirements, user interface prototype link, and data model sketch.

[0046] The architecture intelligent agent module 601-2 is used to generate an architecture based on the user demand generated by the product demand intelligent agent module.

[0047] In particular, the working principle of the architecture intelligent agent module 601-2 is as follows: based on the SRS file containing the user's intent and tool call demand generated by the product demand intelligent agent module 601-1, the content is first divided into functional and non-functional requirements through demand analysis. Among them, the functional requirements are divided into modules, and the non-functional requirements are bound to the technology stack, and finally the input information required for technical decision-making is formed. Then, according to the concurrency index in the technical decision-making input information, the architecture is selected: if the concurrency exceeds 1000, the microservice architecture is adopted and the Consul service discovery is implemented; if the concurrency does not exceed 1000, the monolithic architecture is selected, and SpringBoot is used as the basic framework.

[0048] Finally, based on the determined architecture and technology stack, Tarjan algorithm is used to carry out circular dependency detection. If no circular dependency is found, a component graph is first generated, and then converted into PlantUML format, and then the ADD file is output. If a circular dependency is detected, the architecture is rolled back to the monolithic mode, and a log warning mechanism is triggered and a manual intervention process is started.

[0049] In a specific embodiment, the architecture agent module 601-2 designs the overall architecture of the software system according to the SRS. The SRS file is received from the product requirement agent. The LLM in this module deeply analyzes the SRS file to understand the system size, complexity, key functions and non-functional constraints, in order to select a suitable technology stack, taking into account factors such as team familiarity, community support, performance requirements, etc. Then the system architecture style is designed and the core modules / components and their responsibilities, interfaces are defined, the key data flow, API specification is designed and the scalability, maintainability, security, deployment strategy is considered. This module writes the ADD file into a document file and notifies the code agent module 601-3 of the generated ADD file. It contains architecture decision records, system context diagrams, container diagrams, component diagrams, key class / interface design sketches, data models, deployment diagrams, and non-functional requirement solution descriptions.

[0050] The code agent module 601-3 is used to generate preliminary code based on the architecture generated by the architecture agent module, call the code resources in the knowledge base module, and combine the analysis of user intent by the LLM module.

[0051] Specifically, the working principle of the code agent module 601-3 is as follows: based on the SRS document generated by the product requirement agent module 601-1 and the ADD document generated by the architecture agent module 601-2, a file list is first generated and a dependency relationship is established, and these information is input into the knowledge base for query. Then, the LLM generates keywords related to the files and their dependencies.

[0052] Then the generated keywords are used to extend the knowledge graph. Two ways are used to obtain related content: Elasticsearch combined with BM25 sorting and ChromaDB combined with cosine similarity. Then the retrieved content is code fused to form fused code. The fused code is subjected to AST syntax tree verification. If the verification passes, it is formatted according to Google style and then the preliminary code is output. If the AST syntax tree verification fails, Tree-LSTM is used to correct the code. After correction, the AST syntax tree verification is performed again until it passes, then it is formatted according to Google style and the preliminary code is output.

[0053] In a specific embodiment, the code agent module 601-3 generates source code according to the SRS file and the ADD file on a file-by-file basis. It receives the SRS file from the product requirement agent and the ADD file from the architecture agent. The internal LLM of the module combines the functional description of the SRS file and the technical design of the ADD file to plan the list of files to be generated and their dependencies. For each file to be generated, the role of the file in the architecture and the functional points to be implemented are specified, and the code knowledge base query process is used to find relevant high-quality reference code and algorithm implementation. The source code of the file is generated by integrating the requirements, architecture design, and reference code. The module notifies the test and compilation agent module 601-4 to output the specific source code file and the necessary configuration file by writing the generated code and configuration file to the corresponding location in the project directory structure.

[0054] The test and compilation agent module 601-4 is used to call the test code and the compilation tool to perform testing and compilation on the preliminary code generated by the code agent module, generate a test report, and trigger re-generation if there is an error in the code until there is no error and the final code is output.

[0055] Specifically, the working principle of the test and compilation agent module 601-4 is as follows: incremental compilation is performed based on the preliminary code generated by the code agent module 601-3. If an error occurs during the compilation process, the root cause is traced with the help of the knowledge base to locate the defect, and based on the discovered defect, the corresponding repair suggestion is generated by the LLM in the module; if the incremental compilation is successfully completed, path coverage testing is carried out on the preliminary code, and the test result is obtained. Different operations are taken according to the test result. If the test passes, the preliminary code is directly determined as the final code and output; if the test fails, the error type of the preliminary code is analyzed to form an analysis result. Then, according to the error type analysis result, processing is performed. If the analysis result shows that it is a logical error, a repair suggestion is generated by the LLM in the module; if there is a problem in performance, Prometheus is triggered to alarm by the resource monitoring mechanism. The preliminary code is modified according to the generated repair suggestion, and then the above steps are repeated until the final code that meets the requirements is generated.

[0056] In a specific embodiment, the test compilation intelligent agent module 601-4 automatically tests, compiles and builds the code generated by the code intelligent agent module, ensuring its correctness and runnability. It receives notifications from the code intelligent agent, and obtains all the code files generated by it. It calls the corresponding compiler to compile the code. It captures compilation errors and warnings. It automatically generates or supplements unit test cases for key functions using LLM or test templates, and calls the unit test framework to execute unit tests and collect test results. It performs integration testing at the module or service level, and executes the build script to generate a deployable package. Its output includes compilation results, test pass / fail details, code coverage, performance benchmarks to build a runnable application package. If the compilation or testing fails, the intelligent agent analyzes the error logs, locates the source of the problem and generates a clear error report containing error description, reproduction steps, and relevant code snippets. The error report is fed back to the code intelligent agent, triggering the repair process, so that the code intelligent agent repairs the code according to the error report, and after the repair is completed, the test compilation intelligent agent is notified again for verification. This process is repeated until all tests pass and the compilation is successful.

[0057] With specific reference to ​ , ​ A working embodiment flowchart of the intelligent agent module of the embodiments of the present application is shown.

[0058] In a specific embodiment, in step 701, the user inputs to the product requirement intelligent agent module: "I need a user registration function, users can register through email and password." After interaction, the product requirement intelligent agent module determines that the user needs code with email verification, password encryption storage, and return registration success / failure information function. The product requirement intelligent agent outputs an SRS file, which includes the definition / register API endpoint, request body, response body, and error handling. In step 702, the architecture intelligent agent inputs the SRS, adopts RESTful API, SpringBoot framework, and MySQL database. Define the UserController, UserService, and UserRepository interfaces, and use JPA. The password is encrypted using BCrypt. Output the ADD file containing the above design decisions, class diagram, API specification, and database table design. In step 703, the code intelligent agent module inputs the SRS file and the ADD file, and plans to generate UserController.java, UserService.java, UserServiceImpl.java, UserRepository.java, User.java, and Application.java. Specifically, the requirement for generating UserController.java is to implement @PostMapping(" / register"), which depends on the architecture of UserService. Query the knowledge base and generate the initial code, which includes injecting UserService, calling its registerUser method, and handling success / exception return. Generate other files according to the same principle. In step 704, the test compilation intelligent agent module obtains all.java files and calls mvn compile for compilation. Assume that a method signature in UserService is misspelled, resulting in compilation failure. Output an error report indicating that UserServiceImpl.java line X, the method is not defined. In step 705, the code intelligent agent module receives the error report, locates the error line, corrects the method signature, regenerates / saves the file, and notifies the test compilation intelligent agent. In step 706, the test compilation intelligent agent module compiles successfully, generates and executes the unit test of UserService, and outputs the final test report and build product, i.e., the executed JAR package, after the test passes.

[0059] Obviously, those skilled in the art should understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned embodiment of each control method. The above-mentioned modules or steps of the present application can be realized by a general computing device, which can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices. Alternatively, they can be realized by program codes executable by a computing device, so that they can be stored in a storage device for execution by a computing device, or they can be made into individual integrated circuit modules, or a plurality of modules or steps among them can be made into a single integrated circuit module. Thus, the present application is not limited to any specific combination of hardware and software.

[0060] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned embodiment of each control method. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk or a solid state disk, etc. The storage medium can also include a combination of the above types of memories.

[0061] Electronic device The present application also includes a multi-agent code production electronic device for implementing the above-mentioned method, comprising a processor and a memory. The processor is used to perform all computing tasks and implement the multi-agent code production method. The memory is used to store processor-executable instructions and static storage data.

[0062] The electronic device of the present disclosure embodiment includes a processor and a memory for storing processor-executable instructions. Wherein the processor is configured to execute executable instructions to implement any of the above-mentioned multi-agent code production methods.

[0063] It should be noted that the number of processors can be one or more. At the same time, the electronic device of the present disclosure embodiment can also include an input device and an output device. Among them, the processor, the memory, the input device and the output device can be connected through a bus, or connected through other means, which is not limited here.

[0064] The memory, as a computer readable storage medium of the multi-agent code production method, can be used to store software programs, computer executable programs and various modules, such as programs or modules corresponding to the multi-agent code production of the embodiments of the present disclosure. The processor executes the software programs or modules stored in the memory, thereby performing various function applications and data processing of the electronic device.

[0065] The input device can be used to receive input numbers or signals. Among them, the signal can be a key signal related to the user settings and function control of the device / terminal / server. The output device can include a display device such as a display screen.

[0066] The above has described the embodiments of the present application, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes are obvious to those skilled in the art without departing from the scope and spirit of the described embodiments. The selection of the terms used herein is intended to best explain the principles, practical applications or improvements to the technology in the market of the embodiments, or to enable other ordinary skilled persons in the art to understand the embodiments disclosed herein.

Claims

1. A multi-agent code production method, characterized in that, Including the following steps: Based on user needs, LLM is used for in-depth analysis to generate user intent and tool call requirements; Based on the user intent and the tool invocation requirements, the knowledge base and tools are invoked to generate preliminary code; Based on the preset code knowledge base and the initial code, perform multiple rounds of debugging and compilation until there are no errors in compilation and execution, and output the final code; The preset code knowledge base is obtained by dividing source code and LLM data into blocks according to logical units and classifying and storing the code blocks. The list of available tools is based on the tool dependencies and LLM corresponding to the source code selected manually. The tools are categorized by type according to the entire code production process, and the tool functions, calling conditions and associated code scenarios are stored in a structured manner.

2. The method according to claim 1, characterized in that, The process of generating user intent and tool call requirements through in-depth analysis using LLM based on user needs includes the following steps: Based on user input requirements, classification is performed through multimodal parsing, and user-required functional points are generated through LLM semantic analysis, ASR transformation, and CV recognition. The system scores user-requested features. If the score is less than 0.8, it generates follow-up questions and scores the updated user-requested features until the score is greater than or equal to 0.

8. If the score is greater than or equal to 0.8, based on the requirement structuring engine, user intent and tool call requirement SRS document is generated by extracting fields through BERT-CRF.

3. The method according to claim 1, characterized in that, The process of generating code architecture and preliminary code by invoking the knowledge base and tools based on user intent and tool usage requirements includes the following steps: Based on the SRS document containing user intent and tool call requirements, the requirements are divided into functional requirements and non-functional requirements through requirement analysis. The functional requirements are divided into modules, and the non-functional requirements are bound to the technology stack to generate technical decision input information. Based on the technical decision input information, if the concurrency is greater than 1000, choose a microservice architecture and use Consul for service discovery; if the concurrency is less than or equal to 1000, choose a monolithic architecture and use Spring Boot as the framework. Based on the selected architecture and technology stack, circular dependency detection is performed using the Tarjan algorithm; If no circular dependency is detected, a component diagram is generated, the component diagram is converted into PlantUML format, and then an ADD document is output. If a circular dependency is detected, roll back to monolithic mode, generate a log alert, and trigger manual intervention.

4. The method according to claim 3, characterized in that, The process of generating code architecture and preliminary code by invoking knowledge bases and tools based on user intent and tool invocation requirements also includes the following steps: Based on SRS and ADD documents, a file list is generated and dependency relationships are bound and entered into the knowledge base for querying. Keywords related to files and dependencies are generated through LLM. The knowledge graph is expanded based on the generated keywords. Relevant content is obtained by using Elasticsearch with BM25 sorting and ChromaDB with cosine similarity. The retrieved content is then fused to generate fused code. Perform AST syntax tree verification on the fused code. If the verification passes, output the preliminary code after Google-style formatting. If the validation fails, Tree-LSTM is used for correction. After correction, the AST syntax tree is validated again until the validation passes. Then, Google-style formatting is performed and the initial code is output.

5. The method according to claim 1, characterized in that, The process of debugging and compiling the generated code multiple times based on the code knowledge base and the initial code until there are no errors in compilation and execution, and then outputting the final code, includes the following steps: Based on the initial code, incremental compilation is performed. If there are errors in the incremental compilation, the defects are located by tracing the source through the knowledge base, and repair suggestions are generated through LLM based on the defects. If there are no errors in the incremental compilation, path coverage testing is performed on the initial code, and test results are generated. Based on the test results, if the test passes, the preliminary code is output as the final code; if the test fails, the preliminary code is subjected to error type analysis, and the analysis results are generated. Based on the analysis results, if the analysis results indicate a logical error, a repair suggestion is generated through LLM; if the analysis results indicate a performance problem, a Prometheus alert is triggered through resource monitoring. Based on the repair suggestions, modify the initial code and repeat the above steps until the final code is generated.

6. The method according to claim 2, characterized in that, The multimodal parsing specifically includes text parsing, speech parsing, and image parsing.

7. The method according to claim 2, characterized in that, The SRS document describes the function, inputs and outputs, key algorithms, dependencies, and usage examples of the code block.

8. A multi-agent code production system, characterized in that, The method for implementing the method of claims 1-7 includes an agent module, an LLM module, and a knowledge base module; The intelligent agent module includes a product requirement intelligent agent module, an architecture intelligent agent module, a code intelligent agent module, and a test and compilation intelligent agent module. The intelligent agent module is used to coordinate the entire process, and each sub-module is responsible for requirement, architecture, code generation, and testing. The LLM module is used to provide understanding, analysis, and decision support, and to assist in code generation optimization; The knowledge base module is used to store and manage resources, supporting code generation and analysis.

9. The system according to claim 8, characterized in that, The product demand intelligent agent module is used to interact with users and generate user demands. The architecture intelligent agent module is used to generate an architecture based on the user requirements generated by the product repair module. The code intelligence module is used to generate preliminary code based on the architecture generated by the architecture intelligence module, call the code resources in the knowledge base module, and combine the LLM module's parsing of user intent. The test compilation agent module is used to call the test code and compilation tools, perform tests and compilation on the preliminary code generated by the code agent module, and generate a test report. If there are errors in the code, it will be regenerated until there are no errors, and then the final code will be output.

10. A multi-agent code production electronic device, characterized in that, The method for implementing the methods of claims 1-7 includes a processor and a memory; The processor is used to execute all computational tasks and implement a multi-agent code production method. The memory is used to store processor-executable instructions and statically stored data.

Citation Information

Patent Citations

  • Navigation process code generation method based on artificial intelligence

    CN118409742A

  • Method and device for assisting in compiling codes, medium and product

    CN119396377A

  • Multi-agent-based automatic code generation method for complex desktop application program

    CN119987734A

  • Generative software automatic assembly method and system based on contract framework model

    CN120122919A

  • Intelligent programming auxiliary method and system based on multi-mode AI language model

    CN120315685A

Cited By

  • Design method of plasma control algorithm based on AI intelligent agent

    CN122261532A