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

By splitting complex tasks into simple tasks and adopting modular design and multi-agent collaboration methods, the problems of inconspicuous complex task generation results in the prior art and insufficient multi-agent collaboration capabilities are solved, and high-quality complex desktop application code generation is achieved.

CN119987734APending Publication Date: 2025-05-13BEIJING UNIV OF TECH
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202510067747.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-16
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

When existing LLM-based proxy systems handle complex tasks, the generated results are often not specific and accurate enough, and the multi-agent collaboration capabilities are insufficient, making it difficult to cope with complex requirements.

Method used

Generate automatic code for complex desktop applications by splitting complex tasks into multiple simple tasks, adopting modular design and multi-agent collaboration approaches. The specific steps include requirements analysis, design, coding and testing stages. Each stage is responsible by multiple AI agents, and detailed requirements documents, design documents and final code files are generated through multiple rounds of dialogue chains.

Benefits of technology

It significantly improves the quality and accuracy of code generation, improves code accuracy, maintainability and compatibility between modules, and can more efficiently meet complex requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119987734A_ABST
    Figure CN119987734A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-agent-based automatic code generation method for a complex desktop application program, which is used for remarkably improving the efficiency of developers in a development stage and reducing the time cost. According to the method, the demand software is split into different modules for implementation, so that the code of the complex desktop application program is automatically generated, and the ever-increasing application development demand is met. According to the method, a multi-agent technology is used, each agent plays roles of demand analysis, code generation, code verification and optimization and the like, and full-process automatic development from original demands to high-quality executable codes is realized through collaborative optimization of demand analysis and code generation processes. Finally, the application potential of a multi-agent system based on a large language model (LLM) in complex code generation is further explored, and a more efficient and intelligent multi-agent code generation system is achieved by improving an agent cooperation mode and cue word engineering.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of automatic code development, and focuses on the research of an automatic code generation method for complex desktop application programs based on multi-agents. Background Art

[0002] In recent years, agent systems or frameworks based on large language models (LLMs) have received extensive attention in building LLM applications. By combing through existing research, related work can be divided into two categories: single-agent systems and multi-agent systems:

[0003] In terms of single-agent systems, AutoGPT is an open-source AI agent designed to autonomously complete a given goal. It adopts a single-agent paradigm and enhances the capabilities of AI models by combining multiple tools, but cannot support collaboration between multiple agents. ChatGPT+ (with code interpreter or plugin) is a conversational AI service that supports code interpreter and plugin functions. The code interpreter allows ChatGPT to execute code, while the plugin further extends its functionality through a series of tools. However, these enhancements are still limited to the single-agent paradigm and lack a mechanism for multi-agent collaboration. LangChain is a general framework for developing LLM-based applications. The LangChainAgents module supports selecting and executing a series of actions through LLM, such as the ReAct agent, which combines reasoning and action capabilities. However, the design of LangChain Agents is essentially still based on a single agent and lacks communication and collaboration capabilities. Even the multi-agent system implemented in LangChain is not based on LangChain Agents, but is developed from scratch, using only the basic modules provided by LangChain. In addition, TransformersAgent is an experimental natural language API implemented based on the Transformers library. It provides a set of curated tools and an agent that can interpret natural language and call these tools. Similar to AutoGPT, it adopts a single-agent paradigm and cannot support collaboration between agents.

[0004] In terms of multi-agent systems, BabyAGI is an example of an AI-driven task management system implemented in Python scripts. In this system, multiple LLM-based agents are assigned different task roles, such as creating new tasks, prioritizing task lists, and completing tasks / subtasks. BabyAGI adopts a static agent dialogue mode, that is, a predefined order of agent communication, and cannot support dynamic dialogue modes or tool use. CAMEL is a communication agent framework that enables autonomous cooperation between agents through role-playing. It implements multi-agent dialogue through Inception-prompting technology and records the dialogue between agents for behavioral analysis. However, CAMEL itself does not support tool use (such as code execution) and only supports static dialogue modes, which cannot flexibly adapt to dynamic task requirements. Recent studies have shown that multi-agent debate is an effective strategy to enhance the divergent thinking ability and factual and reasoning ability of LLM. These studies use debate between agents to solve problems by constructing multiple LLM reasoning instances as agents. However, these agents are only independent LLM reasoning instances, do not support tools or human participation, and the dialogue process must strictly follow a predefined order. In addition, MetaGPT is a dedicated LLM application based on a multi-agent dialogue framework that focuses on automated software development. The framework enables multi-agent collaboration to complete software development tasks by assigning different roles to GPTs (such as architects, programmers, testers, etc.).

[0005] In summary, the existing LLM-based agent systems have different focuses in terms of functions and application scenarios. Single-agent systems usually perform well in simple tasks, but lack multi-agent collaboration capabilities and are difficult to handle complex tasks; and although multi-agent systems have shown potential in task division and collaboration, most are still in the initial exploration stage, with problems such as a single dialogue mode and insufficient tool support. Summary of the invention

[0006] In order to improve the code quality of implementing complex requirements in a multi-agent system, the present invention proposes a method based on a multi-agent system, which effectively improves the code quality by breaking down complex problems into simple problems and using modular design to generate a large system.

