Method and system for realizing automatic code generation by using multiple AI Agents
Through collaborative work between multiple AI agents, automatic code generation is achieved, the limitations of existing AI models in complex software development are solved, code quality and efficiency are improved, and code is further optimized through a continuous feedback mechanism.
Patent Information
- Application Number
- CN202510346038.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-04-22
AI Technical Summary
Existing AI models have limitations in software automation development, it is difficult to complete complex software development tasks, and lacks effective supervision capabilities to deal with non-functional needs such as security, performance optimization, and maintainability.
Through collaborative work between multiple AI Agents, automatic code generation is achieved. The specific steps include initializing the system, testing driver agent receiving tasks and generating task numbers and code declarations, code generation agent generating or updating code according to task descriptions, and conducting unit tests, continuous integration agent performing integration verification and regression testing, and continuous deployment of agents for functional testing, performance testing and security testing.
The full-process operation automation is realized, replacing the manual configuration integration tool chain, avoiding permission control issues and code branch conflicts, improving code quality and efficiency, and guiding code corrections through a continuous feedback mechanism, further improving code quality.
Smart Images

Figure CN119861916A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electronic digital data processing, and in particular to a method and system for realizing automatic code generation using multiple AI Agents. Background Art
[0002] Current AI models perform well when dealing with clear and structured requirements, such as generating code for CRUD operations. However, there are still many challenges in the process of software automation development. First, existing AI models are good at local code generation, but have obvious deficiencies in global architecture design, and the existing AI models used for code generation are single and difficult to complete complex software development tasks. Second, for non-functional requirements, such as implicit requirements such as security, performance optimization, and maintainability, AI models lack effective supervision capabilities. Therefore, the existing AI programming methods mainly adopt the human-computer collaboration mode, using AI as an efficiency tool rather than completely replacing developers. However, this human-computer collaboration mode has some limitations: the tool chain needs to be manually configured and integrated, and there are permission control issues between the pipeline execution nodes of the tool chain. Excessive permissions may be exploited by attackers, bringing security risks; the tool chain is prone to code branch conflicts during team collaboration, resulting in problems such as poor code coverage and low performance, affecting development efficiency and code quality. Summary of the invention
[0003] The purpose of the present invention is to provide a method and system for realizing automatic code generation using multiple AI Agents, which aims to overcome the problems existing in the prior art.
[0004] To achieve the purpose, the present invention provides the following technical solutions: A method for realizing automatic code generation using multiple AI agents, wherein the method is realized by dialogue between AI agents, and specifically comprises the following steps: Step (1), initializing the system and instantiating the test driver agent, code generation agent, continuous integration agent, and continuous deployment agent; Step (2), the test driver agent receives the task delivered by the previous node and generates the task number, task description, test data, unit test script and code declaration for the task; Step (3), the code generation agent generates or updates the code according to the received task description and code declaration; performs unit testing on the code; if an error is reported or the code does not comply with the code specification, the code is automatically repaired according to the error information; if the test passes, the task number and code are passed to the continuous integration agent; Step (4): The continuous integration agent passes the current task number to the test drive agent, and the test drive agent returns the integration test script and test data according to the task number; the continuous integration agent performs integration verification and regression testing; if an error is reported, the error result is analyzed. If it is a code error, it is fed back to the code generation agent for repair, and steps (3) and (4) are repeated; if it is a problem with the continuous integration agent test environment, the environment configuration is optimized, and the integration verification and regression testing are repeated until the verification is successful; the current task number and the latest code are passed to the continuous deployment agent; Step (5): The continuous deployment agent passes the current task number to the test drive agent, and the test drive agent returns the functional test, performance test scripts and test data according to the task number; the continuous deployment agent accesses the performance test environment and the customer acceptance environment, and then performs continuous delivery and deployment.
[0005] Furthermore, the previous node is a document library or a task decomposition agent, the document library is used to store data required for project development, and the task decomposition agent is used to call the data, perform task decomposition on the data, and output at least one task; The test driving agent receives the task delivered by the previous node, specifically: receives the data delivered by the document library and takes it as the task, or receives at least one task delivered by the task decomposition agent.
[0006] Furthermore, the task decomposition agent outputs multiple tasks in the form of a task list; in the above step (2), the test drive agent reasonably sorts the tasks in the task list and generates task numbers; the test drive agent then outputs the task descriptions and code declarations corresponding to the task numbers to the code generation agent in sequence.
[0007] Furthermore, in the above step (3), the code generation agent checks the compilation environment, and if the compilation environment corresponding to the code is missing, it builds an internal compilation environment according to the code type.
[0008] Furthermore, in the above step (4), the continuous integration agent checks the integration test environment. If the integration test environment for executing the integration test script is missing, an internal or external integration test environment is generated based on the analysis of the integration test script, and then integration verification and regression testing are performed.
[0009] Furthermore, the above step (5) also includes, if there is abnormal data, analyzing the abnormal data, and if it is a problem with the continuous deployment agent test environment, optimizing the environment configuration and repeating the test until the verification is successful; if it is due to insufficient performance, feeding back the performance data to the code generation agent to update the optimized code, and repeating steps (3), (4) and (5); if successful, the continuous deployment agent notifies the code generation agent and the test drive agent that the process ends.
[0010] Furthermore, in the above step (5), at the end of the process, the code generation agent saves the code of the corresponding task to the code library, the test driver agent saves the test data and unit test script of the corresponding task to the test case library, and the code declaration to the document library.
[0011] Furthermore, it also includes a dynamic monitoring module that captures the execution context of each AI agent in real time, generates serialized snapshots, and performs heartbeat detection, timeout determination and / or resource occupancy monitoring on each AI agent; when the heartbeat detection, timeout determination and / or resource occupancy exceeds the corresponding threshold, a termination mechanism is triggered; then a new agent instance is generated, and the most recent valid snapshot is loaded to continue executing the method from the termination node.
[0012] Furthermore, in the above step (2), the code declaration includes the naming and definition of packages, classes, methods, variables, and the accuracy of data design.
[0013] The present invention also discloses a system for realizing automatic code generation using multiple AI Agents, the system is used to realize any of the above methods, and comprises: The test driver agent is used to receive the task delivered by the previous node and generate the task number, task description, test data, unit test script and code declaration of the task; A code generation agent, used to generate or update code according to the received task description and code declaration; Continuous integration agent, which performs integration verification and regression testing on the code and provides feedback to the code generation agent; The continuous deployment agent is used for functional testing, performance testing, and security testing, and provides feedback to the code generation agent; it is also used for continuous delivery and deployment.
[0014] Furthermore, it also includes: The task decomposition agent is used to call the data required for project development, decompose the data into tasks, and output at least one task; The dynamic monitoring module is used to capture the execution context of each AI agent in real time, generate serialized snapshots, and perform heartbeat detection, timeout determination and / or resource occupancy monitoring on each AI agent; it is also used to trigger the termination mechanism when the heartbeat detection, timeout determination and / or resource occupancy exceed the corresponding thresholds.
[0015] Compared with the prior art, the present invention has the following beneficial effects: The present invention solves the problem that a single large model cannot complete complex software development tasks by having multiple AI Agents communicate with each other and work together. The present invention can realize full-process operation automation, replacing the original manual configuration and integration tool chain; in the automated closed loop, it avoids authority control issues and code branch conflicts caused by teamwork, and can improve the quality and efficiency of generated code. At the same time, the present invention uses a continuous feedback mechanism to guide code correction, further improving the quality of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a system principle block diagram of the present invention, which uses multiple AI Agents to realize automatic code generation. DETAILED DESCRIPTION
[0017] The specific implementation of the present invention is described below with reference to the accompanying drawings. In order to fully understand the present invention, many details are described below, but for those skilled in the art, the present invention can be implemented without these details.
[0018] It should be noted that the AI Agent mentioned in this application refers to an AI agent (intelligent body), which at least includes the following parts: perceiving the environment, analyzing information, making decisions and executing actions to achieve specific goals.
[0019] Among them, sensing the environment may involve data input and processing multimodal information. Perception, analysis, and decision-making may need to rely on large models, which can be freely selected to process natural language (such as understanding instructions, feedback information), reasoning, planning, knowledge base, or multimodal input (such as images, text, audio and video). The execution part is responsible for converting decisions into specific actions, such as generating responses, operating tools, etc.
[0020] The MCP protocol is required in the process of code generation agent (gc_agent), continuous integration agent (ci_agent) and continuous deployment agent (cd_agent) operating virtual machines and code generation agent (gc_agent) and test drive agent (td_agent) operating storage. Among them, the MCP protocol is the Anthropic open source Model Context Protocol protocol. The core value of MCP is to provide a standardized interface to connect AI Agent with external resources and tools.
[0021] like Figure 1As shown in the figure, a method for realizing automatic code generation using multiple AI Agents is realized by dialogue between AI Agents (AIAgent). Among them, dialogue refers to a relatively abstract and high-level interaction method, which emphasizes that AI agents communicate and collaborate with each other through natural language or specific interaction protocols like human dialogue, and pays more attention to semantic understanding, generation and dialogue logic processing. The method specifically includes the following steps: Step (1): Initialize the system and instantiate the task decomposition agent (wbs_agent), test driver agent (td_agent), code generation agent (gc_agent), continuous integration agent (ci_agent), and continuous deployment agent (cd_agent); Step (2): Prepare the information required for project development and store it in the document library.
[0022] The data can be single-modal or multi-modal. Multi-modal data includes but is not limited to: 1. Requirement specification; 2. Prototype, renderings and related description text; 3. Test data set; 4. Code base (including project prototype); 5. Video, audio; 6. Acceptance document. The preparation of these materials provides the necessary information and basis for the automatic code generation of multiple AI agents, laying a solid foundation for subsequent code generation, ensuring that the generated code can meet project requirements and improve the efficiency and quality of code generation.
[0023] Step (3): The task decomposition agent (wbs_agent) calls the data in the document library, decomposes the data into tasks, and outputs at least one task.
[0024] Preferably, when there are multiple tasks, the task decomposition agent outputs these tasks in the form of a task list.
[0025] When the task decomposition agent (wbs_agent) decomposes the data into tasks, it first breaks the data into multiple tasks according to the project's goals and requirements. For example, when developing an e-commerce platform, its data can be decomposed into modules such as user registration, product management, and order processing. Each module is further refined into specific development tasks, such as the user registration module includes front-end form design, back-end data verification, and database storage. Task decomposition aims to clarify the boundaries and responsibilities of each task to facilitate subsequent development and testing.
[0026] Preferably, the task decomposition agent (wbs_agent) can be used as a user agent during operation to interact with the user, such as receiving the user's modification prompt or termination instruction. Of course, step (3) is not necessary and is optional.
[0027] Step (4): The test-driven agent (td_agent, i.e. test_driven_agent) receives the task passed by the previous node and generates the task number, task description, test data, unit test script and code declaration for the task.
[0028] Specifically, the previous node can be the document library in step (2), or the task decomposition agent in step (3). Therefore, the test driving agent receives the task delivered by the previous node, which can be the data delivered by the document library and take it as the task, or at least one task delivered by the task decomposition agent. And each task has a unique task code.
[0029] Taking the task list as an example, the test-driven agent (td_agent) generates corresponding test data based on the task list and designs corresponding test scenarios for each task. For example, in the user registration module, the unit test verifies whether the user name is empty and whether the password complies with the rules; the integration test focuses on the interaction between the front-end and the back-end; the functional test simulates the complete process of user registration; and the performance test evaluates the response time and stability of the registration interface under high concurrency. The design of test data is based on the specific implementation logic of each task in the task list to ensure comprehensive test coverage and avoid missing key scenarios. Code declaration refers to the code framework or interface definition, including the naming and definition of packages, classes, methods, variables, and the accuracy of data design. These code declarations provide a clear development direction for the system to ensure that the development process is closely aligned with the test requirements. Through the cooperation of the task decomposition agent (wbs_agent) and the test-driven agent (td_agent), the project development process achieves quality monitoring of the entire process, improves development efficiency, and reduces the defect rate in the later stage of the project.
[0030] As a preference, the test driver agent (td_agent) reasonably sorts the tasks in the task list and generates task numbers; the test driver agent then outputs the task descriptions and code declarations corresponding to the task numbers to the code generation agent (gc_agent) in turn to facilitate subsequent integration.
[0031] Step (5): The code generation agent (gc_agent, i.e., gen_code_agent) generates or updates the code according to the received task description and code declaration; then, the code generation agent (gc_agent, i.e., gen_code_agent) performs unit testing on the code; during the unit testing process, if an error is reported or the code does not comply with the code specification, the code generation agent (gc_agent) automatically repairs the code according to the error information; if the test passes, the code generation agent (gc_agent) passes the task number and code to the continuous integration agent (ci_agent).
[0032] Preferably, the code generation agent (gc_agent) will first check the compilation environment; if the compilation environment corresponding to the code is missing, it will build an internal compilation environment based on the code type and then perform unit testing.
[0033] When the gc_agent receives the task description and code declaration, it first needs to clarify the specific content of the code declaration. For example, if the code declaration requires the implementation of a sorting algorithm, the gc_agent will select the appropriate algorithm and generate the corresponding code implementation according to the specific requirements of the code declaration. During the code generation process, the gc_agent will ensure that the code structure is clear, complies with the coding standards, and has good readability. In addition, when the gc_agent receives feedback from other subsequent agents, it will modify the code according to the specific content of the feedback information.
[0034] If a unit test fails, the code generation agent (gc_agent) will analyze the cause of the failure and make targeted adjustments. Unit testing is the verification of the smallest functional module in the code. Failure usually means that the module does not work as expected, which may be due to logic errors, unhandled boundary conditions, or mismatched inputs and outputs. The code generation agent (gc_agent) will regenerate the code and rerun the unit test to ensure that the problem is resolved.
[0035] Step (6): The continuous integration agent (ci_agent) passes the current task number to the test driver agent (td_agent). The test driver agent (td_agent) generates and returns the integration test script and test data according to the task number. Then, the continuous integration agent (ci_agent) performs integration verification and regression testing on the code. During the integration verification and regression testing process, if an error is reported, the error result is analyzed. If it is a code error, it is fed back to the code generation agent (gc_agent) for repair, and steps (5) and (6) are repeated. If it is a problem with the continuous integration agent (ci_agent) test environment, the environment configuration is optimized, and the integration verification and regression testing are repeated until the verification is successful. The current task number and the latest code are passed to the continuous deployment agent (cd_agent).
[0036] Preferably, the continuous integration agent (ci_agent) will first check the integration test environment. If there is no integration test environment for executing the integration test script, the continuous integration agent (ci_agent) will generate an internal or external integration test environment based on the analysis of the integration test script, and then perform integration verification and regression testing.
[0037] Step (7), the continuous deployment agent (cd_agent) passes the current task number to the test driver agent (td_agent), and the test driver agent (td_agent) generates and returns functional test, performance test scripts and test data according to the task number; the continuous deployment agent (cd_agent) accesses the performance test environment (QA) and the customer acceptance environment (UAT), and then performs continuous delivery and deployment; during the continuous delivery and deployment process, if there is abnormal data, the abnormal data is analyzed; if it is a problem with the continuous deployment agent (cd_agent) test environment, the environment configuration is optimized and the test is repeated until the verification is successful; if the performance is insufficient, the performance data is fed back to the code generation agent (gc_agent) to update the optimized code, and steps (5), (6) and (7) are repeated; if successful, the continuous deployment agent (cd_agent) notifies the code generation agent (gc_agent) and the test driver agent (td_agent) that the process is finished.
[0038] In addition, the method also includes: a dynamic monitoring module captures the execution context of each AI agent in real time, generates serialized snapshots, and performs heartbeat detection, timeout determination and / or resource occupancy monitoring on each AI agent; when the heartbeat detection, timeout determination and / or resource occupancy exceeds the corresponding threshold, a termination mechanism is triggered; then, the system generates a new agent instance and loads the most recent valid snapshot to continue executing the method from the termination node.
[0039] To make the above method easier to understand, the name, function, input and output of each AI agent are organized into a table below:
[0040] To facilitate understanding of the above method, an example of the process steps is provided below: Step 1: Task description: The test driver agent (td_agent) receives the task of implementing the transfer business, and implements the cross-border transfer function currency type from CNY to USD. In addition, the test part requires the scenario coverage (BSC) of the test case to be >50%, and the code coverage (CC) to be >70%. The task number is 1001. The test driver agent (td_agent) analyzes and concludes that the unit test of the User cross-border transfer function pay based on the unittest framework is used, and the syntax is selected as Python.
[0041] 1. The package, class, and method definition documents are as follows: 1. Package This is a financial project that puts user-related functions under the package path of com.finance.user.
[0042] 2. Class User Class Definition location: located in the user_transfer module (the actual module name should be determined according to the project situation).
[0043] Function Overview: Responsible for processing user-related operations, especially cross-border transfer operations. This class is the core operation class of the entire cross-border transfer function.
[0044] Function: It encapsulates the logic required for users' cross-border transfers, provides a unified interface for cross-border transfer calculations, isolates the transfer logic from external call codes, and facilitates code maintenance and expansion.
[0045] 3. Methods User.pay(self, amount, from_currency, to_currency, exchange_rate) Functional description: This method implements the calculation function of cross-border transfer amount. It calculates the result of converting the source currency amount into the target currency amount based on the given source currency, target currency and exchange rate.
[0046] If the source currency is CNY and the target currency is USD, the amount is converted according to the given exchange rate and the result is returned; otherwise, 0 is returned.
[0047] Parameter Description: self: A reference to the class instance itself, through which you can access the attributes and other methods of the class.
[0048] amount: Type: Numeric type (can be integer or floating point number, depending on the accuracy requirements of the amount in the project requirements).
[0049] Meaning: Indicates the amount to be transferred across borders.
[0050] from_currency: Type: string type.
[0051] Meaning: represents the currency type of the transfer operation. In the current test scenario, we mainly focus on the case where its value is 'CNY'.
[0052] to_currency: Type: string type.
[0053] Meaning: represents the currency type that the transfer operation is finally converted to. In the current test scenario, we mainly focus on the case where its value is 'USD'.
[0054] exchange_rate: Type: Numeric type (can be integer or floating point, depending on the exchange rate accuracy requirements of the project).
[0055] Meaning: Indicates the exchange rate between the source currency and the target currency.
[0056] Return value: Type: Numeric type (same as the type of amount).
[0057] Meaning: If the source currency is CNY and the target currency is USD, returns the converted amount calculated based on the exchange rate; otherwise, returns 0, indicating that the specified currency conversion condition is not met.
[0058] 2. Unit test scripts and test data import unittest from user_transfer import User class TestUserPay(unittest.TestCase): # Test normal transfer scenario def test_normal_pay(self): user = User() amount = 100 # Simulate the exchange rate from CNY to USD exchange_rate = 0.15 result = user.pay(amount, 'CNY', 'USD', exchange_rate) self.assertEqual(result, amount * exchange_rate) # Test the scenario where the amount is 0 def test_zero_amount_pay(self): user = User() amount = 0 exchange_rate = 0.15 result = user.pay(amount, 'CNY', 'USD', exchange_rate) self.assertEqual(result, 0) # Test the scenario where the exchange rate is 0 def test_zero_exchange_rate_pay(self): user = User() amount = 100 exchange_rate = 0 result = user.pay(amount, 'CNY', 'USD', exchange_rate) self.assertEqual(result, 0) if __name__ == '__main__': unittest.main() Step 2: The code generation agent (gc_agent) generates code based on the received task description and code declaration. The User class and pay method in user_transfer.py are defined as follows: class User: def pay(self, amount, from_currency, to_currency, exchange_rate): if from_currency == 'CNY' and to_currency == 'USD': return amount * exchange_rate else: return 0 Then, build the Python compilation environment according to the syntax, receive the unit test script and test data generated in step 1, test the pay method, and check whether the test passes and whether the scenario coverage rate > 50% and code coverage rate > 70% are met. If passed, proceed to step 3.
[0059] Step 3: When the project test environment was first built, the continuous integration agent (ci_agent) received the task and test script, and thought that Flask should be used to build RESTful API integration tests. The script that supports the Postman API test tool was selected, and in the virtual environment built into the continuous integration agent (ci_agent), the external MySQL database server was accessed to save the transfer transaction data, and the relevant MCP service connections were installed and configured. Execute in steps: 1. Flask environment preparation # Create and activate a virtual environment (recommended) python -m venv venv source venv / bin / activate# Linux # Install necessary dependencies pip install flask flask-restful 2. Create a Flask application (app.py), omitted 3. Postman test script configuration Request configuration: Method: POST URL: http: / / localhost:5000 / transfer Headers: Content-Type: application / json Body (raw JSON): { "amount": 100, "from_currency": "CNY", "to_currency": "USD", "exchange_rate":7.2 } Test script (in the Tests tab): / / Verify status code pm.test("Status Code 200", function() { pm.response.to.have.status(200); }); / / Verify the response structure pm.test("Valid Response Structure", function() { const response = pm.response.json(); pm.expect(response).to.have.property('message'); pm.expect(response).to.have.property('details'); }); / / Verify the specific transfer amount pm.test("Correct Conversion", function() { const response = pm.response.json(); pm.expect(response.details.original_amount).to.eql(100); pm.expect(response.details.converted_amount).to.eql(15); pm.expect(response.details.exchange_rate).to.eql(0.15); }); / / Verify balance update pm.test("Balance Updated Correctly", function() { const response = pm.response.json(); pm.expect(response.details.new_balance.A.CNY).to.eql(900); pm.expect(response.details.new_balance.B.USD).to.eql(1015); }); 4. Record transfer data Use the mcp-mysql-server service to connect to the MySQL server outside the agent to save the transfer data.
[0060] 1) Execute the installation command in the agent's virtual environment: npx @f4ww4z / mcp-mysql-server, 2) Configure the agent's MCP connection parameters: { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z / mcp-mysql-server"], "env": { "MYSQL_HOST": "localhost", "MYSQL_USER": "zxz", "MYSQL_PASSWORD": "123456@", "MYSQL_DATABASE": "fin_sys" } } } } 3) The agent uses the configuration information to connect to the MySQL database.
[0061] 4) The agent performs reasoning and issues instructions to save the transfer data 5) MySQL receives the SQL command and completes data saving.
[0062] 5. Postman collection management 1) Create a new collection: Cross-border transfer API 2) Add multiple requests: Successful transfer Insufficient balance test Invalid currency pair test Invalid account test 3) Use collection variables to manage common configuration: Base URL: http: / / localhost:5000 Public test scripts 6. Run Flask Run the command in the bash environment: python app.py 7. Execute Postman test set Use NewMan to execute the .json file exported by the test set in step 4, generate a test report, analyze the report, and proceed to the next step if there are no errors.
[0063] Step 4: The continuous deployment agent (cd_agent) receives the code, passes the current task to the test driver agent (td_agent), returns the functional test, performance test scripts and test data, and the continuous deployment agent (cd_agent) configures the JMeter environment and writes a performance test script to perform concurrent testing on pay. Execute in steps: Configure JMeter script (setup_jmeter.sh) in QA Linux environment #! / bin / bash # JMeter performance test environment automatic configuration script # Install Java (if not already installed) if ! command -v java&> / dev / null; then echo "Installing Java..." sudo apt-get update sudo apt-get install -y openjdk-11-jdk fi # Download JMeter 5.6.2 JMETER_VERSION=5.6.2 JMETER_HOME= / opt / apache-jmeter-${JMETER_VERSION} if [ ! -d "$JMETER_HOME" ]; then echo "Downloading JMeter..." wget https: / / downloads.apache.org / jmeter / binaries / apache-jmeter-${JMETER_VERSION}.tgz sudo tar -xzf apache-jmeter-${JMETER_VERSION}.tgz -C / opt rm apache-jmeter-${JMETER_VERSION}.tgz fi # Setting environment variables echo "Configuring environment variables..." cat< <EOF | sudo tee / etc / profile.d / jmeter.sh export JMETER_HOME=${JMETER_HOME} export PATH=\$JMETER_HOME / bin:\$PATH EOF source / etc / profile.d / jmeter.sh # Install JMeter Plugin Manager echo "Installing Plugins Manager..." PLUGIN_MANAGER_JAR=jmeter-plugins-manager-1.8.jar wget -O ${JMETER_HOME} / lib / ext / ${PLUGIN_MANAGER_JAR} https: / / repo1.maven.org / maven2 / kg / apc / jmeter-plugins-manager / 1.8 / jmeter-plugins-manager-1.8.jar # Install common plugin packages echo "Installing Standard Plugins..." java -jar ${JMETER_HOME} / lib / ext / ${PLUGIN_MANAGER_JAR} install jpgc-standard echo "JMeter setup completed! Please restart your shell session." 2. Execute the script chmod +x setup_jmeter.sh sudo . / setup_jmeter.sh 3. Write the JMeter performance test script structure (payment_test.jmx): Test Plan ├- Thread Group (Cross-border transfer stress test) │├- HTTP Request Defaults (Configure default server) │├- CSV Data Set Config (parameterized test data) │├- HTTP Headers Manager (set request headers) │├- HTTP Request (POST / transfer) │├- Response Assertion (Verify Response) │└- Listener (view results) 4. Start the Flask service in the QA environment and run the JMeter test: Jmeter -n -t payment_test.jmx -l test_results.jtl -e -o . / html_report 5. Execution indicator monitoring # Monitor the resource usage of the Flask server sudo apt-get install sysstat sar -u 1 100# CPU usage sar -r 1 100# Memory usage like Figure 1 As shown, the present invention also discloses a system for realizing automatic code generation using multiple AI agents, the system includes multiple AI agents, and the above method is realized by dialogue between the AI agents. The multiple AI agents of the system specifically include: Task decomposition agent (wbs_agent) is used to call the data required for project development, decompose the data into tasks, and output at least one task.
[0064] The test driver agent (td_agent) is used to receive the task delivered by the previous node and generate the task number, task description, test data, unit test script and code declaration of the task. The previous node can be the task decomposition agent (wbs_agent) or the document library.
[0065] The code generation agent (gc_agent) is used to generate or update code based on the received task description and code declaration.
[0066] The continuous integration agent (ci_agent) is used to perform integration verification and regression testing on the code and provide feedback to the code generation agent (gc_agent).
[0067] The continuous deployment agent (cd_agent) is used for functional testing, performance testing, and security testing, and provides feedback to the code generation agent (gc_agent); it is also used for continuous delivery and deployment.
[0068] In addition, the system also includes a document library, a test case library, and a code library. Among them, the document library is used to store the materials and code declarations required for project development; the test case library is used to store test data and test scripts; the code library is used to store code. The system also includes a dynamic monitoring module, which is used to capture the execution context of each AI agent in real time, generate serialized snapshots, and perform heartbeat detection, timeout determination, and / or resource occupancy monitoring on each AI agent; it is also used to trigger a termination mechanism when the heartbeat detection, timeout determination, and / or resource occupancy exceed the corresponding threshold.
[0069] Of course, in terms of implementing collaborative technical means, in addition to communicating with each other, if the AI agents are deployed in a distributed manner, they can also use message transmission protocols such as HTTP API or gRPC for synchronous communication, and can use coordination mechanisms such as Kafka or RabbitMQ to implement event-driven architecture.
[0070] It should be noted that there are differences between the present invention and the DevOps process: the naming of ci_agnent and cd_agent in the present invention borrows the concept of CI / CD (continuous integration / continuous deployment) of DevOps, but the process only executes deployment to the UAT customer acceptance environment (if there is UAT), and does not deploy to the PROD production environment, that is, after deployment, there is no subsequent continuous monitoring and feedback process, which is different from the general DevOps process. Therefore, the goal of the present invention is to produce code, not to release the product online.
[0071] The above is only a specific implementation of the present invention, but the design concept of the present invention is not limited thereto. Any non-substantial changes to the present invention using this concept shall be deemed as an infringement of the protection scope of the present invention.
Claims
1. A method for realizing automatic code generation using multiple AI Agents, characterized in that: The method is implemented by AI agents communicating with each other, and specifically includes the following steps: Step (1), initializing the system and instantiating the test driver agent, code generation agent, continuous integration agent, and continuous deployment agent; Step (2), the test driver agent receives the task delivered by the previous node, and generates the task number, task description, test data, unit test script and code declaration of the task or data; Step (3), the code generation agent generates or updates the code according to the received task description and code declaration; performs unit testing on the code; if an error is reported or the code does not comply with the code specification, the code is automatically repaired according to the error information; if the test passes, the task number and code are passed to the continuous integration agent; Step (4): The continuous integration agent passes the current task number to the test drive agent, and the test drive agent returns the integration test script and test data according to the task number; the continuous integration agent performs integration verification and regression testing; if an error is reported, the error result is analyzed. If it is a code error, it is fed back to the code generation agent for repair, and steps (3) and (4) are repeated; if it is a problem with the continuous integration agent test environment, the environment configuration is optimized, and the integration verification and regression testing are repeated until the verification is successful; the current task number and the latest code are passed to the continuous deployment agent; Step (5): The continuous deployment agent passes the current task number to the test drive agent, and the test drive agent returns the functional test, performance test scripts and test data according to the task number; the continuous deployment agent accesses the performance test environment and the customer acceptance environment, and then performs continuous delivery and deployment.
2. The method for realizing automatic code generation using multiple AI Agents according to claim 1, characterized in that: In step (2), the previous node is a document library or a task decomposition agent, the document library is used to store data required for project development, and the task decomposition agent is used to call data, decompose the data into tasks, and output at least one task; The test driving agent receives the task delivered by the previous node, specifically: receives the data delivered by the document library and takes it as the task, or receives at least one task delivered by the task decomposition agent.
3. The method for realizing automatic code generation using multiple AI Agents according to claim 2, characterized in that: The task decomposition agent outputs multiple tasks in the form of a task list; in the step (2), the test drive agent reasonably sorts the tasks in the task list and generates task numbers; and then outputs the task descriptions and code declarations corresponding to the task numbers to the code generation agent in sequence.
4. The method for realizing automatic code generation using multiple AI Agents according to claim 1, characterized in that: In step (3), the code generation agent checks the compilation environment. If the compilation environment corresponding to the code is missing, an internal compilation environment is constructed according to the code type, and then unit testing is performed.
5. The method for realizing automatic code generation using multiple AI Agents according to claim 1, characterized in that: In step (4), the continuous integration agent checks the integration test environment. If the integration test environment for executing the integration test script is missing, an internal or external integration test environment is generated based on the analysis of the integration test script, and then integration verification and regression testing are performed.
6. The method for realizing automatic code generation using multiple AI Agents according to claim 1, characterized in that: The step (5) also includes, if there is abnormal data, analyzing the abnormal data, and if it is a problem with the continuous deployment agent test environment, optimizing the environment configuration and repeating the test until the verification is successful; if it is due to insufficient performance, feeding back the performance data to the code generation agent to update the optimized code, and repeating steps (3), (4) and (5); if successful, the continuous deployment agent notifies the code generation agent and the test drive agent that the process is finished.
7. A method for realizing automatic code generation using multiple AI Agents according to claim 1 or 6, characterized in that: In step (5), at the end of the process, the code generation agent saves the code of the corresponding task to the code library, the test drive agent saves the test data and unit test script of the corresponding task to the test case library, and the code declaration to the document library.
8. The method for realizing automatic code generation using multiple AI Agents according to claim 1, characterized in that: It also includes a dynamic monitoring module that captures the execution context of each AI agent in real time, generates serialized snapshots, and performs heartbeat detection, timeout determination, and / or resource occupancy monitoring on each AI agent; when the heartbeat detection, timeout determination, and / or resource occupancy exceed the corresponding threshold, a termination mechanism is triggered; then a new agent instance is generated, and the most recent valid snapshot is loaded to continue executing the method from the termination node.
9. The method for realizing automatic code generation using multiple AI Agents according to claim 1, characterized in that: In step (2), the code declaration includes the naming and definition of packages, classes, methods, and variables, as well as the accuracy of data design.
10. A system for automatically generating code using multiple AI agents, characterized by: The system is used to implement the method as described in any one of claims 1 to 9, which includes: The test driver agent is used to receive the task delivered by the previous node and generate the task number, task description, test data, unit test script and code declaration of the task; A code generation agent, used to generate or update code according to the received task description and code declaration; Continuous integration agent, which performs integration verification and regression testing on the code and provides feedback to the code generation agent; The continuous deployment agent is used for functional testing, performance testing, and security testing, and provides feedback to the code generation agent; it is also used for continuous delivery and deployment.
Citation Information
Patent Citations
Artificial intelligence application deployment environment construction method and device
CA3198338A1
Bidirectional intelligent question and answer code supplementing method and system based on large language model
CN118426825A
Zero-code software development and test system based on artificial intelligence
CN119148988A
Cited By
Cross-environment AI task cooperative execution method and device based on MCP protocol, and storage medium
CN120186142A
Automatic modeling agent system based on MCP protocol and large model
CN120259557A
Automatic cluster management method and system
CN120675965A
Database installation and deployment method based on MCP protocol
CN120743299A
Test method based on multi-mode context protocol and three-stage verification mechanism
CN120849307A