Code generation method and device based on agent, electronic equipment and storage medium
Through the code generation method of the cooperative work of the agent, the problems of low code generation efficiency and poor adaptability in predictive maintenance of industrial equipment are solved, and efficient and accurate code generation and release are achieved.
Patent Information
- Application Number
- CN202510349957.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-24
- Publication Date
- 2025-07-11
AI Technical Summary
In the predictive maintenance technology of existing industrial equipment, the code generation efficiency is low, the model adaptability is poor, and the collaboration ability is weak.
Using the code generation method based on the agent, the first agent retrieves the initial code in the historical code base, the second agent optimizes the initial code, and the third agent verifies the optimization code to ensure that the code meets the release standards and releases it after it is released.
It significantly shortens the code development cycle, improves the efficiency and quality of code generation, and ensures the accurate implementation of code functions.
Smart Images

Figure CN120295632A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical fields of artificial intelligence and predictive maintenance of industrial equipment, and particularly relates to an agent-based code generation method, apparatus, electronic device, and storage medium. Background Art
[0002] As an important part of intelligent manufacturing, although significant progress has been made in the implementation methods of predictive maintenance of industrial equipment, it still faces challenges such as low code generation efficiency, poor model adaptability, and weak collaboration ability. Summary of the Invention
[0003] The purpose of this application is to solve at least one of the technical problems in the related art to some extent.
[0004] To this end, the first object of this application is to propose an agent-based code generation method to automatically generate code, perform feedback iteration optimization on the code, significantly shorten the development cycle, and improve the code generation efficiency.
[0005] The second object of this application is to propose an agent-based code generation apparatus.
[0006] The third object of this application is to propose an electronic device.
[0007] The fourth object of this application is to propose a computer-readable storage medium.
[0008] The fifth object of this application is to propose a computer program product.
[0009] To achieve the above object, an agent-based code generation method according to an embodiment of the first aspect of this application includes: obtaining a code generation task and a historical code library, and retrieving, by a first agent, in the historical code library based on the code generation task to obtain an initial code; executing the initial code, obtaining an execution result of the initial code, and optimizing the initial code based on a second agent and the execution result to obtain an optimized code; determining a release standard for code release, validating the optimized code based on a third agent and the release standard to obtain a validation result, and in response to the validation result meeting the release standard, releasing the optimized code.
[0010] To achieve the above object, an embodiment of the second aspect of the present application provides an agent-based code generation device, including: a retrieval module, configured to obtain a code generation task and a historical code library, and retrieve the historical code library based on the code generation task by a first agent to obtain an initial code; an optimization module, configured to execute the initial code, obtain an execution result of the initial code, and optimize the initial code based on a second agent and the execution result to obtain an optimized code; a verification and release module, configured to determine a release standard for code release, verify the optimized code based on a third agent and the release standard to obtain a verification result, and release the optimized code in response to the verification result meeting the release standard.
[0011] To achieve the above object, an embodiment of the third aspect of the present application provides an electronic device, including: a processor; and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the processor can execute the agent-based code generation method described in the first aspect embodiment above.
[0012] To achieve the above object, an embodiment of the fourth aspect of the present application provides a computer-readable storage medium, on which a computer program is stored, and the computer instructions are used to make the computer execute the agent-based code generation method described in the above-mentioned aspect embodiment.
[0013] To achieve the above object, an embodiment of the fifth aspect of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the agent-based code generation method described in the above-mentioned aspect embodiment.
[0014] The agent-based code generation method, device, electronic device and storage medium provided by the present application retrieve a historical code library based on a code generation task by a first agent to obtain an initial code, and optimize the initial code by a second agent to obtain an optimized code. Furthermore, a third agent verifies the optimized code and releases the optimized code after the verification passes. Thus, the first agent combines the historical code library and the code generation task to automatically generate an initial code, and the second agent and the third agent perform feedback iteration optimization on the initial code, significantly shortening the development cycle and improving the code generation efficiency. Releasing the code after verification can effectively improve the quality of the generated code and ensure the accurate implementation of the code function.
[0015] Additional aspects and advantages of the present application will be given in part in the following description, become apparent in part from the following description, or be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above and / or additional aspects and advantages of the present application will become apparent and be readily understood from the following description of embodiments in conjunction with the accompanying drawings, where:
[0017] Figure 1 is a schematic flowchart of a method for generating code based on an agent provided by an embodiment of the present application;
[0018] Figure 2 is a schematic flowchart of another method for generating code based on an agent provided by an embodiment of the present application;
[0019] Figure 3 is a schematic flowchart of a process for generating initial code provided by an embodiment of the present application;
[0020] Figure 4 is a schematic flowchart of another method for generating code based on an agent provided by an embodiment of the present application;
[0021] Figure 5 is a schematic flowchart of a process for an agent to generate code provided by an embodiment of the present application;
[0022] Figure 6 is a schematic structural diagram of a device for generating code based on an agent provided by an embodiment of the present application. Detailed Embodiments
[0023] The following details the embodiments of the present application. Examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements with the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to explain the present application, and should not be construed as limiting the present application.
[0024] The method of the embodiments of the present application can be widely applied to the field of predictive maintenance of industrial equipment, especially for fault detection and diagnosis of rotating machinery (such as bearings, gearboxes, etc.). In addition, this method can also be extended to other fields that require efficient code development, such as maintenance of wind power generation equipment and generation of operation and maintenance reports. Through the method of the embodiments of the application, efficient and highly adaptable code development can be achieved, while fully leveraging the collaborative advantages of human engineers and agents based on large language models, providing strong technical support for predictive maintenance of equipment in an industrial context.
[0025] The following describes the agent-based code generation method and device of the embodiments of the present application with reference to the accompanying drawings.
[0026] Figure 1 is a flowchart of a method for generating code based on an agent provided by an embodiment of the present application, as Figure 1As shown in the figure, the agent-based code generation method according to the embodiments of the present application includes, but is not limited to, the following steps:
[0027] S101, obtain a code generation task and a historical code library, and retrieve the historical code library by a first agent based on the code generation task to obtain an initial code.
[0028] It should be noted that the execution subject of the agent-based code generation method provided in the embodiments of the present application is an electronic device, and the electronic device may be a terminal device. Optionally, the terminal device may be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device may be a mobile phone, a tablet computer, a laptop computer, a handheld computer, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device may be a personal computer (PC), a television, etc. The embodiments of the present application do not make specific limitations.
[0029] It should be noted that the method proposed in the embodiments of the present application can be applied in the field of predictive maintenance of different industrial devices, such as fault detection, and steps such as preprocessing, feature extraction, and fault diagnosis of the collected signals are performed according to the generated code. In the embodiments of the present application, taking bearing fault detection as an example, the agent-based code generation method proposed in the embodiments of the present application is explained.
[0030] In some embodiments, corresponding code generation tasks can be generated according to different stages of bearing fault detection. For example, if the current stage is the preprocessing stage of vibration signals, "generate analysis code for preprocessing" can be used as the code generation task; if the current stage is the feature extraction stage of vibration signals, "generate analysis code for feature extraction" can be used as the code generation task.
[0031] In some embodiments, different codes are stored in the historical code library. The codes stored in the historical code library can be obtained by retrieving any code from a network platform, and / or different codes can be manually written as the codes stored in the historical code library, etc.
[0032] In some embodiments, after obtaining the code generation task, the code generation task can be transmitted to the first agent, and then the first agent retrieves the historical code library based on the code generation task to obtain an initial code. That is to say, the first agent is a code generation agent for generating an initial code.
[0033] Optionally, the process of generating the initial code can be expressed as:
[0034] c init = G(C hist , t)(1)
[0035] Among them, c init represents the initial code, G represents the first agent, t represents the code generation task, and C hist represents the historical code library.
[0036] In some embodiments, the first agent can call a large language model to retrieve in the historical code library and use the retrieved code as the initial code.
[0037] S102. Execute the initial code to obtain the execution result of the initial code, and optimize the initial code based on the second agent and the execution result to obtain the optimized code.
[0038] In some embodiments, by executing the initial code, the execution result corresponding to the initial code can be obtained. The execution result may include content such as the running data and error information of the code. Furthermore, the second agent can optimize the initial code according to the execution result, thereby obtaining the optimized code. That is to say, the second agent is a code optimization agent for optimizing the initial code.
[0039] In some embodiments, the process of the second agent optimizing the initial code includes performance optimization, readability optimization, and adaptability optimization. The process of optimizing the initial code can be expressed as:
[0040] c opt = O(c init , E feedback )(2)
[0041] Among them, c opt represents the optimized code, O represents the second agent, c init represents the initial code, and E feedback represents the execution result.
[0042] In some embodiments, executing the initial code includes manually executing the initial code and / or having an agent execute the initial code. That is to say, the execution result of the initial code includes the manual execution result and / or the agent execution result.
[0043] S103. Determine the release standard for code release, verify the optimized code based on the third agent and the release standard to obtain the verification result, and release the optimized code in response to the verification result meeting the release standard.
[0044] In some embodiments, to ensure the correctness of the generated code functionality, the optimized code can be verified according to the release criteria for code release, and after the optimized code passes the verification, the optimized code can be released to execute the processing flow corresponding to the code generation task.
[0045] For example, if the code generation task is "generate analysis code for preprocessing", the optimized code can execute the preprocessing flow after passing the verification.
[0046] In some embodiments, the verification scheme and verification data for the task scenario can be determined according to the task scenario corresponding to the code generation task as the release criteria for code release.
[0047] In some embodiments, a third intelligent agent can be used to verify whether the optimized code meets the release criteria and generate a verification result. That is to say, the verification result is used to determine whether the optimized code meets the release criteria, and when it meets the release criteria, the optimized code is released. Among them, the third intelligent agent is a code verification intelligent agent for verifying the optimized code.
[0048] In some embodiments, after obtaining the verification result, a verification report can be generated based on the verification result and used as the result after the execution of the verification scheme.
[0049] In some embodiments, the third intelligent agent can verify whether the optimized code meets the verification scheme according to the verification data in the release criteria. That is to say, when the optimized code meets the verification scheme, it is determined that the verification result meets the release criteria.
[0050] Optionally, the process of verifying the optimized code can be expressed as:
[0051] r = V(c opt , D val )(3)
[0052] where r represents the verification result, V represents the third intelligent agent, c opt represents the optimized code, and D val represents the verification data.
[0053] In some embodiments, to enhance the reliability of the optimized code, after the optimized code passes the verification by the third intelligent agent, it can also be manually verified, and after the optimized code passes the manual verification, the optimized code is released.
[0054] In some embodiments, the optimized code can also be merged into the historical code library to update the historical code library, so that the code in the historical code library can provide a basis for subsequent code generation and facilitate more accurate code generation.
[0055] Optionally, the process of updating the historical code library can be expressed as:
[0056] C new_hist = C hist ∪ c final (4)
[0057] where c final represents the optimized code, and C hist represents the historical code library, and C new_hist represents the updated historical code library.
[0058] In the agent-based code generation method provided by the embodiments of the present application, the first agent retrieves in the historical code library based on the code generation task to obtain the initial code, and the second agent optimizes the initial code to obtain the optimized code. Then, the third agent verifies the optimized code and publishes the optimized code after the verification passes. Thus, the first agent combines the historical code library and the code generation task to automatically generate the initial code, and the second agent and the third agent perform feedback iteration optimization on the initial code, significantly shortening the development cycle and improving the code generation efficiency. Publishing the code after verification can effectively improve the quality of the generated code and ensure the accurate implementation of the code function.
[0059] Figure 2 is a flowchart of an agent-based code generation method provided by the embodiments of the present application. As Figure 2 shown, the agent-based code generation method of the embodiments of the present application includes, but is not limited to, the following steps:
[0060] S201, obtain the code generation task and the historical code library.
[0061] In the embodiments of the present application, the implementation manner of step S201 can be implemented by any one of the embodiments of the present application respectively, and no limitation is made thereto here, nor will it be elaborated further.
[0062] S202, the first agent calls the large language model, retrieves in the historical code library based on the code generation task, and outputs the output information containing the code.
[0063] S203, extract the code from the output information as the initial code.
[0064] In some embodiments, the first agent can retrieve in the historical code library based on the code generation task, input the retrieved code into the large language model, and the large language model sorts out the retrieved code, so as to output the output information containing the code, and then the initial code can be extracted from the output information.
[0065] In some embodiments, code retrieval can be performed based on the feature information of the code generation task. By determining the text features corresponding to the code generation task and performing a retrieval match in the historical code library based on the text features, K code snippets that match the text features are determined, where K is a natural number greater than 1.
[0066] Optionally, the matching degree between the code snippets in the historical code library and the text features can be calculated, and the matching code snippets can be sorted by the matching degree to obtain K code snippets that match the text features.
[0067] Optionally, the process of determining K code snippets can be expressed as:
[0068] codes=max<query,code>,code∈Codes(5)
[0069] where codes represents K code snippets, query represents the text features, code represents the code snippets in the historical code library, and Codes represents the historical code library.
[0070] Furthermore, output information can be generated and output based on the K code snippets. Optionally, the K code snippets and the code generation task can be used as input information and input into a large language model. The large language model sorts out the K code snippets according to the code generation task, thereby outputting the output information containing the code.
[0071] Optionally, the process of determining the output information can be expressed as:
[0072] response=LLM(input)(6)
[0073] where response represents the output information, LLM represents the large language model, and input represents the input information.
[0074] Such as Figure 3 the schematic flowchart of generating the initial code shown. Figure 3 The first intelligent agent in is the code generation intelligent agent. The code generation intelligent agent retrieves code in the historical code library based on the code generation task, can generate the initial code, and then can perform subsequent code optimization and release based on the initial code.
[0075] S204. Execute the initial code, obtain the execution result of the initial code, and optimize the initial code based on the second intelligent agent and the execution result to obtain the optimized code.
[0076] In the embodiments of the present application, the implementation manner of step S204 can be implemented by any one of the embodiments of the present application, and no limitation is made here and will not be elaborated further.
[0077] S205. Determine the release criteria for code release. Based on the third agent and the release criteria, verify the optimized code to obtain a verification result. In response to the verification result meeting the release criteria, release the optimized code.
[0078] In the embodiments of the present application, the implementation manner of step S205 can be implemented by any one of the embodiments of the present application respectively. No limitation is made here and it will not be elaborated further.
[0079] In some embodiments, releasing the optimized code further includes performing a secondary verification on the optimized code and releasing the optimized code after the verification passes. By sending the optimized code to the client for secondary verification, in response to the optimized code passing the secondary verification, release the optimized code.
[0080] That is to say, the optimized code can be sent to the client, and the optimized code is manually verified for the second time. After the manual confirmation that the optimized code passes the secondary verification, it is fed back to the third agent, and then the optimized code can be released, so that it can be applied in practice.
[0081] In some embodiments, in response to the optimized code not meeting the release criteria or failing the secondary verification, the first agent repeats the steps of code generation based on the code generation task and the historical code library until an optimized code that meets the release criteria and passes the secondary verification is obtained and released.
[0082] In the method for generating code based on an agent provided by the embodiments of the present application, the first agent calls a large language model and retrieves in the historical code library based on the code generation task to obtain an initial code. Thus, the first agent can retrieve relevant code segments from the historical code library through semantic analysis and feature matching, and perform migration and adaptation in combination with the code generation task to ensure that the generated code has wide applicability.
[0083] Figure 4 is a flowchart of a method for generating code based on an agent provided by the embodiments of the present application. As Figure 4 shown, the method for generating code based on an agent in the embodiments of the present application includes but is not limited to the following steps:
[0084] S401. Obtain a code generation task and a historical code library, and the first agent retrieves in the historical code library based on the code generation task to obtain an initial code.
[0085] In the embodiments of the present application, the implementation manner of step S401 can be implemented by any one of the embodiments of the present application respectively. No limitation is made here and it will not be elaborated further.
[0086] S402. The fourth agent executes the initial code to determine the first execution result corresponding to the initial code.
[0087] S403. Send the initial code to the client to obtain the second execution result corresponding to the initial code.
[0088] S404. Determine the execution result based on the first execution result and / or the second execution result.
[0089] In some embodiments, when optimizing the initial code according to the execution result, the execution result can be the execution result from the agent, or the execution result from the human, or the execution result from the agent and the execution result from the human.
[0090] In some embodiments, by inputting the initial code into the fourth agent, the fourth agent executes the initial code, and the first execution result corresponding to the initial code can be obtained. That is to say, the fourth agent is a pseudo-code execution agent for executing code.
[0091] In some embodiments, by sending the initial code to the client and having a human execute the code received by the client, the second execution result corresponding to the initial code can be obtained.
[0092] Furthermore, the first execution result can be used as the execution result, or the second execution result can be used as the execution result, or the first execution result and the second execution result can be used as the execution result.
[0093] That is to say, the execution result E feedback can be E feedback = αE agent + βE human , where α and β are weight values, E agent is the first execution result, and E human is the second execution result.
[0094] S405. Optimize the initial code based on the second agent and the execution result to obtain the optimized code.
[0095] In the embodiments of the present application, the implementation manner of step S405 can be implemented by any one of the embodiments of the present application respectively. No limitation is made here and it will not be elaborated further.
[0096] S406. Determine the release standard for code release. Based on the third agent and the release standard, verify the optimized code to obtain the verification result. In response to the verification result meeting the release standard, release the optimized code.
[0097] In the embodiments of the present application, the implementation manner of step S406 can be implemented by any one of the embodiments of the present application, and no limitation is made here and will not be elaborated again.
[0098] In the agent-based code generation method provided by the embodiments of the present application, the first execution result obtained by the fourth agent executing the initial code can be obtained, and the second execution result obtained by the human executing the initial code can be obtained, and based on the first execution result and / or the second execution result, the execution result can be determined. Thus, the creativity of the human and the efficiency of the agent can be fully utilized to achieve human-machine collaborative work. This collaborative mode not only improves the code quality but also reduces the human error rate.
[0099] Based on the above embodiments, the embodiments of the present application can also obtain the experience of task processing and code verification, and verify the generation of the code based on the experience to achieve the rapid generation of high-quality code.
[0100] In some embodiments, the decomposition experience of the code generation task can be obtained, so that the code generation task can be decomposed into multiple subtasks according to the experience, and the completion efficiency of the code generation task is improved by executing the subtasks.
[0101] In some embodiments, the experience of manual task decomposition can be obtained as the experience data of the agent. By sending the code generation task to the client and sending a task decomposition instruction to the client, the client then decomposes the code generation task into multiple subtasks according to the task decomposition instruction, and generates a task assignment instruction for the subtasks to achieve the assignment of the subtasks.
[0102] Further, by receiving the multiple subtasks obtained by the client based on the task decomposition instruction to decompose the code generation task, and receiving the task assignment instruction sent by the client, and based on the task assignment instruction, the subtasks are assigned to multiple agents to complete the code generation task and obtain the code generation result. The agent includes at least one of the first agent, the second agent, and the third agent.
[0103] Further, the task decomposition experience can be determined based on the subtasks and the code generation result.
[0104] Exemplarily, let the code generation task be T0, and T0 is decomposed into multiple subtasks according to the task decomposition instruction, which are: t1, t2,..., t n , and are assigned to different agents based on the task assignment instruction. The decomposition of the task can be expressed as: exp d =T0->∪ i t i . Where exp d is the task decomposition experience.
[0105] In some embodiments, the experience of manual code verification can be obtained as the experience data of the agent. In response to the client receiving a code verification instruction, the code carried by the code verification instruction is verified, and code verification experience is generated.
[0106] Exemplarily, the process of manual code verification can be expressed as: E human = F human (c init ), and the verification process is constructed into an experience trajectory: exp f = c_ init -> E human , where exp f is the code verification experience.
[0107] In some embodiments, an experience model can be established based on the task decomposition experience and the code verification experience, and the experience model is added to the historical code library, so that the first agent can generate an initial code according to the experience model, thereby improving the quality of the code generated by the agent. Through experience accumulation, the agent can continuously learn and optimize, and gradually improve the intelligent level of code development.
[0108] Optionally, adding the agent to the historical code library can be formally expressed as: E = E ∪ {t, c, exp}, where {t, c, exp} is a triple composed of tasks, codes, and experiences, and can be retrieved by the retrieval system of other agents as a reference.
[0109] Figure 5 The flowchart of the agent generating code is shown. As Figure 5 shown, by obtaining a code generation task and using the first agent to retrieve in the historical code library based on the code generation task to generate an initial code, and the initial code is executed and fed back by humans and the agent to obtain the execution result corresponding to the initial code. Thus, the second agent can optimize the initial code according to the execution result to obtain an optimized code. Further, the third agent verifies the optimized code, publishes the optimized code after passing the verification, and updates the optimized code to the historical code library.
[0110] Corresponding to the agent-based code generation method proposed in the above several embodiments, an embodiment of the present application also proposes an agent-based code generation device. Since the agent-based code generation device proposed in the embodiment of the present application corresponds to the agent-based code generation method proposed in the above several embodiments, the implementation manners of the above agent-based code generation method are also applicable to the agent-based code generation device proposed in the embodiment of the present application, and will not be described in detail in the following embodiments.
[0111] To implement the above embodiments, the present application also proposes an agent-based code generation device.
[0112] Figure 6 FIG. 4 is a schematic structural diagram of an agent-based code generation device provided by an embodiment of the present application.
[0113] As Figure 6 shown, the agent-based code generation device 600 includes:
[0114] A retrieval module 601, configured to obtain a code generation task and a historical code library, and retrieve the historical code library based on the code generation task by a first agent to obtain an initial code;
[0115] An optimization module 602, configured to execute the initial code, obtain an execution result of the initial code, and optimize the initial code based on a second agent and the execution result to obtain an optimized code;
[0116] A verification and release module 603, configured to determine a release standard for code release, verify the optimized code based on a third agent and the release standard to obtain a verification result, and release the optimized code in response to the verification result meeting the release standard.
[0117] In a possible implementation manner of an embodiment of the present application, the verification and release module 603 is further configured to: send the optimized code to a client for secondary verification, and release the optimized code in response to the optimized code passing the secondary verification.
[0118] In a possible implementation manner of an embodiment of the present application, the verification and release module 603 is further configured to: in response to the optimized code not meeting the release standard or failing the secondary verification, the first agent repeats the steps of code generation based on the code generation task and the historical code library until an optimized code that meets the release standard and passes the secondary verification is obtained and released.
[0119] In a possible implementation manner of an embodiment of the present application, the retrieval module 601 is further configured to: the first agent invokes a large language model, retrieves the historical code library based on the code generation task, and outputs output information including code; extract the code from the output information as the initial code.
[0120] In a possible implementation manner of an embodiment of the present application, the retrieval module 601 is further configured to: determine text features corresponding to the code generation task; perform retrieval and matching in the historical code library based on the text features to determine K code segments matching the text features, where K is a natural number greater than 1; generate and output output information based on the K code segments.
[0121] In a possible implementation manner of the embodiment of the present application, the optimization module 602 is further configured to: execute the initial code by the fourth agent to determine a first execution result corresponding to the initial code; send the initial code to the client to obtain a second execution result corresponding to the initial code; and determine an execution result based on the first execution result and / or the second execution result.
[0122] In a possible implementation manner of the embodiment of the present application, the device further includes: sending a code generation task to the client and sending a task decomposition instruction to the client; receiving multiple subtasks obtained by the client based on the task decomposition instruction for decomposing the code generation task; receiving a task allocation instruction sent by the client, and allocating the subtasks to multiple agents based on the task allocation instruction to complete the code generation task and obtain a code generation result, where the agents include at least one of a first agent, a second agent, and a third agent.
[0123] In a possible implementation manner of the embodiment of the present application, the device further includes: determining task decomposition experience based on the subtasks and the code generation result; in response to the client receiving a code verification instruction, verifying the code carried by the code verification instruction and generating code verification experience; establishing an experience model based on the task decomposition experience and the code verification experience; and adding the experience model to the historical code library for the first agent to generate an initial code according to the experience model.
[0124] In the agent-based code generation device provided by the embodiment of the present application, the first agent retrieves in the historical code library based on the code generation task to obtain an initial code, and the second agent optimizes the initial code to obtain an optimized code. Further, the third agent verifies the optimized code and publishes the optimized code after the verification passes. Thus, the first agent combines the historical code library and the code generation task to automatically generate an initial code, and the second agent and the third agent perform feedback iteration optimization on the initial code, significantly shortening the development cycle and improving the code generation efficiency. Publishing the code after verification can effectively improve the quality of the generated code and ensure the accurate implementation of the code function.
[0125] It should be noted that the foregoing explanation of the embodiment of the agent-based code generation method is also applicable to the agent-based code generation device of this embodiment, and will not be repeated here.
[0126] To implement the above embodiments, the present application further provides an electronic device, including: a processor and a memory communicatively connected to the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to implement the method provided in the foregoing embodiments.
[0127] To implement the above embodiments, the present application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the method provided in the foregoing embodiments.
[0128] To implement the above embodiments, the present application also provides a computer program product including a computer program, which, when executed by a processor, implements the method provided in the foregoing embodiments.
[0129] The collection, storage, use, processing, transmission, provision, and application of the user's personal information involved in the present application all comply with the provisions of relevant laws and regulations and do not violate public order and good customs.
[0130] It should be noted that personal information from users should be collected for legal and reasonable purposes and not shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after obtaining the informed consent of the user, including but not limited to notifying the user to read the user agreement / user notice and sign an agreement / authorization including authorizing relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data and ensure that others with access to the personal information data comply with their privacy policies and procedures.
[0131] The present application is expected to provide an implementation for users to selectively block the use or access of personal information data. That is, the present application is expected to provide hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, the risk can be minimized by restricting data collection and deleting the data. In addition, when applicable, personal identifiers are removed from such personal information to protect the privacy of the user.
[0132] In the description of the foregoing embodiments, the descriptions referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic descriptions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0133] In addition, the terms "first" and "second" are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In the description of the present application, "a plurality of" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0134] Any process or method description represented in a flowchart or described otherwise herein may be understood to represent a module, segment, or portion of code including one or more executable instructions for implementing a customized logical function or process. The scope of the preferred embodiments of the present application includes additional implementations, where functions may be executed in a substantially simultaneous manner or in a reverse order according to the involved functions, rather than in the order shown or discussed, which should be understood by those skilled in the art to which the embodiments of the present application pertain.
[0135] The logic and / or steps represented in a flowchart or described otherwise herein, for example, may be considered as a sequenced list of executable instructions for implementing a logical function, and may be specifically implemented in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, a system including a processor, or other systems that can fetch and execute instructions from the instruction execution system, apparatus, or device. For the purposes of this specification, a "computer-readable medium" may be any device that can contain, store, communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. More specific examples (non-exhaustive list) of the computer-readable medium include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer diskette (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium may even be paper or other suitable media on which the program can be printed, as the program can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpretation, or other appropriate processing as necessary, and then stored in a computer memory.
[0136] It should be understood that each part of the present application can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, any one or a combination of the following technologies well known in the art can be used: discrete logic circuits with logic gate circuits for implementing logical functions on data signals, application specific integrated circuits with appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), etc.
[0137] Those of ordinary skill in the art can understand that all or part of the steps carried by the method of implementing the above embodiments can be completed by instructing relevant hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiments.
[0138] In addition, in each embodiment of the present application, each functional unit can be integrated in a processing module, or each unit can exist physically alone, or two or more units can be integrated in one module. The above integrated module can be implemented in the form of hardware or in the form of a software functional module. When the above integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0139] The above-mentioned storage medium can be a read-only memory, a magnetic disk, an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present application. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present application.
Claims
1. An agent-based code generation method, characterized in that, The method includes: Obtain a code generation task and a historical code library, and retrieve in the historical code library based on the code generation task by a first intelligent agent to obtain an initial code; Execute the initial code, obtain an execution result of the initial code, and optimize the initial code based on a second intelligent agent and the execution result to obtain an optimized code; Determine a release standard for code release, verify the optimized code based on a third intelligent agent and the release standard to obtain a verification result, and in response to the verification result meeting the release standard, release the optimized code.
2. The method according to claim 1, characterized in that, The releasing of the optimized code further includes: Send the optimized code to a client for secondary verification, and in response to the optimized code passing the secondary verification, release the optimized code.
3. The method according to claim 2, wherein The method further includes: In response to the optimized code not meeting the release standard or failing the secondary verification, the first intelligent agent repeats the steps of code generation based on the code generation task and the historical code library until an optimized code that meets the release standard and passes the secondary verification is obtained and released.
4. The method according to claim 1, wherein The retrieving in the historical code library by the first intelligent agent based on the code generation task to obtain an initial code includes: The first intelligent agent calls a large language model, retrieves in the historical code library based on the code generation task, and outputs output information containing code; Extract the code from the output information as the initial code.
5. The method according to claim 4, wherein The retrieving in the historical code library based on the code generation task and outputting output information containing code includes: Determine text features corresponding to the code generation task; Retrieve and match in the historical code library based on the text features, and determine K code fragments that match the text features, where K is a natural number greater than 1; Generate and output the output information based on the K code fragments.
6. The method according to claim 1, wherein The obtaining of the execution result of the initial code includes: Execute the initial code by a fourth intelligent agent to determine a first execution result corresponding to the initial code; Send the initial code to a client to obtain a second execution result corresponding to the initial code; Determine the execution result based on the first execution result and / or the second execution result.
7. The method according to claim 1, wherein The method further includes: Send the code generation task to a client and send a task decomposition instruction to the client; Receive multiple subtasks obtained by the client decomposing the code generation task based on the task decomposition instruction; Receive a task allocation instruction sent by the client, and allocate the subtasks to multiple intelligent agents based on the task allocation instruction to complete the code generation task and obtain a code generation result, where the intelligent agents at least include one of the first intelligent agent, the second intelligent agent, and the third intelligent agent.
8. The method according to claim 7, wherein The method further includes: Determine task decomposition experience based on the subtasks and the code generation result. In response to the client receiving a code verification instruction, verify the code carried in the code verification instruction and generate code verification experience; Based on the task decomposition experience and the code verification experience, establish an experience model; Add the experience model to the historical code library so that the first intelligent agent generates the initial code according to the experience model.
9. An agent-based code generation device, characterized in that, The device includes: A retrieval module, configured to obtain a code generation task and a historical code library, and the first intelligent agent retrieves in the historical code library based on the code generation task to obtain an initial code; An optimization module, configured to execute the initial code, obtain the execution result of the initial code, and optimize the initial code based on the second intelligent agent and the execution result to obtain an optimized code; A verification and release module, configured to determine the release criteria for code release, verify the optimized code based on the third intelligent agent and the release criteria to obtain a verification result, and in response to the verification result meeting the release criteria, release the optimized code.
10. An electronic device, characterized in that, including: A processor and a memory communicatively connected to the processor; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory to implement the method according to any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, Computer execution instructions are stored in the computer-readable storage medium, and when the computer execution instructions are executed by a processor, they are used to implement the method according to any one of claims 1-8.
12. A computer program product, characterized in that, including a computer program, which when executed by a processor implements the method according to any one of claims 1-8.
Citation Information
Cited By
Software development method and device based on artificial intelligence, equipment and medium
CN120723218A
Artificial intelligence-based software development method, device, equipment and medium
CN120723218B