[0007] In the process of automatic code generation, an agent system refers to an agent system that acts as an intermediary or representative to perform specific tasks or services. Among them, a single-agent system refers to a system in which only one agent is performing a task or solving a problem, while a multi-agent system involves multiple agents that can work independently or collaboratively to complete a task. In recent years, large language models (LLMs) have brought profound changes to the field of code development because of their ability to integrate a wide range of language knowledge and their powerful role-playing capabilities in specific roles. In automatic code development, using large language models as agents to complete the development of specific tasks has become a mainstream trend. The present invention aims to significantly save the time cost of developers in the development stage by constructing a multi-agent-based code generation system. By splitting the required software into different modules and implementing them separately, the automatic code generation task of complex desktop applications is realized, thereby providing developers with a more convenient and efficient development environment to meet the growing demand for application development.

[0008] When dealing with complex tasks, AI agents often generate results that are not specific and accurate enough due to their own "laziness". "Laziness" means that the results generated by AI agents are often too broad, or too few key points are listed. To solve this problem, this study proposes a strategy to split complex tasks into multiple simple tasks. Through this method, the problem that current AI models tend to ignore specific details when directly dealing with complex tasks is solved, thereby improving the completeness and accuracy of the generated results. Preliminary experiments show that the method of decomposing complex tasks and then generating them step by step can significantly improve the quality of the generated results, making them more detailed and in line with expectations. In the requirements we collected, the process of the entire system involves multiple links such as use case description, use case diagram generation, code file generation (module division), data design generation, interface design generation and code generation. In these links, AI agents may face the above problems. The following is a specific example:

[0009] Taking the requirements of simulating an online mall as an example, if the AI ​​agent is directly asked to generate a specific requirement description, usually only 5 to 6 requirement descriptions will be obtained. However, if the AI ​​agent is first asked to generate a brief requirement description (including only the requirement name and a brief introduction), the AI ​​agent can generate 12 to 13 brief requirement descriptions. Subsequently, the AI ​​agent is asked to generate a specific requirement description based on these brief requirement descriptions, and the result will be 12 to 13 specific requirement descriptions. In this way, we can obtain a more detailed and specific description of system requirements.

[0010] In terms of system module division and programming, the present invention adopts the following method: clarify the data design and interface design of each code file in the design stage, and ensure that these design specifications are strictly followed when writing the code of each module. In this way, the system can maintain consistency when the code is integrated. However, the AI ​​agent may not strictly follow the data design and interface design during the programming process, so it is necessary to check again whether the code meets these design requirements during the testing stage.

[0011] The present invention adopts a modular division of labor research method, splitting complex requirements into different modules according to functions, and having multiple AI agents be responsible for code generation, code review and module testing of each module respectively, and finally integrating the codes of each module into a complete system. Through this phased, division of labor and collaborative approach, the development needs of complex systems can be better handled. Preliminary experimental results show that compared with the method of directly generating the entire system code by a single AI agent, the code generated by the division of labor and collaboration of multiple AI agents has a significant improvement in quality, which is manifested in higher code correctness, maintainability and compatibility between modules.

[0012] To achieve the objectives of the present invention, the proposed technical solutions are summarized as follows:

[0013] The present invention provides a multi-agent-based complex desktop application automatic code generation method, which takes the original requirements of users as input and generates requirement documents, design documents and code files as output.

[0014] The whole method uses OpenAI GPT-4o as the API interface and uses its powerful natural language processing capabilities to achieve multi-agent collaboration. In terms of parameter setting, the temperature value is set to 0.2 to ensure the stability and consistency of the generated content. The role-playing prompts of all agents are configured as shown in Table 1:

[0015] Table 1 Role prompts for different agents

[0016]

[0017]

[0018] The implementation of the system mainly includes the following steps:

[0019] Step 1: Requirements Analysis Phase

[0020] In the requirements analysis phase, the AI ​​agent is required to act as a professional requirements analyst and generate a detailed requirements document based on the original software requirements input by the user. In this phase, the input received by the AI ​​agent is the original software requirements. After multiple rounds of dialogue chains, the final output is a requirements document containing a project overview, functional requirements, non-functional requirements, the technology stack required for system development, use case descriptions, and use case diagrams.

[0021] The original software requirements entered by the user should include the following items:

[0022] Project Background: Explain the background, motivation and reasons for the development of the project.

[0023] Expected goals: Clarify the project's goals and expected outcomes.

[0024] Functional description: Summarize the functional modules and main features that the project needs to have.

[0025] Interface design: describes the interface layout and interaction design of the software.

[0026] Technical implementation: explain the technical selection and implementation methods of the project.

[0027] Platform support: Clarify the operating environment and platforms supported by the project.

[0028] User Group: Describes the target users or audience of the project.

[0029] The requirements document generated by the AI ​​agent should include the following items:

[0030] ①Project Overview:

[0031] The purpose of the project overview is to help subsequent agents understand the original requirements more accurately, thereby improving the accuracy of task execution. In addition, research shows that summarizing the task objectives before executing the task can help reduce the hallucination phenomenon that may occur in large language models. Therefore, by allowing the large language model to generate a project overview based on the original requirements summary, it can have a clearer understanding of the task, thereby effectively reducing potential errors or deviations.

