Patch round method, device, system, storage medium and program product
By working collaboratively with code retrieval agents and target language agents, the conflict between patch rounds between software versions is automatically resolved, improving the success rate and accuracy of patch rounds and solving the problem of time-consuming and error-prone manual adaptation in existing technologies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ALIBABA CLOUD COMPUTING CO LTD
- Filing Date
- 2026-06-23
- Publication Date
- 2026-07-21
AI Technical Summary
In existing technologies, the patching process relies on manual adaptation, which is time-consuming and prone to errors, and cannot effectively solve the problem of code differences between software versions.
The code retrieval agent and the target language agent work together to automatically locate and rewrite the patch logic through a deep learning model, generate adapted code segments, and realize the patching round.
It improves the success rate of automatic patching rounds, reduces human error, and enhances the efficiency and accuracy of patching rounds.
Smart Images

Figure CN122431716A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a patching method, device, system, storage medium, and program product. Background Technology
[0002] Security vulnerabilities or functional defects fixed in the mainline version of a software need to be ported to multiple historical stable branches to ensure that older versions of the software still widely deployed in production environments can receive the necessary security updates and critical fixes. This process of porting patches from the mainline version to older versions is called patch backporting, and it is a key component of the long-term maintenance system for large software projects.
[0003] However, due to the continuous evolution of software codebases across different versions, original patches originating from the current version often cannot be directly applied to the target older version. Current patch rounds heavily rely on manual adaptation by domain experts, a process that is not only time-consuming but also prone to human error. Summary of the Invention
[0004] This application provides a patch rounding method, device, system, storage medium, and program product to automatically resolve patch rounding conflicts and improve the automatic patch rounding success rate.
[0005] This application provides a patching round method, including: Obtain the first code segment and the second code segment restored based on the first patch; the first code segment is the original code of the target software of the first version corresponding to the first patch; the second code segment is the modified code of the target software of the first version corresponding to the first patch. Guided by a first prompt word, the code retrieval agent determines the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the second version of the target software. Guided by the second prompt word, the second code segment is rewritten using the target programming language by the target language agent to obtain the fourth code segment; the target programming language is the programming language used by the third code segment. Guided by the second prompt word, the target language agent uses the third code segment and the first position information to return the fourth code segment to the first source code.
[0006] This application also provides a patching round system, including: a code retrieval agent and a target language agent; The code retrieval agent is used to obtain a first code segment restored based on a first patch; the first code segment is the original code of the target software of the first version corresponding to the first patch; and, guided by a first prompt word, to determine a third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the target software of the second version. The target language agent is used to acquire a second code segment restored based on the first patch; the second code segment is the modified code of the first version of the target software corresponding to the first patch; and, guided by a second prompt, rewrites the second code segment using a target programming language to obtain a fourth code segment; the target programming language is the programming language used by the third code segment; and, guided by the second prompt, returns the fourth code segment to the first source code according to the third code segment and the first position information.
[0007] This application also provides an electronic device, including: a memory and a processor; wherein the memory is used to store computer programs; The processor is coupled to the memory for executing the computer program to perform the steps in the patch round method described above.
[0008] This application also provides a computer-readable storage medium storing computer instructions that, when executed by one or more processors, cause the one or more processors to perform the steps in the patching round method described above.
[0009] This application also provides a computer program product, including a computer program that, when executed by one or more processors, causes the one or more processors to perform the steps in the patching round method described above.
[0010] In this embodiment, the code retrieval agent locates the third code segment in the target project awaiting a turn that corresponds to the original modified semantics. Then, the target language agent rewrites the patch logic based on this context to be oriented towards the target environment (generating the fourth code segment), thereby generating the adapted code for the target project. This solves the patch turn conflict caused by version evolution and helps to improve the automatic patch turn success rate. Attached Figure Description
[0011] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments of this application and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 A flowchart illustrating the patching round method provided in this application embodiment; Figure 2 A schematic diagram illustrating the process of the patch round method provided in this application embodiment; Figure 3 This is a schematic diagram of the architecture of the patch round system provided in the embodiments of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0012] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0013] It should be noted that, in the cases involving user information in the embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse. The deep learning models involved in each embodiment of this application also comply with the relevant laws, regulations, and standards of the relevant countries and regions.
[0014] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0015] Figure 1 This is a flowchart illustrating the patching round method provided in an embodiment of this application. Figure 1 As shown, this patching round method mainly includes the following steps: 101. Obtain the first code segment and the second code segment restored based on the first patch; the first code segment is the original code of the target software of the first version corresponding to the first patch; the second code segment is the modified code of the target software of the first version corresponding to the first patch.
[0016] 102. Using a code retrieval agent, guided by the first prompt word, determine the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the second version of the target software.
[0017] 103. Using the target language agent, guided by the second prompt word, write the second code segment in the target programming language to obtain the fourth code segment; the target programming language is the programming language used in the third code segment.
[0018] 104. Using the target language agent, guided by the second prompt word, the fourth code segment is returned to the first source code segment based on the third code segment and the first position information.
[0019] In this embodiment, the agent is intelligent code based on a deep learning model. It refers to an intelligent system with a deep learning model as its "core brain," possessing autonomous understanding, planning, memory, and tool usage capabilities, and able to interact with the external environment to achieve specific goals. The deep learning model can be a deep learning model with a relatively large number of parameters. The Large Language Model (LLM) is merely one example; this application does not limit the number of model parameters supported by the deep learning model used, aiming to meet actual needs. The deep learning model involved in this application embodiment can be an artificial intelligence-based language model (LM) or a multimodal model (MM).
[0020] In this embodiment, the target software is a computer program product, which can be implemented as an application (APP), a mini-program, a PC client, a program module, a plugin, an installation package, a software development kit (SDK), an optical disc image file, a plugin, or software in the form of Software as a Service (SaaS), but is not limited to these. Multiple versions of the target software are deployed in the production environment. The operation and maintenance personnel of the target software generally use patching technology to fix vulnerabilities or functional defects in the main version and then port the patch to older versions. A patch is a set of structured change instructions used to modify, update, or repair existing software source code. In this embodiment, the first patch refers to the patch used to repair the first version of the target software.
[0021] Patches are typically represented in text format, describing the differences between the target file before and after modification. They can be automatically parsed and applied by version control systems (such as Git tools) or patching tools. Patches generally include: metadata information, file path identifiers, and diff hunks. Metadata information may include: patch commit information (such as the purpose, background, and scope of impact of the patch), the patch author, and the commit time. File path identifiers specify the path to the source file being modified. Diff hunks may include: the path to the original code file, the path to the new code file, a location identifier, the original code line (starting with "-"), the newly added code line (starting with "+"), and the context line (starting with a space). Lines in the diff hunk that begin with the identifiers "---" and "+++" respectively record the paths to the original and new code files. Location identifiers indicate the starting line number and line number of the code segment to be modified in the original and new code files, typically represented as "@@ -old_start,old_length, +new_start,new_length @@". In this code, "-" indicates the starting line number of the code to be deleted or replaced in the original code file; "old_length" indicates the number of lines in the original code file occupied by the code to be deleted or replaced. "new_start" indicates the starting line number of the replaced or added code in the modified code file; "new_length" indicates the number of lines in the replaced or added code in the modified code file.
[0022] Original code lines refer to the code in the original code file that needs to be deleted or replaced; newly added code lines refer to the code that has been replaced or added. Context lines refer to surrounding code that has not been modified but is used for location purposes.
[0023] For example, the original modified block can be represented as: --- a / lib / timeutils.c / / Path to the original code file +++ b / lib / timeutils.c / / Path to the new code file @@ -438,14 +439,14 @@ / / Location information (starting from line number -438 in the original code file, totaling 14 lines; starting from line number +439 in the new code file) if (flags&ISO_DOTUSEC) { - len = sprintf(p, s, "%06ld"); / / Delete the line of code + len = sprintf(p, s, "%06"Id64); / / Add a new line of code / / With ISO_DOTUSEC (a formatting option flag) enabled, the sprintf format originally used for outputting microseconds is changed from %06ld to %06"Id64.
[0024] As described above, a patch contains code that needs to be deleted or replaced in the original code file, as well as the replaced or newly added code. Through research on the deep learning model relied upon by the agent, the researchers of this application found that the deep learning model's ability to process code is significantly better than its ability to process the patch itself or the modified blocks within the patch. Therefore, in this embodiment, in order to transfer the first patch to the second version of the target software, in step 101, a first code segment and a second code segment reconstructed based on the first patch can be obtained. The first code segment is the original code of the first version of the target software corresponding to the first patch; the second code segment is the modified code of the first version of the target software corresponding to the first patch.
[0025] In some embodiments, the first patch includes one or more original modification blocks. For any original modification block, modification units can be read from that original modification block, as shown below: if (flags&ISO_DOTUSEC) { - len = sprintf(p, s, "%06ld"); / / Delete the line of code + len = sprintf(p, s, "%06"Id64); / / Add a new line of code } Furthermore, based on a preset identifier (e.g., "-") of the original code, code starting with the identifier of the original code can be determined from the first patch. In the modification unit, code starting with the identifier of the original code (e.g., "-") is retained, and lines of code starting with the identifier of the original code and the identifier of the modified code (e.g., "+") are deleted, resulting in the first code segment corresponding to the original modified block. Correspondingly, the modification unit can also be determined as the second code segment corresponding to the original modified block. All first and second code segments corresponding to the first patch can be obtained using the same method. In other embodiments, to reduce the workload of a single execution by the agent and improve the agent's execution efficiency, such as... Figure 2 and Figure 3 As shown in the "splitting" step of the "preprocessing" process, the first patch can be split into multiple modified blocks (defined as original modified blocks). Specifically, the modified blocks contained in the first patch can be identified based on the identifier characters of the modified blocks (such as "@@"); and these modified blocks can be extracted from the first patch to obtain multiple original modified blocks. Deep learning models are significantly better at processing code than at processing modified blocks; therefore, as... Figure 2 and Figure 3 : As shown in "conversion", the original change block can be converted into a custom change block. Among them, as shown in Figure 2 and Figure 3 : The custom change block includes: the first code segment and the second code segment restored from the original change block, without including other information in the original change block. In this embodiment, the agent can round the first patch to the target software of the second version in batches according to the change block granularity, that is, round the content of one change block in each batch. Among them, the custom change block converted from the aforementioned original change block can be expressed as: <<<<<<<<<<<<<<<<<<<<<<<<<< / / Separator if (flags&ISO_DOTUSEC) { len = sprintf(p, s, "%06ld"); } / / First code segment ========================== / / Separator if (flags&ISO_DOTUSEC) { - len = sprintf(p, s, "%06ld"); / / Deleted code line + len = sprintf(p, s, "%06"Id64); / / Newly added code line } / / Second code segment In this embodiment, the first patch includes multiple original change blocks. The aforementioned step 101 can be implemented as: obtaining the first code segment and the second code segment corresponding to each of the multiple original change blocks. Among them, the first code segment corresponding to the original change block is the original code of the target software of the first version described by the original change block. The second code segment corresponding to the original change block is the code after modifying the target software of the first version described by the original change block.
[0026] In some embodiments, multiple original change blocks can be pre-converted into multiple custom change blocks. Then, the first code segment and the second code segment corresponding to the corresponding original change block can be read from each custom change block, which helps to improve the efficiency of obtaining the first code segment and the second code segment, and further helps to improve the subsequent patch rounding efficiency.
[0027] In other embodiments, multiple original change blocks can be converted into multiple custom change blocks online. Among them, the first code segment and the second code segment in each custom change block are the first code segment and the second code segment restored from the corresponding original change block. This embodiment does not require preprocessing of the patch, which can reduce the storage cost of the custom change block.
[0028] This embodiment breaks down the patch into multiple modification blocks, providing support for subsequent batch deployment of the patch to the target software in the second version using an agent at the block level. Deploying the patch in batches at the block level reduces the number of tokens processed by the agent per run, thereby lowering the time and cost of inference. Furthermore, this embodiment converts the original modification blocks into custom modification blocks containing only code. The data subsequently input into the agent is more aligned with the processing capabilities of the deep learning model upon which the agent relies, contributing to improved inference accuracy.
[0029] Since the first code segment is the original code of the target software before modification in the first version corresponding to the first patch, it can provide reference information for locating the code that needs to be modified from the source code of the target software in the second version. This embodiment introduces an agent to perform code retrieval on the source code of the target software in the second version. For ease of description, the agent performing the code retrieval is defined as the code retrieval agent. The prompt input to the code retrieval agent may include natural language instructing the agent to identify the code segment that needs to be modified from the source code and the location information of the code segment to be modified in the source code. The prompt input to the code retrieval agent may also include the format instructing the agent to return the code segment that needs to be modified.
[0030] The prompt can be pre-set. For example, in some embodiments, the prompt input to the code retrieval agent could be something like, "Please help me pinpoint the exact location in the source code where the change block should be applied or entered, and please place the matched original code (which must be strictly extracted from the source code) in..." <origin> and< / origin> Between tags. In some embodiments, the prompts input to the code retrieval agent may also include: reminders of precautions for the code retrieval agent, and / or, reference information provided to the code retrieval agent for solving specific problems. For example, prompts may include: "You can refer to the following methods to handle this problem: 1. If possible, provide a complete code snippet at the function or class level; 2. You must ensure that every character returned (including indentation, blank lines, tabs, spaces, etc.) is completely consistent with the source code; 3. [Important] If the code inferred from the diff hunk conflicts with the original source code, the result should be as close to the original source code as possible, rather than following the diff hunk; 4. [Important] If necessary, you should adjust the way the diff hunk is interpreted to fit the original source code." and / or prompts may also include "Precautions: 1. The found code must be completely consistent with the original source code; 2. Do not directly apply (port) the modifications of the diff hunk to the source code—we will handle this step later; 3. Do not add any extra content, including indentation, spaces, blank lines, etc.; 4. Do not add extra characters or tags around the code," etc.
[0031] Accordingly, such as Figure 2 As shown, the source code of the first code segment, the second version of the target software, and the prompt words corresponding to the code retrieval agent (defined as the first prompt words) can be used. Figure 2 (Not shown), input to the code retrieval agent. Accordingly, in step 102, the code retrieval agent, guided by the first prompt, can determine the code segment corresponding to the first code segment (defined as the third code segment) and the position information (defined as the first position information) of the third code segment in the first source code from the first source code, based on the first code segment and the source code of the second version of the target software (defined as the first source code). The first code segment corresponds to code in the first source code, and this code is the third code segment. In the embodiment where the first patch is rolled out to the second version of the target software in batches at the granularity of the modification block, for the modification block of the first round, the corresponding source code is the initial source code of the second version of the target software obtained from the code repository (i.e., Figure 2 and Figure 3 (The "initial source code" in the text).
[0032] To ensure the accuracy of the third code segment determined by the code retrieval agent, engineering verification can be performed on the third code segment. Specifically, a string matching method can be used to search for the third code segment in the first source code. If the third code segment is found in the first source code, it means that the third code segment has passed the engineering verification. If the third code segment is not found in the first source code, it means that the third code segment does not completely come from the first source file, and there may be some characters automatically added or deleted by the code retrieval agent, that is, the third code segment has failed the engineering verification. If the third code segment fails the engineering verification, step 102 can be executed again; or, based on the aforementioned first prompt word, a reason for the third code segment failing the engineering verification can be added to obtain a new prompt word, and under the guidance of the new prompt word, the operation of determining the third code segment corresponding to the first code segment in the first source code and the position information of the third code segment in the first source code in step 102 can be executed again until the third code segment passes the engineering verification.
[0033] The third code segment passed engineering verification, indicating that the code requiring modification in the first source code has been accurately located. The modified code corresponding to the first patch can then be integrated into the target software of the second version. During the continuous evolution of the software codebase across different versions, structural differences exist, including but not limited to changes in function interfaces, control flow refactoring, data structure adjustments, macro definition replacements, and compiler dependency migrations. Code originating from the first version is not entirely compatible with code from other versions. Therefore, the modified code in the first patch needs to be rewritten based on the code characteristics of the target software of the second version.
[0034] Therefore, the programming language of the third code segment can be analyzed to determine the target programming language used by the third code segment. The type of programming language may include: C, Python, Java, C++, etc. Figure 2 As shown, the third code segment and the first position information can also be input into the target language agent. Accordingly, as... Figure 1 Step 103 and Figure 2 As shown in "Rewriting the Second Code Segment," a target language agent, guided by a second prompt, can program the second code segment using the target programming language to obtain a new code segment (defined as the fourth code segment). The second prompt includes natural language instructions that direct the target language agent to adapt the second code segment to the first source code. For example, the second prompt might include phrases like, "You need to modify the modified code in the modification block to adapt it to the second version of the source code."
[0035] Furthermore, such as Figure 1 Step 104 and Figure 2As shown in the "Fourth Code Segment Round," the target language agent, guided by the second prompt, can return the fourth code segment to the first source code based on the third code segment and the first position information. Specifically, guided by the second prompt, the target language agent can delete the third code segment from the first source code based on the third code segment and the first position information, and add the fourth code segment to the first position information location in the first source code.
[0036] In this embodiment, the code retrieval agent focuses on finding the semantically equivalent third code segment and its location in the source code of the target version based on the first code segment; the target language agent focuses on rewriting the second code segment into a fourth code segment according to the language specification of the target version and completing the patch round. This achieves a separation of responsibilities among expert agents, with concise prompts and single responsibilities, avoiding the logical confusion and illusions caused by a single large model undertaking multiple tasks. On the other hand, this embodiment uses the code retrieval agent to locate the third code segment in the target project awaiting a round that corresponds to the original modified semantics, and then the target language agent rewrites the patch logic based on this context to be environment-oriented (generating the fourth code segment), thereby generating code adapted to the target project. This resolves patch round conflicts caused by version evolution and helps improve the success rate of automatic patch regeneration.
[0037] This application studies the performance of agents in patching round tasks and finds that deep learning models such as LLM, which agents rely on, are prone to "illusions"—such as incorrectly adjusting code indentation, introducing unused header files, or adding redundant logic. These problems are difficult to completely avoid, therefore it is necessary to introduce engineered constraint mechanisms to verify the compliance of intermediate results during the code generation process of the language agent. However, integrating the checking logic of all programming languages into a single general agent would result in highly complex and tightly coupled logic, significantly increasing the system's understanding cost and long-term maintenance difficulty. Therefore, this application's embodiments adopt a multi-expert agent architecture based on programming language type, where each programming language is handled by a dedicated "language expert," i.e., a dedicated language agent. In this way, the prompts and generation logic of each language agent can be optimized for the specific language's syntax, idioms, and context, reducing errors caused by cross-language confusion, thereby reducing the risk of illusions and helping to improve round accuracy. Accordingly, such as Figure 3 As shown, embodiments of this application can provide multiple language agents, each dedicated to processing the programming language it supports. For example... Figure 3 As shown, language intelligent agents can include: C language intelligent agents, Python language intelligent agents, Java language intelligent agents, etc. The target language intelligent agent is one of these language intelligent agents.
[0038] This application employs a multi-agent architecture, including code retrieval agents and multi-language agents, to collaboratively implement patching rounds. Each agent performs its specific function and can execute according to a fixed sequence. However, this architecture, which executes according to a fixed sequence, lacks autonomous collaboration capabilities, such as determining the order of execution. Therefore, in some embodiments of this application, such as... Figure 3 As shown, a decision-making agent is introduced. This agent coordinates and schedules the expert agents, ensuring their responsibilities are aligned. The decision-making agent can dynamically schedule the order in which expert agents are invoked based on the task status, avoiding blind, pipelined execution.
[0039] The decision-making agent is configured with system prompts. These system prompts are pre-defined instructions by the system designer, defining the agent's role, capability boundaries, behavioral norms, and task objectives. They are implicitly injected before each interaction with the model, invisible (or semi-transparent) to the user, but profoundly influence the model's output style and logic. The decision-making agent's system prompts include natural language instructions to apply the first patch to the first source code, as well as identifiers of the tools involved in the application process. For example, the system prompts could be: "You are a decision expert, and you need to apply the patch I provide to the project code. This process will involve resolving some conflicts. You have the following tools available: Git tools, file read / write tools, content evaluation tools, etc." The system prompts may also include the calling methods and paths for each tool. Figure 3 The illustrations only depict tools including Git, file reading tools, and content evaluation tools, and are not intended to limit the scope of the tool. Git is a distributed version control system created to manage Linux kernel development. Its core goal is to efficiently and securely track code change history. Git can be used to record every code modification (e.g., who changed what, when), provide a defined baseline version, and serve as the starting point for patch generation and verification.
[0040] In addition to system prompts, the decision-making agent can also pre-set user prompts. User prompts are input text dynamically provided by the user or upstream modules, describing the current specific task or query content. They represent a specific request, triggering the agent to perform a specific operation. For ease of description, user prompts are defined as third prompts. In this embodiment, the third prompt is used to instruct the decision-making agent to call the code retrieval agent. Accordingly, the third prompt includes natural language instructing the decision-making agent to call the code retrieval agent. For example, the third prompt might include, "You will need to call the code retrieval agent next, using a toolcall method and the call path is abcd." "abcd" represents the specific call path.
[0041] Accordingly, before step 102, "using the code retrieval agent, guided by the first prompt word, to determine the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code based on the first code segment and the first source code of the target software of the second version," the first code segment, the second code segment, and the first source code can be input into the decision agent; further, such as Figure 3 As indicated by the "Invocation" button, the decision-making agent, guided by its system prompt and a predefined third prompt, can invoke the code retrieval agent; and input the first code segment, the first source code, and the first prompt into the code retrieval agent. Specifically, the decision-making agent, guided by its system prompt and the predefined third prompt, can invoke a file read / write tool to read the first source code; then, it invokes the code retrieval agent; and inputs the first code segment, the first source code, and the first prompt into the code retrieval agent.
[0042] Subsequently, guided by the first prompt, the code retrieval agent can determine the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the target software of the second version; and return the third code segment and the first position information to the decision agent.
[0043] This embodiment introduces a decision-making agent to dynamically schedule the calling order of multiple expert agents (such as code retrieval agents and multi-language expert agents), thereby realizing the coordinated work of multiple expert agents and avoiding blind pipeline execution of multiple expert agents.
[0044] To ensure the accuracy of the third code segment determined by the code retrieval agent, engineering verification can be performed on the third code segment. Specifically, a string matching method can be used to search for the third code segment in the first source code. If the third code segment is found in the first source code, it means that the third code segment has passed the engineering verification, and the code retrieval agent can return the third code segment and the first location information to the decision agent. If the third code segment is not found in the first source code, it means that the third code segment does not completely come from the first source file, and there may be some characters automatically added or deleted by the code retrieval agent, that is, the third code segment has not passed the engineering verification. If the third code segment fails the engineering verification, step 102 can be executed again; or, based on the aforementioned first prompt word, a reason for the third code segment failing the engineering verification can be added to obtain a new prompt word, and under the guidance of the new prompt word, the operation of determining the third code segment corresponding to the first code segment in the first source code and the location information of the third code segment in the first source code in step 102 can be executed again until the third code segment passes the engineering verification.
[0045] If the third code segment passes engineering verification, it indicates that the code requiring modification in the first source code has been accurately located. The code retrieval agent can then return the third code segment and the first location information to the decision-making agent for further scheduling. In this embodiment, before returning the located code to the decision-making agent, a string matching method is used to verify whether the located code originates from the source code. If the code is found in the source code, the process proceeds to the next step. This ensures the accuracy of the third code segment determined by the code retrieval agent, thereby improving the accuracy of subsequent patch rounds.
[0046] When the decision-making agent receives the third code segment and the first location information returned by the code retrieval agent, it can determine that the code retrieval was successful and then trigger the decision-making agent to make the next scheduling decision.
[0047] Accordingly, the decision-making agent can analyze the programming language used in the third code segment to determine the target programming language. Then, from multiple language agents, it can determine the language agent to be called (i.e., the one to be called) for the next step—the target language agent. Afterward, the decision-making agent can input the second and third code segments, the first position information, and the second prompt word into the target language agent.
[0048] Accordingly, the target language agent can rewrite the second code segment using the target programming language under the guidance of the second prompt word, thus obtaining the aforementioned fourth code segment.
[0049] Because different programming languages differ significantly in syntax, semantics, standard libraries, and idiomatic patterns, general-purpose agents are prone to confusing syntax rules when handling cross-language tasks, leading to incorrect parsing or the generation of invalid code. This embodiment first identifies the programming language of the third code segment and then routes it to a dedicated language agent, ensuring that subsequent processing is based on the correct language model and rule engine, thereby improving the accuracy of the rewritten fourth code segment.
[0050] This study investigated the reasoning process of the Agent and found that if only simplified task instructions (such as "Please rewrite this code") are passed to the target language agent (the executing agent), while discarding the existing code analysis and location information in the decision agent's context, the target language agent will lack sufficient background and is prone to illusions or errors. It will also force the target language agent to re-parse the original code or patch, leading to redundant computation. However, by providing the target language agent with the parts of the decision agent's context window that are strongly related to the current task (code rewriting and patching rounds), the target language agent can directly generate accurate results based on the complete context, reducing the number of retries and improving the success rate of patching rounds. Furthermore, it avoids redundant information reconstruction and significantly reduces token consumption.
[0051] Based on this, before using the decision-making agent to input the second prompt word into the target language agent, the current context window information of the decision-making agent (defined as the original context window information) can also be obtained. The context window information of the decision-making agent refers to the working memory used by the decision-making agent in the current inference cycle to store its interactions with the environment, including: input information (input data and instructions, etc.), tool return results, its own inference chain, and task planning drafts, etc. In this embodiment, the tool return results may include: the third code segment and the first position information returned by the code retrieval agent; the self-inference chain refers to the self-reasoning process completed by the decision-making agent based on the system prompt word and the third prompt word. Input information may include: the first code segment, the second code segment, and the third prompt word, etc.
[0052] Furthermore, based on the original context window information and the prompt word template corresponding to the target programming language, prompt words (i.e., second prompt words) for the target language agent can be generated. The second prompt words include some or all of the information from the original context window information.
[0053] In this embodiment, the context window information of the upstream agent is selectively passed as prompt words to the downstream execution agent (i.e., the target language agent). On the one hand, the target language agent can generate more accurate results based on the context information, reduce the number of retries, and improve the patch synthesis efficiency. On the other hand, it can also avoid repeated parsing of the original code (such as the first code segment, the second code segment, etc.), which helps to reduce token consumption.
[0054] Specifically, the system prompts in the original context window information can be modified to the system prompts for the target language agent within the prompt template to obtain the target context window information. For ease of description, the system prompts for the aforementioned decision agent are defined as the first system prompts; and the system prompts for the target language agent are defined as the second system prompts. The second system prompts include: natural language instructions to the target language agent to round the first patch to the first source code, and identifiers of the tools involved in the rounding process. For example, for a C language agent, the second system prompt could be: "You are a C language code rounding expert. You need to round the patch I provide into the project code. This process will involve resolving some conflicts. You have the following tools available:...".
[0055] The prompt template may also include: natural language instructions to the target language agent to adapt the second code segment to the first source code, and corresponding programming considerations for the target programming language. Accordingly, based on the target context window information, the natural language instructions to the target language agent to adapt the second code segment to the first source code, and the corresponding programming considerations for the target programming language in the prompt template can be added to obtain the second prompt. The programming considerations may include: do not include additional header files, do not add additional blank lines, do not add additional curly braces, maintain consistent indentation with the project code, etc. The natural language instructions to the target language agent to adapt the second code segment to the first source code, and the corresponding programming considerations for the target programming language, are both obtained from the prompt template.
[0056] This embodiment modifies the original context information to obtain prompt words that are adapted to the programming language habits of the target language agent, making the prompt words more accurate and thus helping to improve the accuracy of subsequent code rewriting and patching rounds.
[0057] Since the second prompt word encompasses the context window information of the decision agent, it contains the aforementioned first code segment, second code segment, third code segment, and the location information (i.e., first location information) of the third code segment in the first source code. Therefore, the decision agent can input the second prompt word into the target language agent, thereby inputting the location information (i.e., first location information) of the first code segment, second code segment, third code segment, and the third code segment in the first source code into the target language agent.
[0058] Furthermore, guided by the second prompt word, the target language agent can delete the third code segment from the first source code based on the first position information; and add the fourth code segment to the first source code based on the first position information, thereby returning the first patch to the second version of the target software.
[0059] In an embodiment where the first patch is rolled out to the target software of the second version in batches at the granularity of modification blocks, one modification block from the first patch can be rolled out each time. The process of rolling out each modification block to the target software of the second version is the same. The rolling process is illustrated below using any original modification block in the first patch as an example. For ease of description, any original modification block is defined as the target original modification block. Accordingly, after the aforementioned decision-making agent calls the code retrieval agent in the current batch, it can input the first code segment and the first source code from the target original modification block into the code retrieval agent.
[0060] In the aforementioned embodiment of converting the original modified block into a custom modified block, the decision-making agent can input the custom modified block (defined as the target custom modified block) corresponding to the target original modified block and the first source code into the code retrieval agent. Further, guided by the first prompt, the code retrieval agent can determine, based on the first code segment in the target original modified block and the first source code, the third code segment corresponding to the first code segment in the target original modified block, and the first position information of the third code segment in the first source code.
[0061] Accordingly, the original context window information generated by the decision-making agent during the round corresponding to the original target modification block can be obtained; and based on the original context window information generated during the round corresponding to the original target modification block and the prompt word template corresponding to the target programming language, a second prompt word corresponding to the original target modification block can be generated.
[0062] Furthermore, the decision-making agent can invoke the target language agent and input the second prompt word corresponding to the original target modification block into the target language agent. Guided by the second prompt word, the target language agent can then rewrite the second code segment in the original target modification block using the target programming language to obtain the fourth code segment corresponding to the original target modification block. Furthermore, guided by the second prompt word, the target language agent can also, based on the third code segment corresponding to the first code segment in the original target modification block and the first position information of that third code segment in the first source code, return the fourth code segment corresponding to the original target modification block to the first source code to obtain the second source code corresponding to the original target modification block.
[0063] In this embodiment, the first source code refers to the source code of the second version of the target software before the target original modification block is rounded up; the second source code refers to the source code of the second version of the target software after the target original modification block is rounded up. Specifically, for two adjacent round batches (defined as the first batch and the second batch, with the first batch preceding the second batch), the first source code corresponding to the second batch is the second source code corresponding to the first batch. In this embodiment, the decision-making agent can invoke the Git tool to determine the first source code corresponding to the target original modification block.
[0064] This embodiment uses modification blocks as the granularity, and delivers the first patch to the target software of the second version in batches. This reduces the amount of data processed by the deep learning model that the agent relies on each time, reduces the inference burden of the deep learning model, and improves the patch delivery speed. On the other hand, the agent performs inference on a single modification block (such as a custom modification block) each time, which reduces information interference from other modification blocks, thereby improving the agent's inference accuracy and thus improving the patch delivery accuracy.
[0065] In a patch round scenario, patching rounds must conform to project maintenance specifications. Code changes introduced in a round must meet pre-defined maintenance standards, and the scope of modification must not be expanded arbitrarily or irrelevant changes introduced. Therefore, after rounding the fourth code segment to the first source code based on the third code segment and the first location information, engineering methods can be used to obtain the current code change characteristics of the target software in the second version. Code change characteristics refer to a set of measurable indicators used to quantify or describe the semantic, structural, or scale attributes of a code modification. In a patch round scenario, it reflects the evolutionary differences of the target software in the second version before and after receiving the patch, providing a basis for evaluating round quality. Code change characteristics may include: the code similarity of the target software in the second version before and after receiving the patch and / or the scale of code changes in the target software in the second version before and after receiving the patch, etc.
[0066] In some embodiments, code change features include code similarity. Accordingly, when obtaining the current code change features of the target software in the second version, the code similarity between the first source code and the second source code can be calculated. In embodiments where patch rounds are performed at the patch granularity, the first source code refers to the source code before the first patch is rounded to the target software in the second version; the second source code refers to the source code after the first patch is rounded to the target software in the second version, and is defined as the second source code. In embodiments where patches are rounded to the target software in batches at the modification block granularity, for the modification block (such as a custom modification block) currently rounded to the target software in the second version, the first source code refers to the source code before the custom modification blocks of the current batch are rounded to the target software in the second version; the second source code refers to the source code after the custom modification blocks of the current batch are rounded to the target software in the second version. For adjacent first and second batches, the first source code corresponding to the second batch is the second source code corresponding to the first batch. In this embodiment, the code change features include code similarity between the first source code and the second source code.
[0067] In some embodiments, the edit distance, such as the Levenshtein distance, between the first source code and the second source code can be calculated as the code similarity between them. The Levenshtein distance refers to the minimum number of single-character edit operations required to convert one string into another. Edit operations include inserting a character, deleting a character, and replacing a character. In this embodiment, the first source code and the second source code can be considered as strings. The Levenshtein distance can be expressed as the minimum number of single-character edit operations required to convert the first source code into the second source code. The edit distance is inversely correlated with code similarity; that is, the smaller the edit distance, the higher the code similarity.
[0068] In other embodiments, the first source code can be converted into an Abstract Syntax Tree (AST) (defined as the first AST); and the second source code can be converted into an AST (defined as the second AST). Here, an AST is a tree-like representation of the syntactic structure of a programming language. Then, the similarity between the first AST and the second AST can be calculated as the code similarity between the first source code and the second source code.
[0069] When calculating the similarity between the first and second ASTs, the ASTs can be viewed as graphs, and a Graph Neural Network (GNN) can be used to convert the first and second ASTs into embedding vectors respectively; the first AST is converted into a first embedding vector, and the second AST is converted into a second embedding vector. Then, the distance between the first and second embedding vectors can be calculated as the similarity between the first and second ASTs. The distance between the first and second embedding vectors is inversely correlated with the similarity between the first and second ASTs. That is, the smaller the distance between the first and second embedding vectors, the higher the similarity between the first and second ASTs.
[0070] This embodiment uses code similarity before and after a patch round as a code change feature. If the code similarity before and after a patch round is too low, it may mean that the language agent is experiencing "illusion" and introducing unnecessary logic. High similarity indicates that the modifications focus on necessary adjustments and do not disrupt the original control flow or data flow, thus meeting the conservative requirements of security patches. Therefore, using code similarity as a code change feature can provide a reliable basis for subsequent compliance verification of the round process.
[0071] In other embodiments, the code change feature includes the scale of the code change. Accordingly, the scale of the code change between the second source code and the first source code can be obtained. The scale of the code change can be represented by the number of lines of code that have changed in the second source code compared to the first source code. Accordingly, a string matching algorithm can be used to compare the first and second source codes line by line; and the number of lines that differ between the first and second source codes can be counted as the scale of the code change between the second and first source codes.
[0072] Using the scale of code changes as a compliance verification characteristic can quantify the actual amount of code modified in a patch round and determine whether it exceeds a reasonable range. A patch round should only contain the core fix logic of the original patch. If the number of lines or functions changed far exceeds the original patch, irrelevant changes may have been mixed in. Therefore, using the scale of code changes as a code change characteristic can provide a reliable basis for subsequent compliance verification of the round process.
[0073] In some other embodiments, the code change characteristics include code similarity and code change scale. For details on how to obtain code similarity and code change scale, please refer to the relevant content in the foregoing embodiments. This embodiment combines code similarity and code change scale as code change characteristics, which can measure the degree of code change from multiple perspectives and provide a more reliable basis for subsequent compliance verification of the round process.
[0074] After obtaining the current code change characteristics of the target software in the second version, the target language agent, guided by corresponding prompts, can perform compliance verification on the current round corresponding to the original target modification block based on the code change characteristics. The fourth prompt includes: natural language instructing the target language agent to perform compliance verification on the current round corresponding to the original target modification block, and compliance verification rules corresponding to the target programming language. The compliance verification rules include: compliance conditions for the code change characteristics. Guided by the fourth prompt, the target language agent can invoke a content evaluation tool to perform compliance verification on the current round corresponding to the original target modification block based on the code change characteristics.
[0075] Specifically, the target language agent can determine whether the code change features meet the set compliance conditions. If all code change features meet the set compliance conditions, the current round corresponding to the target original modified block is deemed to have passed the compliance check. Furthermore, if the current round corresponding to the target original modified block passes the compliance check, the target language agent can return a success message to the decision agent. Upon receiving the success feedback for the current round, the decision agent can select any original modified block from the remaining rounds as the next target original modified block, and input the first and second code segments corresponding to the next target original modified block into the code retrieval agent. The subsequent processing of the next target original modified block is the same as the processing of the target original modified block shown in the aforementioned embodiment, and will not be repeated here.
[0076] Accordingly, if all or some of the code change features do not meet the set compliance conditions, it is determined that the current round corresponding to the target original modified block has failed the compliance check. The target language agent can then return a failure message for the current round and the reason for the round failure to the decision agent. The reason for the round failure is determined by the target code change features that do not meet the compliance conditions. For example, if the target code change feature is code similarity, the reason for the round failure could be that the code similarity before and after the round is low. Or, if the target code change feature is the scale of the code change, the reason for the round failure could be that the number of lines of code changed before and after the round is too high.
[0077] Furthermore, the decision-making agent can call the code retrieval agent again, and input the reason for the round failure and the aforementioned first prompt word into the code retrieval agent. Guided by the first prompt word and the reason for the round failure, the code retrieval agent can then re-determine the third code segment corresponding to the first code segment in the target original modified block from the first source code, and the first position information of the third code segment corresponding to the first code segment in the target original modified block in the first source code, based on the first code segment and the first source code in the target original modified block. Subsequently, it can call the target language agent to rewrite the second code segment to obtain a new fourth code segment, and return the new fourth code segment to the first source code to obtain a new second source code, etc., until the second version of the target software meets the set compliance conditions in the current code change characteristics.
[0078] In the second version of the target software, if the current code change characteristics meet the set compliance conditions, the next round of the original change block can be processed, until multiple rounds of the original change block are completed.
[0079] In this embodiment, by performing compliance verification on the code change characteristics before and after the modified block round, the code changes introduced in the round are controlled within the preset maintenance range, which can reduce the possibility of the agent introducing illusions and further improve the accuracy of the patch round.
[0080] In some embodiments, after returning the fourth code segment corresponding to the target original modified block to the first source code, the target language agent can also obtain the second position information of the fourth code segment corresponding to the target original modified block in the second source code, and the line number of the fourth code segment corresponding to the target original modified block. Then, the target language agent can create a partial code snapshot for the second version of the target software based on the fourth code segment corresponding to the target original modified block, the second position information, the line number of the fourth code segment corresponding to the target original modified block, the third code segment corresponding to the first code segment in the target original modified block, and the first position information of the third code segment in the first source code.
[0081] A local code snapshot is an incremental snapshot, which is a structured record containing information about the differences between the second source code and a known baseline version (i.e., the first source code) and its related metadata. A local code snapshot may include: a baseline identifier and incremental change content. The baseline identifier refers to the starting point of the current round, i.e., the identifier of the snapshot corresponding to the first source code. The incremental change content may include: the third code segment corresponding to the target original modified block, the first position information of this third code segment in the first source code, the fourth code segment corresponding to the target original modified block, and the position information (i.e., the second position information) of this fourth code segment in the second source code.
[0082] In an embodiment of compliance verification of the turn process corresponding to the original target modification block, compliance verification can be performed on the turn process corresponding to the original target modification block before creating a local code snapshot for the second version of the target software. For details, please refer to the relevant content of the foregoing embodiment.
[0083] After multiple rounds of the original modification blocks are completed, the target language agent can generate a patch (defined as the second patch) for the target software to be rolled to the second version, based on the local code snapshots corresponding to each of the original modification blocks. Specifically, the target language agent can determine the location information of the third code segment corresponding to each original modification block in the initial source code of the second version of the target software, according to the chronological order of the multiple rounds of the original modification blocks, based on the local code snapshots corresponding to each of the original modification blocks; and determine the location information of the fourth code segment corresponding to each original modification block in the final modified source code of the second version of the target software, according to the reverse chronological order of the multiple rounds of the original modification blocks, based on the local code snapshots corresponding to each of the original modification blocks. The final modified source code is the second source code corresponding to the original modification block that was rolled in the last round.
[0084] Specifically, for the first original modification block that completes the first round among multiple original modification blocks (defined as the first original modification block), the target language agent can use a local code snapshot corresponding to the first original modification block to obtain the third code segment (denoted as third code segment 1) corresponding to the first original modification block, the first position information (denoted as first position information 1) of the third code segment 1 in the first source code (i.e., the initial source code of the second version of the target software, denoted as first source code 1) corresponding to the first original modification block, the fourth code segment (denoted as fourth code segment 1) corresponding to the first original modification block, and the second position information of the fourth code segment 1 in the second source code (denoted as second source code 1) corresponding to the first original modification block; furthermore, the first position information 1 can be determined as the position information of the third code segment 1 in the initial source code.
[0085] For the second completed round of multiple original modification blocks (defined as the second original modification block), the target language agent can use a local code snapshot corresponding to the second original modification block to obtain the first position information (denoted as first position information 2) of the third code segment (denoted as third code segment 2) corresponding to the second original modification block, the fourth code segment (denoted as fourth code segment 2) corresponding to the second original modification block, and the second position information of the fourth code segment 2 in the second source code (denoted as second source code 2) corresponding to the second original modification block. Furthermore, the target language agent can use the first position information 1, the second position information 2, the line number of the third code segment 1, the line number of the fourth code segment 1, and the first position information 2 to determine the position information of the third code segment 2 in the initial source code (i.e., the first source code 1).
[0086] For any original modified block after the first original modified block (denoted as original modified block i), the target language agent can determine the position information of the third code segment corresponding to original modified block i in the initial source code based on the first position information of each of the original modified blocks 1 to (i-1) completed before original modified block i, the second position information of each of the original modified blocks 1 to (i-1), the line number of the third code segment corresponding to each of the original modified blocks 1 to (i-1), and the line number of the fourth code segment corresponding to each of the original modified blocks 1 to (i-1). Using the same method, the position information of the third code segment corresponding to each original modified block i in the initial source code can be determined.
[0087] For the original modified block (defined as original modified block N) that is the last completed round among multiple original modified blocks, the target language agent can use the local code snapshot corresponding to the original modified block N to obtain the third code segment (denoted as third code segment N), the first position information of the third code segment N in the first source code corresponding to the original modified block N (denoted as first position information N), the fourth code segment (denoted as fourth code segment N), and the second position information of the fourth code segment N in the second source code corresponding to the original modified block N (denoted as second source code N, i.e., the final modified source code) (denoted as second position information N). Furthermore, the second position information N can be determined as the position information of the fourth code segment N in the final modified source code.
[0088] For any original modified block (denoted as original modified block j) before the last completed original modified block N, the target language agent can use the first position information of each of the original modified blocks (j+1) to N completed after original modified block j, the second position information of each of the original modified blocks (j+1) to N, the line number of the third code segment of each of the original modified blocks (j+1) to N, and the line number of the fourth code segment of each of the original modified blocks (j+1) to N to determine the position information of the fourth code segment j corresponding to the original modified block j in the final modified source code.
[0089] Furthermore, for any original modified block X, the target language agent can generate the target modified block corresponding to the original modified block X according to the set standard modified block format, based on the third code segment corresponding to the original modified block X, the line number of the third code segment, the position information of the third code segment in the initial source code, the fourth code segment corresponding to the original modified block X, the line number of the fourth code segment, and the position information of the fourth code segment in the final modified source code.
[0090] Furthermore, the target language agent can generate a second patch according to the target modification blocks corresponding to each of the multiple original modification blocks X, based on the set patch format. The set patch format can be a patch format with an RFC 2822 mail standard header and a Unix uniform difference format.
[0091] In this embodiment, the target language agent generates patches to be rolled back to the second version of the target software based on the local code snapshots corresponding to each original modified block after it has been rolled back to the second version of the target software. Since the rolling process corresponding to each local code snapshot is compatible with the second version of the target software and has high accuracy, the generated patches are also compatible with the second version of the target software and have high accuracy. Subsequently, the second patch can be directly applied to the second version of the target software in the production environment, thus achieving patch rolling for the second version of the target software in the production environment.
[0092] It should be noted that the execution subject of each step of the method provided in the above embodiments can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 101 and 102 can be device A; or the execution subject of step 101 can be device A, and the execution subject of step 102 can be device B; and so on.
[0093] Furthermore, some processes described in the above embodiments and accompanying drawings include multiple operations that appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear herein, or they may be executed in parallel. The operation numbers, such as 101, 102, etc., are merely used to distinguish different operations and do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel.
[0094] This application also provides a patch round system, such as Figure 2 and Figure 3 As shown, the patching round system may include a code retrieval agent and a target language agent. The code retrieval agent is used to obtain a first code segment reconstructed based on the first patch; the first code segment is the original code of the first version of the target software corresponding to the first patch; and, guided by a first prompt, to determine a third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the second version of the target software.
[0095] A target language agent is used to obtain a second code segment restored based on the first patch; the second code segment is the modified code of the first version of the target software corresponding to the first patch; and, guided by a second prompt, rewrites the second code segment using the target programming language to obtain a fourth code segment; the target programming language is the programming language used by the third code segment; and, guided by the second prompt, returns the fourth code segment to the first source code based on the third code segment and the first position information.
[0096] In some embodiments, such as Figure 3 As shown, the patch round-robin system may further include a decision agent. The decision agent, guided by a first system prompt and a predefined third prompt, invokes a code retrieval agent. The first system prompt includes natural language instructing the decision agent to round the first patch to the first source code and identifiers of tools involved in the round-robin process. The third prompt includes natural language instructing the decision agent to invoke the code retrieval agent. The system also inputs the first code segment, the first source code, and the first prompt into the code retrieval agent, so that the code retrieval agent, guided by the first prompt, can determine, from the first source code of the second version of the target software, the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code.
[0097] Accordingly, the code retrieval agent is also used to: after determining the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the second version of the target software, return the third code segment and the first position information to the decision agent.
[0098] In some embodiments, the decision agent is further configured to: after the code retrieval agent returns the third code segment and the first location information to the decision agent, analyze the programming language used by the third code segment to determine the target programming language; and determine the language agent to be called from among multiple language agents as the target language agent corresponding to the target programming language; and input the second prompt word into the target language agent.
[0099] In some embodiments, the patching round system may further include: a prompt word generation module. The prompt word generation module is configured to: obtain the original context window information of the decision agent in the current state; and generate a second prompt word based on the original context window information and a prompt word template corresponding to the target programming language.
[0100] In some embodiments, for a target original modification block among multiple original modification blocks, the target language agent is further configured to: obtain second location information of the fourth code segment corresponding to the target original modification block in the second source code; create a local code snapshot for the second version of the target software based on the fourth code segment corresponding to the target original modification block, the second location information, the third code segment corresponding to the first code segment in the target original modification block, and the first location information of the third code segment corresponding to the first code segment in the target original modification block in the first source code; and after the multiple original modification blocks are completed, generate a second patch for the target software to be rolled to the second version based on the local code snapshots corresponding to each of the multiple original modification blocks.
[0101] In some embodiments, the target language agent is further configured to acquire the current code change characteristics of the second version of the target software; guided by a fourth prompt word, it performs compliance verification on the current next round corresponding to the original target modification block based on the code change characteristics; the fourth prompt word includes: natural language instructing the target language agent to perform compliance verification on the current next round corresponding to the original target modification block and compliance verification rules corresponding to the target programming language; if the current next round corresponding to the original target modification block passes the compliance verification, the operation of creating a local code snapshot for the second version of the target software is executed.
[0102] In other embodiments, the patch round system may further include a preprocessing module. The preprocessing module is configured to: split the first patch into multiple original modification blocks; and for any given original modification block, convert it into a custom modification block; the custom modification block includes a first code segment and a second code segment corresponding to any given original modification block.
[0103] In some other embodiments, the patching round system may further include a verification module. The verification module is configured to: search for a third code segment in the first source code using a string matching method before the code retrieval agent returns the third code segment and the first location information to the decision agent; if the third code segment is found in the first source code, then allow the code retrieval agent to perform the operation of returning the third code segment and the first location information to the decision agent.
[0104] Accordingly, embodiments of this application also provide a computer-readable storage medium storing computer instructions, which, when executed by one or more processors, cause one or more processors to perform the steps in the patching round method provided in the foregoing embodiments.
[0105] Computer-readable storage media include volatile or non-volatile or a combination thereof, and may be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital video disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transfer medium.
[0106] This application also provides a computer program product, including a computer program that, when executed by one or more processors, causes the one or more processors to perform the steps in the patching round method provided in the foregoing embodiments. For specific implementation details of the computer program product, please refer to the relevant descriptions in the foregoing embodiments.
[0107] The computer program product should understand that each or a combination of the above-described method flow can be implemented by a computer program or instructions. Furthermore, these computer programs or instructions can be applied to the processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device, enabling the processor of the general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to function as an apparatus for implementing the corresponding functions in the above-described method embodiments.
[0108] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4 As shown, the electronic device includes a memory 40a and a processor 40b. The memory 40a is used to store computer programs and can be configured to store various other data to support operation on a computing platform. Examples of this data include instructions for any application or method used to operate on the electronic device, data structures, contact data, phone book data, messages, pictures, videos, etc.
[0109] Processor 40b is coupled to memory 40a for executing computer programs to perform the steps in the patching round methods provided in the foregoing embodiments. Specific implementation details of each step can be found in the relevant descriptions of the foregoing embodiments, and will not be repeated here.
[0110] In some alternative implementations, such as Figure 4 As shown, the electronic device may also include optional components such as a communication component 40c, a power supply component 40d, a display component 40e, and an audio component 40f. Figure 4 The diagram only shows some components and does not mean that the electronic device must contain them. Figure 4 The inclusion of all components does not imply that an electronic device can only include... Figure 4 The components shown.
[0111] in addition, Figure 4 The components within the dashed box are optional, not mandatory, and their specific requirements depend on the form factor of the electronic device. The electronic device in this embodiment can be a desktop computer, laptop computer, mobile phone, or IoT device; it can also be a traditional server, cloud server, or server cluster, or other server equipment.
[0112] In this embodiment, the memory is used to store computer programs and can be configured to store various other data to support operation on its host device. The processor can execute the computer programs stored in the memory to implement corresponding control logic. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0113] In the embodiments of this application, the processor can be any hardware processing device capable of executing the above-described method logic. Optionally, the processor can be a central processing unit (CPU), a graphics processing unit (GPU), or a microcontroller unit (MCU); it can also be a programmable device such as a field-programmable gate array (FPGA), a programmable array logic (PAL), a general array logic (GAL), or a complex programmable logic device (CPLD); or it can be an advanced RISC machine (ARM) or a system on chip (SoC), etc., but is not limited thereto.
[0114] In this embodiment, the communication component is configured to facilitate wired or wireless communication between its host device and other devices. The device hosting the communication component can access wireless networks based on communication standards, such as 2G or 3G, 4G, 5G, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.
[0115] In embodiments of this application, the display component may include a liquid crystal display (LCD) and a touch panel (TP). If the display component includes a touch panel, the display component can be implemented as a touchscreen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation.
[0116] In this embodiment, a power supply component is configured to provide power to various components of the device in which it resides. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply component resides.
[0117] In embodiments of this application, the audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), which is configured to receive external audio signals when the device containing the audio component is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals can be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals. For example, in devices with voice interaction capabilities, voice interaction with the user can be achieved through the audio component.
[0118] It should be noted that the terms "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent a chronological order, nor do they limit "first" and "second" to different types.
[0119] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the aforementioned element.
[0120] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A patching round method, characterized in that, include: Obtain the first and second code segments restored based on the first patch; The first code segment is the original code of the target software of the first version corresponding to the first patch; The second code segment is the modified code of the target software of the first version corresponding to the first patch; Guided by a first prompt word, the code retrieval agent determines the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the second version of the target software. Guided by the second prompt word, the second code segment is rewritten using the target programming language by the target language agent to obtain the fourth code segment; the target programming language is the programming language used by the third code segment. Guided by the second prompt word, the target language agent uses the third code segment and the first position information to return the fourth code segment to the first source code.
2. The method according to claim 1, characterized in that, Before using a code retrieval agent, guided by a first prompt word, to determine the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code of the second version of the target software, the method further includes: Guided by a first system prompt and a predefined third prompt, the decision agent invokes the code retrieval agent. The first system prompt includes natural language indicating that the decision agent should return the first patch to the first source code, as well as identifiers of the tools involved in the return process. The third prompt includes natural language indicating that the decision agent should invoke the code retrieval agent. The first code segment, the first source code, and the first prompt word are input into the code retrieval agent so that the code retrieval agent, guided by the first prompt word, can determine the third code segment and the first location information from the first source code of the second version of the target software. After using a code retrieval agent to determine the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code from the first source code of the second version of the target software, the method further includes: The code retrieval agent uses the code to return the third code segment and the first location information to the decision-making agent.
3. The method according to claim 2, characterized in that, Before writing the second code segment using the target programming language under the guidance of the second prompt word using a target language agent that supports the target programming language, the method further includes: Obtain the current original context window information of the decision-making agent; The second prompt word is generated based on the original context window information and the prompt word template corresponding to the target programming language.
4. The method according to claim 3, characterized in that, The step of generating the second prompt word based on the original context window information and the prompt word template corresponding to the target programming language includes: The first system prompt word in the original context window information is modified to the second system prompt word of the target language agent in the prompt word template to obtain the target context window information; the second system prompt word includes natural language instructing the target language agent to return the first patch to the first source code and the identifier of the tools involved in the return process; Based on the target context window information, the prompt word template includes instructions for the target language agent to adapt the second code segment to the natural language of the first source code, as well as programming considerations corresponding to the target programming language included in the prompt word template, to obtain the second prompt word.
5. The method according to any one of claims 2-4, characterized in that, After the code retrieval agent returns the third code segment and the first location information to the decision-making agent using the code retrieval agent, the method further includes: The decision-making agent analyzes the programming language used in the third code segment to determine the target programming language; and from multiple language agents, it determines the language agent to be called as the target language agent corresponding to the target programming language. The decision-making agent inputs the second prompt word into the target language agent.
6. The method according to any one of claims 1-4, characterized in that, The step of using the target language agent, guided by the second prompt word, to return the fourth code segment to the first source code based on the third code segment and the first position information includes: Guided by the second prompt word, the target language agent deletes the third code segment from the first source code based on the first location information; and adds the fourth code segment to the first source code based on the first location information.
7. The method according to any one of claims 1-4, characterized in that, The first patch includes multiple original modification blocks; the first code segment is the first code segment corresponding to each of the multiple original modification blocks; the second code segment is the second code segment corresponding to each of the multiple original modification blocks; wherein, the first code segment corresponding to any original modification block is the original code of the target software of the first version described by the original modification block; and the second code segment corresponding to any original modification block is the modified code of the target software of the first version described by the original modification block.
8. The method according to claim 7, characterized in that, For the target original modified block among the plurality of original modified blocks, after returning the fourth code segment corresponding to the target original modified block to the first source code, the method further includes: The target language agent is used to obtain the second position information of the fourth code segment corresponding to the original target modified block in the second source code; Using the target language agent, a local code snapshot is created for the second version of the target software based on the fourth code segment corresponding to the target original modified block, the second position information, the third code segment corresponding to the first code segment in the target original modified block, and the first position information of the third code segment corresponding to the first code segment in the target original modified block in the first source code. After the multiple rounds of the original modification blocks are completed, the target language agent generates a second patch for the target software to be rounded to the second version based on the local code snapshots corresponding to each of the multiple original modification blocks.
9. The method according to claim 8, characterized in that, Before creating a local code snapshot for the target software of the second version, the method further includes: Obtain the current code change characteristics of the target software in the second version; Guided by a fourth prompt word, the target language agent performs compliance verification on the current round corresponding to the original target modification block based on the code change characteristics. The fourth prompt word includes natural language that instructs the target language agent to perform compliance verification on the current round corresponding to the original target modification block, as well as compliance verification rules corresponding to the target programming language. If the current round corresponding to the original target modification block passes the compliance check, the target language agent is allowed to perform the operation of creating a local code snapshot for the second version of the target software.
10. The method according to claim 9, characterized in that, The process of obtaining the current code change characteristics of the target software in the second version includes: The code similarity between the first source code and the second source code is obtained as the code change feature; And / or, The size of the code change in the second source code compared to the first source code is obtained as the code change feature.
11. The method according to claim 7, characterized in that, Before obtaining the first and second code segments corresponding to each of the plurality of original modified blocks, the method further includes: The first patch is split into multiple original modification blocks; For any of the original modified blocks, convert the original modified block into a custom modified block; the custom modified block includes: a first code segment and a second code segment corresponding to the original modified block; The step of obtaining the first code segment and the second code segment corresponding to each of the plurality of original modified blocks includes: For any original modified block, obtain the first code segment and the second code segment corresponding to the original modified block from the custom modified block corresponding to the original modified block.
12. The method according to claim 2, characterized in that, Before using the code retrieval agent to return the third code segment and the first location information to the decision-making agent, the method further includes: The third code segment is located in the first source code using a string matching method. If the third code segment is found in the first source code, the code retrieval agent is executed to return the third code segment and the first location information to the decision agent.
13. A patching round system, characterized in that, include: Code retrieval agent and target language agent; The code retrieval agent is used to obtain the first code segment restored based on the first patch; The first code segment is the original code of the first version of the target software corresponding to the first patch; and, guided by the first prompt word, the third code segment corresponding to the first code segment and the first position information of the third code segment in the first source code are determined from the first source code of the second version of the target software. The target language agent is used to obtain the second code segment restored based on the first patch; The second code segment is the modified code of the target software of the first version corresponding to the first patch; And, guided by the second prompt, the second code segment is rewritten using the target programming language to obtain the fourth code segment; the target programming language is the programming language used by the third code segment; and guided by the second prompt, the fourth code segment is returned to the first source code according to the third code segment and the first position information.
14. An electronic device, characterized in that, include: A memory and a processor; wherein the memory is used to store computer programs; The processor is coupled to the memory for executing the computer program to perform the steps of the method according to any one of claims 1-12.
15. A computer-readable storage medium storing computer instructions, characterized in that, When the computer instructions are executed by one or more processors, the one or more processors are caused to perform the steps of the method according to any one of claims 1-12.
16. A computer program product, characterized in that, Includes a computer program that, when executed by one or more processors, causes the one or more processors to perform the steps of the method according to any one of claims 1-12.