[0032] The project overview generated by the AI ​​agent should follow the following structure:

[0033] Project Background: Describe the origin and background of the project.

[0034] Project objectives: Clarify the core objectives and expected outcomes of the project.

[0035] Project Scope: Define the project boundaries, clarify what is included and what is not included in the project, and avoid scope creep. Through clear scope definition, ensure that subsequent agents have a correct understanding of the requirements.

[0036] Target users: Describe the target user group or audience of the project, clarify the service objects of the project and their demand characteristics, and provide guidance for subsequent design and development.

[0037] ② Functional requirements:

[0038] Functional requirements describe what the system needs to do, that is, the specific functions and behaviors of the system, which usually correspond to the functional description and interface design part of the original requirements, such as the system's functional modules, user interaction methods, etc.

[0039] The core idea of ​​this method is to decompose complex tasks into simple tasks to improve the effect of large language model content generation. Developing code in modules is the concrete practice of this idea. Specifically, modular development decomposes the complex task of overall code development into simple tasks of gradually developing module code. To achieve this process, this method further designs a set of task decomposition processes: clarify functional requirements in the requirements analysis phase, complete module division, data design and interface design according to functional requirements in the design phase, and gradually implement module code in the coding phase. Therefore, the definition of functional requirements not only helps the subsequent agent to develop more efficiently, but also lays the foundation for module division in the design phase.

[0040] Functional requirements generated by the AI ​​agent should follow the following structure:

[0041] Function point name: clarify the name of the function and summarize the core content of the function.

[0042] Detailed functions of a function point: specifically describe the implementation details or sub-functions of the function point.

[0043] ③ Non-functional requirements:

[0044] Non-functional requirements describe how the system can run better, covering performance, quality, constraints and other characteristics, usually corresponding to the platform support and user group parts of the original requirements, and also include performance requirements, security, maintainability, scalability, etc. Its definition is a deconstruction and supplementary explanation of the original requirements, aiming to help subsequent agents carry out development work more efficiently.

[0045] Non-functional requirements generated by the AI ​​agent should follow the following structure:

[0046] Requirement name: Briefly summarize the core content of the non-functional requirement and clarify the theme of the requirement.

[0047] Requirement description: Describe the requirement in detail and clarify the specific requirements or goals that the system needs to meet.

[0048] ④Use case description:

[0049] Use case descriptions have significant advantages for large language models in the programming stage. It clarifies the input, output, and system behavior through the interaction process of specific scenarios, making the information clearer and more specific, thereby helping the large language model to understand functional requirements more accurately. Compared with only using project overviews or functional requirements, use case descriptions can further improve the details and operation processes of the software, especially in functions that need to handle user interactions or multi-step logic. Use case descriptions can clearly define the behavior of each step, helping large language models understand complex requirements and software processes. This detailed description not only enables the large language model to have a deeper understanding of functional requirements, but also better guides the implementation of software in the coding stage, improving the accuracy and practicality of the code.

[0050] The use case description generated by the AI ​​agent should follow the following structure:

[0051] Use Case Name: Each use case has a name.

[0052] Abstract: A brief description of the use case, usually one to two sentences.

[0053] Dependencies: This optional section describes whether the use case depends on other use cases, i.e. whether it contains or extends another use case.

[0054] Actors: This section lists the actors in the use case. There is always a primary actor who initiates the use case. Additionally, there may be other actors who also participate in the use case.

[0055] Precondition: One or more conditions that must be true at the start of a use case, from the perspective of that use case.

[0056] Main sequence description: The main part of the use case is a narrative description of the main sequence of the use case, which is the most common interaction sequence between the actor and the system. The description is in the form of the actor's input, followed by the system's response.

[0057] Alternative sequence description: A narrative description of alternative branches off the main sequence. The main sequence may have several alternative branches. The steps in the use case where the alternative sequences branch off the main sequence are identified, along with a description of the alternative.

[0058] Non-functional requirements: A narrative description of non-functional requirements, such as performance and security requirements.

[0059] Postcondition: A condition that is always true (from the perspective of that use case) at the end of the use case if the primary sequence is followed.

[0060] ⑤Use case diagram:

[0061] The use case diagram intuitively shows the functional scope of the system and the interaction between the user and the system, providing a clear reference for subsequent design, coding and testing, and helping to deepen the understanding of requirements. In addition, the use case diagram can also help users to intuitively evaluate the quality of the requirements document generated by the large language model to a certain extent, and judge its rationality and completeness.

[0062] ⑥Technology stack required for system development:

[0063] The technology stack required for system development corresponds to the technical implementation part of the original requirements. In the requirements stage, it is crucial to clarify the technology stack required for system development. This not only provides a unified technical foundation for subsequent development, but also avoids the situation where different modules use different technologies due to inconsistent technology stacks during the coding stage. This method adopts a modular development approach during the coding stage, and each agent is responsible for the coding of a module. Therefore, the uniformity of the technology stack is particularly important to ensure the consistency and maintainability of the entire system.

[0064] Step 1.1: Generate system overview, functional requirements, non-functional requirements, and technology stack required for system development

[0065] The prompt words for this stage are:

[0066]

[0067]

[0068] The input of this stage is the original user requirements, and the output is the system overview, functional requirements, non-functional requirements, and the technology stack required for system development in the requirements document.

[0069] Step 1.2: Generate a simplified use case description

[0070] Research shows that when large language models are directly used to generate use case descriptions, the generated results are often too broad, for example, 12 use case descriptions should be generated.

[0071] There are errors, most of which are concentrated in the use case relationships. However, if the large language model is used to generate the use case relationships first, and then the use case diagram is drawn based on the generated use case relationships, the error rate of the use case relationships in the use case diagram can be significantly reduced.

[0072] The prompt words for this stage are:

[0073]

[0074] The input of this stage is the context of the previous tasks in the requirements stage (i.e. the conversation record and generated results of step 1.1, hereinafter referred to as "memory"), and the output is a simplified version of the use case description.

[0075] Step 1.3: Generate a detailed use case description

[0076] The prompt words for this stage are:

[0077]

[0078] The input to this phase is the memory of the previous tasks in the requirements phase (i.e., steps 1.1 and 1.2), and the output is a detailed use case description.

[0079] Step 1.4: Generate Use Case Relationships

[0080] Research shows that when a large language model is directly used to generate a use case diagram, the generated results often contain errors, and these errors are mostly concentrated in the use case relationship. However, if a large language model is used to generate the use case relationship first, and then a use case diagram is drawn based on the generated use case relationship, the error rate of the use case relationship in the use case diagram can be significantly reduced.

[0081] Based on the above analysis, the prompt words for this step are designed as follows:

[0082]

[0083] The input of this phase is the memory of the previous tasks in the requirements phase, and the output is the use case relationship.

[0084] Step 1.5: Generate a use case diagram

[0085] The prompt words for this stage are:

[0086]

[0087] The input of this phase is the memory of the previous tasks in the requirements phase, and the output is the use case diagram.

[0088] Step 1.6: Integrate and generate a complete requirements document

[0089] The prompt words for this stage are:

[0090]

[0091]

[0092] The input to this phase is the memory of the previous tasks in the requirements phase, and the output is a complete requirements document.

[0093] Step 2: Design Phase

[0094] In the design phase, the AI ​​agent will act as a professional architect and generate a design document based on the original requirements input by the user and the requirements document generated by the AI ​​agent in the requirements phase. The document first determines the overall architecture of the system, then lists the code files that the system should include, and divides the system into different modules according to function, explaining the module to which each code file belongs. Finally, the design document also includes database design (if the system requires a database) and data design and interface design in each code file. Among them, the database design requires type, naming, precision, field description, table description and other content; the interface design should include class name (if necessary), interface function name, specific parameters, return value and possible error handling. At this stage, the input received by the AI ​​agent is the original requirements and requirements document, and the output is a design document.

[0095] In the design phase, this method extracts the user's original requirements and the final generated complete requirements document from the agent dialogue in the requirements phase and integrates them into a new memory (context). The AI ​​agent in the design phase will start working in this new context dialogue.

[0096] Step 2.1: Generate a list of code files and the functions each file is responsible for implementing

[0097] The prompt words for this stage are:

[0098]

[0099] The input of this stage is the user's original requirements and the complete requirements document generated in the requirements phase. The output is the overall architecture of the system, a list of code files, and the functions that each file is responsible for implementing.

[0100] Step 2.2: Divide into modules

[0101] The prompt words for this stage are:

[0102]

[0103]

[0104] The input to this phase is the memory of the previous tasks in the design phase, and the output is the modules and what code files are contained within them.

[0105] Step 2.3: Data design, interface design and database design

[0106] The prompt words for this stage are:

[0107]

[0108] The input of this stage is the memory of the previous tasks in the design phase, and the output is data design, interface design and database design.

[0109] Step 2.4: Check data design, interface design and database design

[0110] Research shows that large language models often encounter the following two problems when generating data design and interface design: First, for the design of composite data types, the specific fields within the data are often not clearly given; second, the generated parameters sometimes lack clarity (for example, vague descriptions may appear in the parameters, such as "user input"). For these two types of high-frequency problems, it is necessary to check and correct them after the design agent completes the data design, interface design, and database design to ensure the integrity and accuracy of the design. This is crucial for subsequent modular programming.

[0111] Based on the above analysis, the prompt words for this step are designed as follows:

[0112]

[0113] The input of this stage is the memory of the previous tasks in the design phase, and the output is the revised data design, interface design and database design.

[0114] Step 2.5: Integrate and generate complete design documentation

[0115] The prompt words for this stage are:

[0116]

[0117]

[0118] The input to this phase is the memory of the previous tasks in the requirements phase, and the output is a complete requirements document.

[0119] Step 3: Coding Phase

[0120] In the coding phase, multiple AI agents will play the role of professional programmers, and each module will be assigned an AI agent to generate the corresponding code. The prompts clearly remind the AI ​​agent to avoid common mistakes, such as incomplete code generation or missing necessary package imports. In this phase, the input received by the AI ​​agent is the original requirements, requirements documents and design documents, and the output is code.

[0121] In the encoding phase, this method extracts the user's original requirements, complete requirements documents, and complete design documents from the agent dialogues in the requirements phase and the design phase and integrates them into a new memory (context). The AI ​​agent in the encoding phase will start working in this new context dialogue.

[0122] Step 3.1: Write the code for each module

[0123] When writing code for a large language model, some common errors may occur, such as only generating part of the code file, or using placeholders to replace the specific implementation code in the method. In addition, since this method uses the module-by-module code generation method, it is particularly important to ensure that the code generated by each module strictly complies with the design document. Therefore, it is necessary to remind the programming agent to avoid the above errors in the prompt words to ensure the completeness and accuracy of the code generation.

[0124] Based on the above analysis, the prompt words for this step are designed as follows:

[0125]

[0126] The input of this stage is the user's original requirements, the complete requirements document generated in the requirements analysis phase, and the complete design document generated in the design phase. The output is the implementation code of each module.

[0127] Step 3.2: Unit test each module

[0128] The code generated by a large language model is often not 100% correct in the initial stage and may contain some errors. In particular, large language models are prone to making some specific common errors when generating code. In addition, because this method uses module-based code generation, whether the code generated by each module strictly complies with the design document is a very important issue. Therefore, introducing a review agent in the code generation process to review the generated code can effectively discover and correct these problems. In addition, studies have shown that the code generated by large language models often has a higher probability of certain specific types of errors. If these specific error types are clearly informed to the review agent, the effectiveness and efficiency of its review can be significantly improved. In addition, the study also found that when specific suggestions are provided (such as detailed modification plans), programming agents are more inclined to accept suggestions and modify the code than when only general or non-specific suggestions are provided.

[0129] Based on the above analysis, the prompt words for this step are designed as follows:

[0130]

[0131]

[0132] The input of this stage is the user's original requirements, the complete requirements document generated in the requirements analysis phase, the complete design document generated in the design phase and the implementation code of each module. The output is a review suggestion.

[0133] Step 3.3: Modify the implemented module code

[0134] Research shows that the review results generated by the review agent are not always correct. Although sometimes the programming agent will regenerate the original answer intact when faced with an incorrect review result. However, in order to reduce costs and improve the correctness of code generation, the programming agent should first judge the correctness of the review result when receiving it.

[0135] Based on the above analysis, the prompt words for this step are designed as follows:

[0136]

[0137] The input of this phase is the results of the conversation and code review in step 3.1, and the output is the modified code.

[0138] In order to strike a balance between cost and effect, the unit code review (i.e., steps 3.2 and 3.3) is set to be performed three rounds to ensure the reliability of the results.

[0139] Step 4: Testing Phase

[0140] During the testing phase, the AI ​​agent will act as a professional tester and undertake two main tasks. First, a code review will be conducted to check if there are any errors or missing requirements in the code. It should be noted that in the experiment, the errors and solutions proposed by the AI ​​agent in the code review phase are not always accurate. Therefore, when providing feedback to the programming AI agent, it is necessary to let it first judge the correctness of the feedback. If the feedback is correct, it will be modified according to the suggestions. In addition, the feedback proposed by the AI ​​agent in the code review phase may not be accepted by the programming AI agent. In order to increase the probability of feedback being adopted, the AI ​​agent in the code review should clearly point out the specific errors and provide detailed modification plans. Subsequently, dynamic testing will be carried out, and the system will execute the program locally. If there is a problem, the error information will be fed back to the programming agent so that it can make corresponding modifications.

[0141] This method extracts the user's original requirements, complete requirements documents, complete design documents, and the codes of each module from the agent dialogues in the requirements stage, design stage, and coding stage and integrates them into a new memory (context). The AI ​​agent in the coding stage will start working in this new context dialogue. First, perform a code review to check whether there are errors or missing requirements in the code. The specific details of the code review are basically the same as steps 3.2 and 3.3, except that the code being reviewed has changed from module code to system code.

[0142] Then, dynamic testing is performed, where the system executes the program locally. If any problems occur, the error information is fed back to the programming agent so that it can make corresponding modifications. The specific details of code testing are basically the same as code review.

[0143] Compared with the prior art, the present invention has the following obvious advantages and beneficial effects:

[0144] First, compared with the previous multi-agent-based automatic code development method, the present invention proposes a modular generation and integration method for code generation for complex requirements. This method enables the multi-agent system to generate high-quality software when faced with complex requirements. Secondly, the multi-agent system of the present invention is constructed based on the principles of software engineering, which ensures the systematicness and standardization of the code generation process, thereby facilitating subsequent code maintenance and expansion. In summary, the method of the present invention performs well in achieving code generation for complex requirements and significantly improves the effect of code generation.

[0145] Experiments have shown that in the code generation task of complex requirements, the code generation method proposed in the present invention has significant advantages in terms of the number of generated code files, the total number of code lines, the implemented functional points and executability. This method can not only quickly realize the conversion from requirements to codes, thereby effectively saving labor costs, but also better meet the code generation of complex requirements, and has broad application prospects and promotion value. BRIEF DESCRIPTION OF THE DRAWINGS

[0146] Figure 1 The multi-agent system structure of the present invention. DETAILED DESCRIPTION

[0147] The present invention proposes a multi-agent-based automatic code generation method for complex desktop applications, which can generate code files through original requirements and multiple rounds of dialogue chains.

[0148] The following is a detailed description of the multi-agent based complex desktop application automatic code generation method proposed by the present invention in conjunction with a specific implementation. For ease of explanation, a relatively simple original requirement is used as an example.

[0149] Original requirements:

[0150] The Bilingual Reader app is a tool developed based on PyQT5 and Python. It is designed to display English and Chinese text side by side in a vertically split dual-screen layout, with English on the left and Chinese translation on the right. The text is not editable. Users can import .txt files in English or Chinese through the menu bar. The app only supports this format and prompts users to specify the file type. The interface supports adjusting the font size and the position of the dividing line so that users can adjust the size of the text area to optimize the reading experience. All interface instructions and labels are in Chinese, and the design is bright and visually appealing. The application has error handling functions and pops up error message boxes when the file format is not supported or the translation is missing. No user authentication or complex operations are required. It is simple and intuitive, efficient, and does not require special security measures or subsequent maintenance, suitable for users to use quickly.

[0151] Step 1: Requirements Analysis Phase

[0152] The whole method uses OpenAI GPT-4o as the API interface. In terms of parameter setting, the temperature value is set to 0.2. In the demand analysis phase, the role prompt words of the agent are set to the prompt words of the demand analysis phase in Table 1.

[0153] Step 1.1: Generate system overview, functional requirements, non-functional requirements, and technology stack required for system development

[0154] This step takes the original requirements and the prompt words of this step in the invention content as input, and outputs the system overview, functional requirements, non-functional requirements and the technology stack required for system development in the requirements document.

[0155] Step 1.2: Generate a simplified use case description

[0156] The input of this step is the memory of the previous requirement analysis phase, and the output is a simplified use case description. The following is a specific example:

[0157]

[0158] Step 1.3: Generate a detailed use case description

[0159] The input of this step is the memory of the previous requirement analysis phase, and the output is a detailed use case description. The following is a specific example:

[0160]

[0161]

[0162] Step 1.4: Generate Use Case Relationships

[0163] The input of this step is the memory of the previous requirement analysis phase, and the output is the relationship between use cases.

[0164] Step 1.5: Generate a use case diagram

[0165] The input of this step is the memory of the previous requirement analysis phase, and the output is a use case diagram described in the PlantUML language.

[0166] Step 1.6: Integrate and generate a complete requirements document

[0167] The input of this step is the memory of the previous requirements analysis phase, and the output is a complete requirements document.

[0168] Step 2: Design Phase

[0169] In the design phase, the role prompts of the agent are set to the prompts of the design phase in Table 1.

[0170] Step 2.1: Generate a list of code files and the functions each file is responsible for implementing

[0171] The input of this step is the original requirements and the complete requirements document generated in the requirements analysis phase. The output is a list of files and the functions that each file is responsible for implementing. The following is a specific example:

[0172]

[0173] Step 2.2: Divide into modules

[0174] The input of this step is the memory of the previous design phase, and the output is the result of module division. The following is a specific example:

[0175]

[0176] Step 2.3: Data design, interface design and database design

[0177] The input of this step is the memory of the previous design phase, and the output is data design, interface design and database design. The following is a specific example:

[0178]

[0179] Step 2.4: Check data design, interface design and database design

[0180] The input of this step is the memory of the previous design phase, and the output is the modified data design, interface design and database design.

[0181] Step 2.5: Integrate and generate complete design documentation

[0182] The input of this step is the memory of the previous design stage, and the output is a complete design document.

[0183] Step 3: Coding Phase

[0184] In the encoding phase, the agent's role cue words were set to the encoding phase cue words in Table 1.

[0185] Step 3.1: Write the code for each module

[0186] The input of this step is the original requirements, the complete requirements document generated in the requirements analysis phase, and the complete design document generated in the design phase. The output is the code for each module.

[0187] Step 3.2: Unit test each module

[0188] The input of this step is the memory of the previous encoding stage, and the output is specific modification suggestions.

[0189] Step 3.3: Modify the implemented module code

[0190] The input of this step is the memory from the previous encoding stage, and the output is the modified code.

[0191] Step 4: Testing Phase

[0192] In the test phase, the agent's role prompt words are set to the prompt words of the test phase in Table 1.

[0193] The input of this step is the original requirements, the complete requirements document generated in the requirements analysis phase, the complete design document generated in the design phase, and the code of each module. The output is the code of the entire system after modification.

[0194] The series of detailed descriptions listed above are only specific descriptions of feasible implementation schemes of the present invention. They are not used to limit the scope of protection of the present invention. All equivalent implementation schemes or changes that do not deviate from the spirit of the invention should be included in the scope of protection of the present invention.

Claims

1. A multi-agent-based automatic code generation method for complex desktop applications, characterized in that: This method takes the user's original requirements as input and generates requirement documents, design documents, and code files as output; The whole method uses OpenAI GPT-4o as the API interface. In terms of parameter setting, the temperature value is set to 0.2; The following steps are involved: Step 1: Requirements Analysis Phase In the requirements analysis phase, the AI ​​agent is required to act as a professional requirements analyst and generate a detailed requirements document based on the original software requirements input by the user. In this phase, the input received by the AI ​​agent is the original software requirements. After multiple rounds of dialogue chains, the final output is a requirements document that includes a project overview, functional requirements, non-functional requirements, the technology stack required for system development, use case descriptions, and use case diagrams. Step 2: Design Phase In the design phase, the AI ​​agent will act as a professional architecture designer and generate a design document based on the original requirements input by the user and the requirements document generated by the AI ​​agent in the requirements phase. The design document first determines the overall architecture of the system, then lists the code files that the system should include, and divides the system into different modules according to function, explaining the module to which each code file belongs. Finally, the design document also includes database design and data design and interface design in each code file. Among them, database design requires type, naming, precision, field description, and table description. Interface design includes class name, interface function name, specific parameters, return value, and possible error handling. In this phase, the input received by the AI ​​agent is the original requirements and requirements document, and the output is a design document. Step 3: Coding Phase In the coding phase, multiple AI agents will play the role of professional programmers, and each module will be assigned an AI agent to generate the corresponding code. The prompts clearly remind the AI ​​agents to avoid mistakes. In this phase, the input received by the AI ​​agent is the original requirements, requirement documents and design documents, and the output is code. In the coding phase, the user's original requirements, complete requirements documents, and complete design documents are extracted from the agent dialogues in the requirements phase and the design phase and integrated into a new memory. The AI ​​agent in the coding phase will start working in this new context dialogue. Step 4: Testing Phase During the testing phase, the AI ​​agent will act as a professional tester and undertake two tasks. First, it will conduct code review to check whether there are errors or missing requirements in the code. It should be noted that in the experiment, the errors and solutions proposed by the AI ​​agent in the code review phase are not always accurate. When providing feedback to the programming AI agent, it is necessary to first determine the correctness of the feedback. If the feedback is correct, it will be modified according to the suggestions. The feedback proposed by the AI ​​agent in the code review phase may not be accepted by the programming AI agent. In order to increase the probability of feedback being adopted, the AI ​​agent in code review should clearly point out the specific errors and provide detailed modification plans. Subsequently, dynamic testing is carried out to execute the program locally. If a problem occurs, the error information will be fed back to the programming agent so that it can make corresponding modifications.

2. The method for automatic code generation of complex desktop applications based on multi-agents according to claim 1 is characterized in that: In step 1, the original software requirements entered by the user should include the following items: Project background: explain the background, motivation and reasons for the development of the project; Expected goals: clarify the project's goals and expected outcomes; Functional description: outline the functional modules and main features that the project needs to have; Interface design: describes the software’s interface layout and interaction design; Technical implementation: explain the technical selection and implementation methods of the project; Platform support: clarify the operating environment and platforms supported by the project; User Group: Describes the target users or audience of the project; The requirements document generated by the AI ​​agent contains the following items: ①Project Overview: The project overview generated by the AI ​​agent follows the following structure: Project Background: Describe the origin and background of the project; Project objectives: clarify the core objectives and expected outcomes of the project; Project scope: Define the project boundaries, clarify what is included and what is not included in the project, and avoid scope creep; through clear scope definition, ensure that subsequent agents have a correct understanding of the requirements; Target users: describe the target user group or audience of the project, clarify the service objects of the project and their demand characteristics, and provide guidance for subsequent design and development; ② Functional requirements: Decompose complex tasks into simple tasks to improve the effect of large language model content generation; modular development decomposes the complex task of overall code development into simple tasks of gradually developing module codes; design a set of task decomposition processes: clarify functional requirements in the demand analysis phase, complete module division, data design and interface design according to functional requirements in the design phase, and gradually implement module codes in the coding phase; The functional requirements generated by the AI ​​agent follow the following structure: Function point name: clarify the name of the function and summarize the core content of the function; Detailed functions of the function point: specifically describe the implementation details or sub-functions of the function point; ③ Non-functional requirements: The non-functional requirements description covers performance, quality, constraints and other characteristics, corresponding to the platform support and user group parts in the original requirements, and also includes performance requirements, security, maintainability, and scalability; Non-functional requirements generated by the AI ​​agent should follow the following structure: Requirement name: briefly summarize the core content of the non-functional requirement and clarify the theme of the requirement; Requirement description: Describe the requirements in detail and clarify the specific requirements or goals that the system needs to meet; ④Use case description: Use case descriptions have significant advantages over large language models in the programming phase, through the interaction process of specific scenarios; The use case description generated by the AI ​​agent should follow the following structure: Use case name: Each use case has a name; Abstract: A brief description of the use case, usually one to two sentences. Dependencies: This optional section describes whether the use case depends on other use cases, i.e., whether it includes or extends another use case; Actors: This section lists the actors in the use case; there is always a primary actor who initiates the use case; in addition, there may be other actors who also participate in the use case; Precondition: One or more conditions that must be true at the start of a use case, from the perspective of that use case; Main sequence description: The main part of the use case is a narrative description of the main sequence of the use case, which is the most common sequence of interactions between the actor and the system; the description is in the form of the actor's input, followed by the system's response; Alternative sequence description: A narrative description of alternative branches off the main sequence; the main sequence may have several alternative branches; the steps in the use case where the alternative sequences branch off the main sequence are identified, along with the alternative descriptions; Non-functional requirements: A narrative description of non-functional requirements; Postcondition: A condition that is always true at the end of the use case if the main sequence is followed; ⑤Use case diagram: Use case diagrams intuitively display the functional scope of the system and the interaction between users and the system, providing a clear reference for subsequent design, coding, and testing agents, helping to deepen the understanding of requirements; In addition, the use case diagram can also help users to intuitively evaluate the quality of the requirements document generated by the large language model to a certain extent, and judge its rationality and completeness; ⑥Technology stack required for system development: The technology stack required for system development corresponds to the technical implementation part of the original requirements. In the requirements stage, it is very important to clarify the technology stack required for system development. This not only provides a unified technical foundation for subsequent development, but also avoids the situation in which different modules use different technologies due to inconsistent technology stacks in the coding stage. This method adopts modular development in the coding stage, and each agent is responsible for the coding of one module. Step 1.1: Generate system overview, functional requirements, non-functional requirements, and technology stack required for system development; The prompt words for this stage are: The input of this stage is the original user requirements, and the output is the system overview, functional requirements, non-functional requirements, and the technology stack required for system development in the requirements document; Step 1.2: Generate a simplified use case description; The prompt words for this stage are: The input of this phase is the context of the previous tasks in the requirements phase (i.e. the conversation record and generated results of step 1.1, hereinafter referred to as "memory"), and the output is a simplified version of the use case description; Step 1.3: Generate a detailed use case description; The prompt words for this stage are: The input of this phase is the memory of the previous tasks in the requirements phase, i.e., steps 1.1 and 1.2, and the output is a detailed use case description; Step 1.4: Generate use case relationships; The prompt words for this step are designed as follows: The input of this phase is the memory of the previous tasks in the requirements phase, and the output is the use case relationship; Step 1.5: Generate a use case diagram; The prompt words for this stage are: The input to this phase is the memory of the previous tasks in the requirements phase, and the output is the use case diagram; Step 1.6: Integrate and generate a complete requirements document The prompt words for this stage are: The input to this phase is the memory of the previous tasks in the requirements phase, and the output is a complete requirements document.

3. The method for automatic code generation of complex desktop applications based on multi-agents according to claim 2 is characterized in that: In step 2, in the design phase, this method extracts the user's original requirements and the final generated complete requirements document from the agent dialogue in the requirements phase and integrates them into a new memory. The AI ​​agent in the design phase will start working in this new context dialogue; Step 2.1: Generate a list of code files and the functions each file is responsible for implementing The prompt words for this stage are: The input of this stage is the user's original requirements and the complete requirements document generated in the requirements stage. The output is the overall architecture of the system, a list of code files, and the functions that each file is responsible for implementing. Step 2.2: Divide into modules The prompt words for this stage are: The input to this phase is the memory of the previous tasks in the design phase, and the output is the modules and what code files are contained within them; Step 2.3: Data design, interface design and database design The prompt words for this stage are: The input of this phase is the memory of the previous tasks in the design phase, and the output is data design, interface design, and database design; Step 2.4: Check data design, interface design and database design The prompt words are designed as follows: The input of this phase is the memory of the previous tasks in the design phase, and the output is the revised data design, interface design and database design; Step 2.5: Integrate and generate complete design documentation The prompt words for this stage are: The input to this phase is the memory of the previous tasks in the requirements phase, and the output is a complete requirements document.

4. The method for automatic code generation of complex desktop applications based on multi-agents according to claim 3 is characterized in that: In Step 3, Step 3.1: Write the code for each module The prompt words for this step are designed as follows: The input of this stage is the original user requirements, the complete requirements document generated in the requirements analysis phase, and the complete design document generated in the design phase. The output is the implementation code of each module. Step 3.2: Unit test each module The prompt words for this step are designed as follows: The input of this stage is the original user requirements, the complete requirements document generated in the requirements analysis phase, the complete design document generated in the design phase and the implementation code of each module. The output is a review suggestion. Step 3.3: Modify the implemented module code The prompt words for this step are designed as follows: The input of this phase is the results of the conversation and code review in step 3.1, and the output is the modified code; In order to strike a balance between cost and effect, the unit code review, i.e., steps 3.2 and 3.3, is set to be performed three rounds to ensure the reliability of the results.

5. The method for automatic code generation of complex desktop applications based on multi-agents according to claim 4 is characterized in that: In step 4, this method extracts the user's original requirements, complete requirements documents, complete design documents, and codes of each module from the agent dialogues in the requirements stage, design stage, and coding stage and integrates them into a new memory. The AI ​​agent in the coding stage will start working in this new context dialogue. First, code review is performed to check whether there are errors or missing requirements in the code. The specific details of the code review are the same as steps 3.2 and 3.3, except that the code being reviewed is changed from module code to system code. Subsequently, dynamic testing is performed, and the system will execute the program locally. If any problems occur, the error information will be fed back to the programming agent so that it can make corresponding modifications. The specific details of code testing are basically the same as code review.

Citation Information

Cited By

  • Multi-agent code production method and system and electronic equipment

    CN120994180A

  • Multi-agent large model code generation method and system in optical field

    CN121143812A

  • Intelligent WinForm interface generation method and system based on state collaboration and multi-mode perception

    CN121326322A