A code review result optimization method fusing multi-agent collaborative reasoning

By integrating a multi-agent collaborative reasoning code review method and utilizing large language models and prompt word templates to automate code review, the problem of low efficiency and unstable quality of manual review is solved, achieving efficient and reliable code quality assurance.

CN122111815APending Publication Date: 2026-05-29SUZHOU CHUANGLUTIANXIA INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SUZHOU CHUANGLUTIANXIA INFORMATION TECH CO LTD
Filing Date
2025-12-30
Publication Date
2026-05-29

Smart Images

  • Figure CN122111815A_ABST
    Figure CN122111815A_ABST
Patent Text Reader

Abstract

The application relates to a code review result optimization method fusing multi-agent collaborative reasoning, and belongs to the technical field of code review. The method comprises the following steps: receiving a review instruction, and acquiring a code difference file to be reviewed; the code difference file is dynamically rendered into a preset cognitive prompt word template to generate a first prompt word; the first prompt word is input into a preset large language model, and a final review result is output by the large language model; and the final review result is output for developers to know. The application has the effects of improving code review efficiency and review accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of code review technology, and in particular to a method for optimizing code review results by incorporating multi-agent collaborative reasoning. Background Technology

[0002] In software engineering, code review is a crucial step in ensuring code quality and identifying potential defects. Current code review processes are generally human-led, relying on reviewers' experience and using tools like GitHub Pull Requests or Gerrit to examine code line by line. While this method can be combined with specific business logic for judgment, its low efficiency has become a major bottleneck in the development process, accounting for over 30% of the development cycle, according to research. Furthermore, review quality is limited by the individual reviewer's knowledge gaps, leading to the easy overlooking of critical vulnerabilities, especially security risks specific to certain frameworks, thus requiring improvement. Summary of the Invention

[0003] To address the technical problems of inefficiency and inaccuracy caused by manual code review, this application provides a method for optimizing code review results by incorporating multi-agent collaborative reasoning.

[0004] Firstly, this application provides a method for optimizing code review results by integrating multi-agent collaborative reasoning, employing the following technical solution: Receive review instructions and obtain the code difference files to be reviewed; The code difference file is dynamically rendered into a preset cognitive prompt word template to generate the first prompt word; The first prompt word is input into a preset large language model, and the final review result is output through the large language model for developers to know.

[0005] By adopting the above technical solution, the review logic is embedded in a pre-set cognitive prompt template, and tools (such as Jinja2) are used to dynamically render code difference files, thus achieving full automation from input to output. This frees up human labor from time-consuming line-by-line review, solves the efficiency bottleneck of manual review, improves review efficiency, and ensures that the cognitive prompt template ensures that each review follows the same set of high-quality standards and output specifications, eliminating the uncertainty of human instructions and making the automated review results more stable and reliable.

[0006] Optionally, the step of inputting the first prompt word into a preset large language model, outputting the final review result through the large language model, and providing the final review result to developers includes: The first prompt word is input into a preset large language model, and the preliminary review result is output through the large language model. The preliminary review results and the code difference file are dynamically rendered into a preset verification prompt template to generate a second prompt; wherein, the cognitive prompt template and the verification prompt template include at least output format constraints; The second prompt word is input into the large language model, and the large language model outputs the final review result for the developers to know.

[0007] By adopting the above technical solutions and introducing verification prompt templates to further optimize the preliminary review results, the risk of a single model outputting erroneous review opinions is significantly reduced, further improving the reliability of the final review results. Furthermore, the multi-template collaborative review mechanism overcomes the blind spots of individual knowledge during manual review, enabling the discovery of deeper and more hidden code defects, thus improving review quality. Moreover, the carefully designed prompt templates strictly constrain the output format, ensuring a clear and organized final review result. This eliminates the problem of the existing single LLM review output format being flexible and requiring secondary manual processing. The entire system, from preliminary analysis and verification to rule cleaning, forms a complete automated decision-making chain, producing high-quality review conclusions with little or no human intervention, achieving a leap from "auxiliary tool" to "automated solution."

[0008] Optionally, the final review result includes several review recommendations and a confidence score for each review recommendation; The step of inputting the first prompt word into a preset large language model, outputting the final review result through the large language model, and outputting the final review result for developers to know also includes: Before outputting the final review result, based on a preset confidence threshold, review suggestions in the final review result output by the large language model are filtered out if their confidence scores are lower than the confidence threshold.

[0009] By adopting the above technical solutions, the output of a large language model may contain some review suggestions that it itself is not entirely certain about, are generated based on fuzzy associations, or are of low importance. These low-confidence suggestions are often "noise" for developers, interfering with their judgment, requiring extra time for verification, and potentially misleading them. To address this, by setting a confidence threshold, the system can automatically filter out these low-value, uncertain suggestions. This ensures that every review suggestion presented to developers is content that the model considers highly likely, the problem is serious, or has high value. Developers can trust this list of results more and prioritize addressing the issues listed, thereby improving the operability and decision-making efficiency of the review results. The filtering operation based on the confidence threshold ensures that the final review results are concise and focused, directly guiding developers' attention to the most important issues. Essentially, this precisely allocates limited developer resources to the most worthwhile code problems, avoiding wasted time on low-value issues; and the filtering step adds a layer of security to the system. It proactively reduces the output risk caused by model uncertainty through a quantifiable and objective standard (confidence score).

[0010] Optionally, the method further includes: Obtain all review suggestions corresponding to the final review result output by the large language model, wherein each review suggestion includes at least a problem description and / or modification suggestions; A semantic similarity analysis is performed on all the review recommendations, and review recommendations with similar semantics are clustered into the same issue group. Review recommendations belonging to the same issue group are integrated to generate a summary review opinion. Based on the data flow and control flow analysis of the source code to which the code difference file belongs, it is determined whether there is a causal relationship between the code defects pointed to by different review suggestions. For review suggestions with causal relationship, review opinions are generated according to the preset causal logic. The system detects whether there are logical conflicts between the proposed modifications in different review suggestions. For review suggestions with logical conflicts, it generates review opinions with conflict warning information and recommended solutions to resolve the logical conflicts. Based on the generated review comments, the final review result and corresponding review comments are output for the developers to know.

[0011] By adopting the above technical solutions, the deep logical relationships between scattered review suggestions are analyzed and sorted out through automation, and then clustered and summarized, thereby helping developers reduce the analysis and development burden and significantly improve development efficiency.

[0012] Optionally, the method further includes: At specified intervals, acquire and analyze the code difference files and their corresponding final review results and comments within the specified intervals; Pattern mining is performed on the final review results to analyze the correlation between different code types, code locations, and problem type sets, and to generate and store targeted priority review schemes; wherein, the targeted priority review schemes include a set of code locations to be prioritized for review, a set of problem types to be prioritized for review, and early warnings of expected related problems based on the correlation; Whenever a review instruction is received, and before dynamically rendering the code difference file to the preset cognitive prompt template, the code type and / or code location of the code difference file corresponding to the review instruction are identified. Based on the code type and / or code location, a targeted priority review scheme stored in the past period is matched. The matched targeted priority review scheme is dynamically integrated into the preset cognitive prompt template.

[0013] By adopting the above technical solutions, and by mining the correlation between different code types, code locations, and problem type sets in historical periods, potential risk chains can be proactively deduced to achieve correlation mining. This enables reviews to discover deeper and more coupled design flaws, and by integrating these findings, targeted priority review schemes can be obtained. These schemes can then be used to optimize cognitive prompt word templates, resulting in more targeted first prompt words. This allows the large language model to focus more effectively on reviewing high-risk areas of code difference files, making single reviews faster, cheaper, and particularly suitable for frequent and incremental reviews of large projects.

[0014] Optionally, the method further includes: Obtain the final review results, and select target review suggestions that meet the automatic repair conditions from the final review results; Based on the type and content of the target review recommendations, corresponding code fixes are generated. Based on the code fixes, the corresponding code is modified, and the modified code file or standard patch file is generated and output.

[0015] By adopting the above technical solution, this solution creates a closed-loop system of "review + repair". Based on review suggestions, as well as the corresponding problem type and context, the system automatically generates specific code modifications (i.e., patches) and can automatically apply them to the source code. This frees developers from tedious and formulaic code modifications, improves problem-solving efficiency, avoids omissions and inconsistencies that may occur with manual modifications, ensures consistent code style, and creates a seamless integrated experience of "discovering a problem → clicking to repair → problem solved", which greatly optimizes the developer workflow.

[0016] Optionally, dynamically rendering the code difference file into a preset cognitive prompt word template includes: The code difference files are subjected to feature analysis and classification to identify the domain category to which the dominant technical features of the code difference files belong; Based on the domain category, a matching cognitive prompt template is dynamically selected from a set of multiple domain-specific cognitive prompt templates; The code difference file is dynamically rendered into the matched cognitive prompt word template.

[0017] By adopting the above technical solution, the inaccuracy of a single, general cognitive prompt template in complex code review is fundamentally solved. By identifying the domain category of the code difference files and selecting a cognitive prompt template that matches the domain, the subsequent large language model can conduct in-depth analysis under the guidance of specific domain knowledge. This significantly improves the accuracy and professionalism of review opinions, enabling the efficient discovery of deep-seated, domain-specific issues that a single, general cognitive prompt template might overlook (such as misuse of specific encryption algorithms or database transaction isolation level issues). This achieves a shift from "general talk" to "hitting the nail on the head."

[0018] Secondly, this application provides a code review result optimization system that integrates multi-agent collaborative reasoning, including: The review instruction acquisition module is used to receive review instructions and obtain the code difference files to be reviewed; The cognitive preliminary review module is used to dynamically render the code difference file to a preset cognitive prompt word template to generate a first prompt word; input the first prompt word into a preset large language model, and output the preliminary review result through the large language model; The verification-type optimization review module is used to dynamically render the preliminary review results and the code difference file into a preset verification-type prompt word template to generate a second prompt word; input the second prompt word into the large language model, and output the final review result through the large language model; wherein, the cognitive prompt word template and the verification prompt word template include at least output format constraints; The final review post-processing output module is used to filter out review suggestions with confidence scores lower than the preset confidence threshold from the final review results output by the large language model; and then output the final review results for developers to know.

[0019] Thirdly, this application provides a code review result optimization device that integrates multi-agent collaborative reasoning, including a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and executed as described in any of the first aspects.

[0020] Fourthly, this application provides a computer-readable storage medium storing a computer program that can be loaded by a processor and executed as described in any of the first aspects.

[0021] In summary, this application includes at least one of the following beneficial technical effects: 1. In this application, by embedding the review logic into a pre-defined cognitive prompt template and using tools (such as Jinja2) to dynamically render code difference files, the entire process from input to output is automated, freeing humans from time-consuming line-by-line review, solving the efficiency bottleneck of manual review, improving review efficiency, and ensuring that the cognitive prompt template ensures that each review follows the same set of high-quality standards and output specifications, eliminating the uncertainty of human instructions, and making the automated review results more stable and reliable; 2. Furthermore, by introducing verification prompt templates to further optimize the preliminary review results, the risk of a single model outputting erroneous review opinions is significantly reduced, further improving the reliability of the final review results. Moreover, the multi-template collaborative review mechanism overcomes the blind spots of individual knowledge during manual review, enabling the discovery of deeper and more hidden code defects, thus improving review quality. Furthermore, the carefully designed prompt templates strictly constrain the output format, ensuring a clear and organized final review result. This eliminates the problem of the existing single LLM review output format being flexible and requiring secondary manual processing. The entire system, from preliminary analysis and verification to rule cleaning, forms a complete automated decision-making chain, producing high-quality review conclusions with little or no human intervention, achieving a leap from "auxiliary tool" to "automated solution." 3. Furthermore, this application utilizes a confidence threshold-based filtering operation to ensure that the final review results are concise and focused, directly guiding developers' attention to the most critical issues. Essentially, this allocates limited developer resources precisely to the most worthwhile code problems, avoiding wasted time on low-value issues; and the filtering step adds an extra layer of security to the system. It proactively reduces output risks caused by model uncertainty through a quantifiable and objective standard (confidence score). Attached Figure Description

[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 This is a flowchart illustrating the code review result optimization method for integrating multi-agent collaborative reasoning according to an embodiment of this application.

[0024] Figure 2 This is a structural block diagram of the code review result optimization system for multi-agent collaborative reasoning disclosed in the embodiments of this application.

[0025] Figure labeling: 201, Review instruction acquisition module; 202, Cognitive preliminary review module; 203, Verification-based optimization review module; 204, Final review post-processing output module. Detailed Implementation

[0026] The following is in conjunction with the appendix Figure 1-2 This application will be described in further detail.

[0027] This application discloses a code review result optimization method integrating multi-agent collaborative reasoning (hereinafter referred to as the review optimization method). The execution subject of the review optimization method is a code review result optimization system integrating multi-agent collaborative reasoning (hereinafter referred to as the review optimization system). The following will be combined with Figure 1 This section details the specific steps and processes by which the review and optimization system executes the review and optimization methods.

[0028] S101, Receive review instructions and obtain the code difference file to be reviewed.

[0029] S102, dynamically render the code difference file to the preset cognitive prompt word template to generate the first prompt word.

[0030] S103, input the first prompt word into the preset large language model, output the final review result through the large language model, and provide the final review result to the developers.

[0031] S103 specifically includes the following steps: S1031, Input the first prompt word into the preset large language model, and output the preliminary review result through the large language model; S1032, dynamically render the preliminary review results and code difference files into a preset verification prompt template to generate a second prompt; wherein, the cognitive prompt template and the verification prompt template include at least output format constraints; S1033, Input the second prompt word into the large language model, and output the final review result through the large language model; S1034, for the final review result output by the large language model, based on a preset confidence threshold, filter out review suggestions in the final review result whose confidence scores are lower than the confidence threshold, and output the final review result for developers to know.

[0032] In implementation, the review and optimization system receives review instructions through an interface with version control systems (such as Git and SVN). These instructions are typically triggered by code push events from developers (such as Git Pull Requests or Merge Requests). The system then uses the `git diff` command or algorithms like `DiffMatchPatch` to compare the code in the working directory with the target branch (such as the main branch), generating a uniformly formatted diff file. This file precisely describes the add, delete, and modify operations on the code, along with their context line numbers, forming the raw data foundation for subsequent analysis—the code diff file to be reviewed.

[0033] The review and optimization system includes a pre-built cognitive prompt template. The core function of this template is to guide the large language model to act as a code analyst and problem finder. It aims to stimulate the model to broadly explore, deeply analyze, and creatively consider the differences in the input code, in order to identify various potential defects in the code. This template is a text file written in Jinja2 syntax, containing fixed instruction text and variable placeholders for dynamically inserting code context. For example, it includes: Role Definition: Explicitly specify the expert role the model will play in this interaction through instructions. For example: "You are a Java backend development expert with ten years of experience, specializing in high-performance and high-concurrency systems, and have a deep understanding of the OWASP security specification." Objectives: Clearly define the specific tasks and scope of this code review. For example: "Your task is to comprehensively analyze the differences in the provided code, focusing on identifying security vulnerabilities, performance bottlenecks, logical errors, and code that does not conform to the predetermined coding style." Input / Output Format Requirements: Input Description: Explicitly inform the subsequent large language model of the format of the input code data (e.g., "The following is a code snippet in a uniform Git diff format"); Output Specifications: Mandate that the large language model must output in a machine-readable, structured data format (preferably JSON or XML), and define the precise pattern of the output data. For example, the output may include review suggestions for the following fields: The `Type` field identifies the type of issue addressed by the review suggestion (e.g., security, performance, bugs, code style); the `description` field provides a clear description of the issue in natural language, such as what went wrong in the code and why it is an issue; the `line number` field explicitly indicates the specific line number of the problematic code in the code diff file; the `severity` field indicates the severity level of the impact of the problem on code quality (e.g., high, medium, low); the `suggestion` field provides a specific, actionable solution for fixing the problem, in natural language or with example code; and the `confidence` field is a confidence score, a quantified numerical value (e.g., an integer or floating-point number between 0 and 10) generated by the large language model, representing the large language model's confidence in the correctness and relevance of its review suggestion.

[0034] Defensive design: Includes instructions to reduce the "illusion" of large language models, such as: "Analyze only based on the provided code diff files. For issues that you infer but cannot be directly verified from the given code diff files, please explicitly state in the description that this is a 'speculation' and lower its confidence score accordingly."

[0035] The review and optimization system uses the Jinja2 template engine to inject the obtained code difference files into the variable placeholders of the cognitive prompt word template, generating a complete and customized first prompt word.

[0036] Next, the first suggestion word is input into a pre-defined large language model via an API (such as an Open API or a locally deployed LLM API). This large language model can be a model with strong code understanding capabilities, such as GPT-4 or Code Llama. The large language model analyzes the fixed instructions contained in the first suggestion word and outputs a structured JSON string. The review and optimization system parses this JSON string to obtain preliminary review results. These preliminary results are a list (such as a JSON array) containing multiple review suggestions, each object in the list representing an independent review suggestion. Review suggestions include the aforementioned fields (Type, description, line number, severity, suggestion, and confidence). The direct object of the review suggestions is the code difference file to be reviewed; more specifically, each review suggestion addresses a potential defect in a specific line of code (indicated by the line number field) or its logic within that code difference file. In summary: a code diff file (i.e., a code commit) corresponds to a review result (preliminary or final), which contains multiple review recommendations. Each review recommendation is associated with one or more specific lines of code in the code diff file through its line number field.

[0037] In addition, the review optimization system also includes pre-built verification prompt templates. The core function of these templates is to guide the large language model to act as a quality assurance officer or review expert. They aim to critically examine, verify logical consistency, and optimize content based on preliminary review results. The verification prompt template is also a text file, written using Jinja2 syntax, and contains fixed instructions and variable placeholders. However, its specific fixed instructions differ from those of the cognitive prompt template, focusing on critical thinking. For example, they include: Role Restriction: Specify a role that focuses on questioning and verification. For example: "You are a rigorous code reviewer and quality inspector. Your expertise lies in finding logical flaws and factual errors in analysis reports."

[0038] Objective definition: Clearly define the task as quality control of preliminary results. For example: "Your task is to carefully review the 'preliminary review results' and the 'differences between the original code,' identify and eliminate errors, 'illusions,' irrelevant suggestions, or logical incompleteness, and at the same time optimize and supplement the language of effective suggestions to make them more actionable."

[0039] Input / Output Format Constraints: Input Description: Both the code difference file and the preliminary review results should be used as input; Output Specification: The large language model should output standardized data with the same structure as the preliminary review results (such as the same JSON structure), but the content should be a version that has been corrected, deleted, merged, and optimized. The corresponding fixed instructions emphasize: "You must re-evaluate and calibrate the confidence score for each retained or modified review suggestion in the preliminary review results."

[0040] Defensive design: Includes instructions that emphasize fact-checking. For example: "Any judgment you make must be strictly based on the differences in the original code. If a suggestion in the initial review results is clearly inconsistent with the facts of the code, you must remove the suggestion and briefly explain the reason in the output."

[0041] Then, the review and optimization system again uses the Jinja2 engine, injecting the code difference file and the preliminary review results as context into the variable placeholders corresponding to the verification template to generate a second prompt word. The second prompt word is then input into the large language model, and the review result output by the large language model based on the second prompt word is taken as the final review result. This result is superior to the preliminary result in terms of logical rigor and clarity of expression.

[0042] Finally, the review optimization system, based on a preset confidence threshold, iterates through each review suggestion in the final review results and reads its confidence field. It then compares the confidence score corresponding to the confidence field with the confidence threshold, filtering out review suggestions with confidence scores below the threshold from the final review results—a post-processing step. In other embodiments, the review optimization system can also maintain an extensible rule base containing explicit code standards. For example: Standard 1: If the specific content of the review suggestion's type field is "security" and the description includes "SQL injection," then the code must be checked for SQL queries involving string concatenation; Standard 2: If the specific content of the review suggestion's type field is "code style," and the relevant line of code has been marked as "delete," then this review suggestion is ignored… The review optimization system also matches filtered review suggestions against the rule base. If a review suggestion conflicts with a predefined specification, it is removed. For example, if a high-confidence review suggestion misjudges a safe SQL query construction method as "SQL injection," specification verification will capture and remove it; this achieves a self-verifying logical loop and is the last effective line of defense against deep model illusions.

[0043] The final output is the post-processed review result, which is output in a standardized JSON format and can be automatically published back to the version control system's comment interface (such as GitHub Comments) or sent to developers through other notification channels, completing the entire automated review process.

[0044] Optionally, the review optimization method may also include the following steps: Obtain all review suggestions corresponding to the final review results output by the large language model, wherein each review suggestion includes at least a problem description and / or modification suggestions; A semantic similarity analysis is performed on all review recommendations, and those recommendations with similar semantics are clustered into the same issue group. Review recommendations belonging to the same issue group are then integrated to generate a summary review opinion. Based on the data flow and control flow analysis of the source code to which the code difference files belong, it is determined whether there is a causal relationship between the code defects pointed to by different review suggestions. For review suggestions with causal relationships, review opinions are generated according to the preset causal logic. Detect whether there are logical conflicts between the proposed modifications in different review suggestions, and generate review opinions with conflict warning information and recommended solutions to resolve logical conflicts for review suggestions with logical conflicts. Based on the generated review comments, the final review results and corresponding review comments are output for developers to see.

[0045] In practice, after the review optimization system outputs the final review result with several review suggestions from the large language model, it is also used to analyze the logical relationships between all the review suggestions contained in the final review result, specifically including causal relationships, semantic similarity, and logical conflicts.

[0046] The method for analyzing whether a causal relationship exists is as follows: Conduct in-depth static analysis of the code difference files, construct miniature data flow diagrams or control flow diagrams, and analyze whether the issues corresponding to different review suggestions share the same source variable, are on the same execution path, and whether a causal relationship exists. For example, if review suggestion A points out that "the variable 'userInput' is not validated," and review suggestion B points out that "userInput is directly concatenated in the SQL query," data flow analysis can identify that review suggestion A is the root cause of review suggestion B, and a causal relationship exists between the two.

[0047] The method for analyzing semantic similarity is as follows: using natural language processing models or code embedding techniques, the description field (corresponding to the problem description) and suggestion field (corresponding to the modification suggestion) of all review suggestions are vectorized. Then, a clustering algorithm is used to classify review suggestions whose problems and solutions are semantically similar in both fields as semantically similar review suggestions. As mentioned earlier, each review suggestion corresponds to a problem. Therefore, for review suggestions that are semantically similar, the review optimization system uses them to group them into the same category, that is, into the same problem group. For example, review suggestion C points out that "the method 'calculate()' is too long," and review suggestion D points out that "the method 'calculate()' has high cyclomatic complexity." Therefore, through semantic clustering, review suggestion C and review suggestion D can be identified as the same type of code smell problem targeting the same method "calculate()", belonging to the same problem group.

[0048] The method for detecting logical conflicts is as follows: The review and optimization system extracts architectural rules and patterns from pre-defined or code-based frameworks to check whether the modification suggestions (i.e., the content of the `suggestion` field) included in different review recommendations violate the corresponding architectural rules. For example, review recommendation E suggests "Introduce a global cache to improve performance," while review recommendation F suggests "Remove shared state to ensure microservices are stateless." Based on the architectural principle of "stateless microservices," the review and optimization system can identify a logical conflict between these two review recommendations.

[0049] After identifying the logical relationships between all review suggestions in the manner described above, the review optimization system will perform the following optimization operations: The review suggestions from the same issue group are used to generate a higher-level, general review opinion. The purpose of this review opinion is to present the logical relationships between the review suggestions in a structured manner. Therefore, the specific content of the review opinion includes a core question derived from integrating the problem descriptions of all review suggestions within the corresponding issue group, as well as the specific content of all review suggestions in the corresponding issue group. Furthermore, the problem description corresponding to each review suggestion within the corresponding issue group is presented as a subordinate concept. For example, for review suggestions A and B, a core question is generated: "Lack of user input validation leads to potential SQL injection risk." The problem descriptions corresponding to review suggestions A and B are presented as subordinate concepts of this core question, such as: "Core Question: Lack of user input validation leads to potential SQL injection risk, specifically manifested as: the variable 'userInput' is not validated, and 'userInput' is directly concatenated in the SQL query."

[0050] Similarly, for review recommendations with a causal relationship, a review opinion can also be generated. That is, the review opinion contains the specific content of the review recommendation with a causal relationship, as well as a core issue summarized from the higher level. For example, for the review recommendations C and D mentioned at the higher level, the core issue "the calculation method has a complex structure" can be summarized, and the specific problem descriptions of review recommendations C and D can be used as subordinate concepts of this core issue.

[0051] It should be noted here that when generating the core problem, techniques based on graph theory and root cause analysis can be used to construct a directed graph for review suggestions within the same problem group or review suggestions with causal relationships. In the graph, nodes represent review suggestions, and edges represent relationship types (such as "cause" or "belong to the same category"). Specifically, for review suggestions with causal relationships, a causal graph is constructed. For example, review suggestion A (unvalidated input) has an edge pointing to review suggestion B (SQL injection risk), and the relationship is "cause". For review suggestions with similar semantics, an undirected graph is constructed or a common parent node is used. For example, review suggestion C (method process) and review suggestion D (high cyclomatic complexity) are connected to a new, virtual parent node review suggestion G.

[0052] Then, when integrating and generating the core issue, in the cause-effect graph, look for nodes without any incoming edges (i.e., no other issues cause them); these nodes are the root causes. Input the description field from the review suggestions of the found root cause node group or the same issue group into a text summarization or generalization model (such as another LLM, or a dedicated text summarization API). By designing specific prompts, the model generates a highly generalized description of the core issue.

[0053] In other embodiments, a rule base is pre-configured. For example, the rule base may specifically include the following exemplary rule content: Rule 1: IF (exists "unverified" review suggestion X) AND (exists "unsafe use" review suggestion Y) AND (X and Y are associated via data flow) THEN Core issue template = "[variables in X] lack effective verification, resulting in [security risk in Y]".

[0054] Rule 2: IF (There are multiple "code smell" review suggestions H, I, J pointing to the same code entity) THEN Core issue template = "[code entity] has a complex structure and poor maintainability", where [code entity] is the same code entity pointed to by review suggestions H, I, J.

[0055] The review and optimization system allows users to input specific variables (such as userInput), code entity names (such as the calculate function), and specific risks (such as SQL injection) into the core issue template of the matched rules, which will automatically generate an accurate description of the core issues.

[0056] Furthermore, the system can intelligently sort the remediation order of the review recommendations contained in the review opinion, generating remediation paths. In implementation, the review optimization system calculates a remediation priority score for each review recommendation. A higher score indicates a higher priority, and the corresponding remediation order is earlier. The remediation priority score is calculated as F(severity, confidence), which assigns scores to severity, confidence, and impact and sums them to obtain the remediation priority score. Severity can be directly obtained from the severity field in the review recommendation (e.g., High=3, Medium=2, Low=1); confidence can be directly obtained from the confidence field in the review recommendation (normalized to 0-1). Finally, the review prioritization system sorts the review recommendations contained in the review opinion according to the remediation priority scores from highest to lowest, and determines the remediation path according to this intelligent sorting, such as remediating review recommendation A first, then remediating review recommendation B.

[0057] For review suggestions with logical conflicts, the review optimization system will further invoke a large language model (such as LLM) to generate a compromise, better solution suggestion based on the background and project architecture of both conflicting parties. For example, it will generate an alert message: "Warning: Architectural conflict suggestion detected," along with an analysis generated by LLM: "In the current scenario, it is recommended to use Redis distributed locks or stateless tokens to replace global caching in order to meet both performance and statelessness requirements."

[0058] Optionally, the review optimization method may also include the following steps: At specified intervals, acquire and analyze the code difference files and their corresponding final review results and comments within the specified intervals; Pattern mining is performed on the final review results to analyze the correlation between different code types, code locations, and problem type sets, and to generate and store targeted priority review plans. The targeted priority review plans include the set of code locations to be prioritized for review, the set of problem types to be prioritized for review, and early warnings of expected related problems based on the correlation. Whenever a review instruction is received, and before dynamically rendering the code difference file to the preset cognitive prompt template, the code type and / or code location of the code difference file corresponding to the review instruction are identified. Based on the code type and / or code location, a targeted priority review scheme stored in the past period is matched. The matched targeted priority review scheme is dynamically integrated into the preset cognitive prompt template.

[0059] In implementation, the review and optimization system retrieves the code difference files (i.e., diff files) within the specified period from the databases of the version control system (such as Git) and the code review platform (such as Gerrit) every specified period (e.g., 7 days), along with the final review results and corresponding review comments. As mentioned earlier, the retrieved content includes the problem type, problem description, line number, severity, modification suggestion description, and related information after logical relationship analysis (such as the problem group, root cause, core problem, etc.).

[0060] Based on the information obtained above, the review and optimization system will employ data mining techniques, such as frequent pattern mining (FP-Growth algorithm) and cluster analysis (K-Means algorithm), to analyze the preprocessed historical data. The system first identifies key code entities from code changes, such as filenames (UserService.java), class names, method names (updateUserProfile), and code modules ( / src / main / controller). Next, the system analyzes the strong association rules between specific code entities (such as the updateUserProfile method) and the types of issues that occur (such as Input Validation, Security: Access Control). Furthermore, the system analyzes not only single issues but also sets of issues. For example, it might find that the issue of "{updating the database without validating the user ID}" frequently occurs in the updateUserProfile method, and that the former is the root cause of the latter.

[0061] Next, based on the discovered association rules, the review and optimization system generates a structured, targeted priority review plan for frequently occurring code entities or code types. This plan is a data object containing the following fields: target_entity: The target code entity (e.g., OrderController.createOrder); priority_locations: The set of code locations to be prioritized for review (can be derived from the line number field, such as [line number 45-78] or [method parameter list]). `priority_issue_types`: The set of issue types to be prioritized for review (e.g., ["Business Logic", "Concurrency"]); `expected_issue_chains`: Warnings of expected related issues (e.g., "When an 'unlocked' issue is found, please focus on checking whether there are race conditions in the 'Inventory Deduction' and 'Points Update' logic"). This field is directly derived from the analysis of review comments in historical data; that is, the specific content of this field can directly be the issue description of all review suggestions included in the review comments.

[0062] The review priority system is used to store the generated targeted priority review plans in a preset review knowledge base, which can be a relational database or a search engine, for subsequent fast matching queries.

[0063] Whenever a new review instruction is received, the review optimization system parses the corresponding code diff file (i.e., the diff file), identifies the modified code entities (i.e., source code, such as filenames, class names, and method names), and then uses these entities as keywords to search the review knowledge base, matching the most relevant targeted priority review scheme, i.e., the targeted priority review scheme whose `target_entity` is the same as the code entity in the current code diff file. Finally, the review optimization system obtains a pre-set cognitive prompt template. It should be noted that the cognitive prompt template is not a completely fixed text, but contains an extensible dynamic instruction block. This block contains pre-set variable placeholders and fixed instruction frames corresponding to the data structure of the targeted priority review scheme. Therefore, the review optimization system uses the matched targeted priority review scheme as a structured data context (such as a Python dictionary) and renders it into the cognitive prompt template using a template engine (such as Jinja2). If no targeted priority review scheme is matched, the corresponding dynamic instruction block is empty, which does not affect the execution of other parts of the cognitive prompt template.

[0064] For example, a specific example of the targeted priority review scheme in the cognitive prompt template could be: "The code entity '{{ priority_scheme.target_entity}}' currently under review is a high-risk area for historical issues. Please prioritize and focus on the following aspects:" Core location: {%for location in priority_scheme.priority_locations %} - {{ location}} {% endfor %}; Common problem types: {% for issue_type in priority_scheme.priority_issue_types %} - {{ issue_type}} {% endfor %} Warning of anticipated risk chain: {{ priority_scheme.expected_issue_chains}} {% endif %} {% endif %}”.

[0065] Next, using the cognitive prompt template and the currently obtained code difference file, the first prompt is generated and S1031, S1032, S1033, and S1034 are executed.

[0066] Optionally, the review optimization method may also include the following steps: Obtain the final review results and filter out the target review suggestions that meet the automatic repair criteria from the final review results; Based on the type and content of the target review recommendations, generate corresponding code fixes, modify the corresponding code based on the code fixes, and generate and output the modified code file or standard patch file.

[0067] In implementation, the review optimization system user obtains the final review results and, based on the issue type (Type field), issue description (description field), line number (line number field), severity (severity field), and confidence (confidence field) included in the final review results, filters out target review suggestions that meet the automatic repair conditions. The automatic repair conditions include: Repair condition 1, the confidence score of the review suggestion is higher than a preset first threshold; Repair condition 2, the issue type of the review suggestion belongs to a predefined set of automatically repairable issue types (e.g., {"Code Style", "Simple Bug", "Hardcoded Credentials"}); Repair condition 3, the severity level of the review suggestion is high or medium (i.e., "High" or "Medium"). Target review suggestions are those that meet at least one of the aforementioned automatic repair conditions.

[0068] Accordingly, the review optimization system has a pre-built remediation rule base. Each rule in the remediation rule base is associated with a problem type and defines a specific remediation action. Therefore, the review priority system is used to match the target review suggestion problem type with the corresponding rule in the remediation rule base, and then uses an abstract syntax tree (AST) parser to accurately locate the code node of the problem (i.e., determine the code location based on the corresponding line number), and finally execute the remediation action corresponding to the rule.

[0069] Furthermore, the review and optimization system uses standard diff algorithms (such as the unified diff format) to compare the code differences corresponding to the review instructions with the modified code executed according to the fix, generating a standard patch file. This patch file can be directly recognized and applied by version control systems (such as Git). To ensure the reliability of automatic fixes, the review and optimization system can also introduce verification steps: including compilation testing (attempting to compile the fixed code in an isolated environment to ensure syntax correctness) and regression testing (running unit test suites related to the code to ensure the fix does not break existing functionality). The review and optimization system also provides user interaction and application functionality. On the user interface, a "View and Apply Fix" button is displayed for each successfully fixed review suggestion. After clicking, the user can view the specific code changes (i.e., the diff view). After confirming that everything is correct, the user can apply the patch with one click. The review and optimization system executes commands such as `gitapply` to write the changes to the working directory or create a new fix commit.

[0070] Optionally, "Dynamically rendering the code diff file to a preset cognitive prompt template" in S102 specifically includes the following steps: Perform feature analysis and classification on code difference files to identify the domain category to which the dominant technical features of the code difference files belong; Based on the domain category, a matching cognitive prompt template is dynamically selected from multiple preset domain-specific cognitive prompt templates; The code difference file is dynamically rendered into the matched cognitive prompt word template.

[0071] In implementation, when the review and optimization system receives a review instruction, it analyzes the code difference files to be reviewed and extracts features to obtain key information for classification. The extracted features include one or more of the following: 1. File path pattern (i.e. the path where the code difference files are located). For example: if the path contains / src / main / java / controller / , it may be an API interface layer change; if the path contains / src / main / java / service / , it may be a business logic layer change; if the path contains / src / main / resources / mapper / or the file extension is .xml (MyBatisMapper), it may be a database operation change; if the path contains .jsx / .vue / .css, it may be a front-end UI change; if the path contains Security / Auth, it may be a security-related change.

[0072] 2. Keyword analysis in code content (scanning for specific keywords or API calls in the changed code). For example: the presence of @Transactional, save, update, and delete may indicate database transactions / concurrency; the presence of Cipher, encrypt, decrypt, and SecretKey may indicate encryption algorithms; the presence of ExecutorService, Thread, and synchronized may indicate multithreading / concurrency; and the presence of @RequestMapping, @GetMapping, and @PostMapping may indicate API interfaces.

[0073] 3. Change type (identify whether the change type is adding a method, modifying conditional statements, or refactoring, etc.).

[0074] Next, the review and optimization system uses the extracted features to make classification decisions. Specifically, it can be a rule-based classifier: for example, a pre-defined rule base can be used for matching using "if...then..." logic. For example: IF (file path contains ' / crypto / ') OR (code content contains 'Cipher') THEN category = 'encryption algorithm'; IF (file path contains 'mapper' or 'dao') AND (code content contains 'select' or 'update') THEN category = 'database operation'.

[0075] Furthermore, the review and optimization system also maintains a template router to store the mapping relationship between classification results (such as security / encryption, database operations, front-end UI, concurrency / multithreading, and API interfaces) and cognitive prompt word templates. The classification results obtained from the classification decision are queried in this routing table to match the corresponding cognitive prompt word template. It should be noted that the different cognitive prompt word templates in the routing table are structurally consistent, differing only in the inclusion of domain knowledge in the specific content related to role and target limitations.

[0076] This application also discloses a code review result optimization system that integrates multi-agent collaborative reasoning, referring to... Figure 2 ,include: The review instruction acquisition module 201 is used to receive review instructions and acquire the code difference file to be reviewed. The cognitive preliminary review module 202 is used to dynamically render the code difference file to a preset cognitive prompt word template to generate the first prompt word; input the first prompt word into a preset large language model, and output the preliminary review result through the large language model; The verification-type optimization review module 203 is used to dynamically render the preliminary review results and code difference files into a preset verification-type prompt word template to generate a second prompt word; input the second prompt word into a large language model, and output the final review result through the large language model; wherein, the cognitive prompt word template and the verification prompt word template include at least output format constraints; The final review post-processing output module 204 is used to filter out review suggestions with confidence scores lower than the confidence threshold in the final review results output by the large language model based on a preset confidence threshold; and then output the final review results for developers to know.

[0077] Optionally, it also includes a deep relationship analysis module, used to obtain all review suggestions corresponding to the final review results output by the large language model. Each review suggestion includes at least a problem description and / or modification suggestions. Semantic similarity analysis is performed on all review suggestions, clustering semantically similar suggestions into the same problem group, and integrating review suggestions belonging to the same problem group to generate a summary review opinion. It is also used to determine whether there is a causal relationship between the code defects pointed to by different review suggestions based on data flow and control flow analysis of the source code to which the code difference file belongs. For review suggestions with causal relationships, review opinions are generated according to a preset causal logic. It detects whether there are logical conflicts between the modification schemes proposed by different review suggestions. For review suggestions with logical conflicts, review opinions with conflict warning information and recommended solutions for resolving logical conflicts are generated. Based on the generated review opinions, the final review results and corresponding review opinions are output for developers to see.

[0078] Optionally, it also includes a template customization configuration module, used to acquire and analyze code difference files and their corresponding final review results and comments within a specified period; perform pattern mining on the final review results to analyze the correlation between different code types, code locations and problem type sets, and generate and store targeted priority review schemes; wherein, the targeted priority review scheme includes a set of code locations to be reviewed first, a set of problem types to be reviewed first, and warnings of expected related problems based on the correlation; it is also used to identify the code type and / or code location of the code difference file corresponding to the review instruction whenever a review instruction is received, and before dynamically rendering the code difference file to the preset cognitive prompt word template, and match the targeted priority review scheme stored in the past period according to the code type and / or code location; and dynamically integrate the matched targeted priority review scheme into the preset cognitive prompt word template.

[0079] Optionally, it also includes an automatic code repair module, which is used to obtain the final review results, filter out target review suggestions that meet the automatic repair conditions from the final review results, generate corresponding code repair content based on the type and content of the target review suggestions, modify the corresponding code based on the code repair content, and generate and output the modified code file or standard patch file.

[0080] Optionally, the cognitive preliminary review module 202 is also used to perform feature analysis and classification on the code difference files, identify the domain category to which the dominant technical features of the code difference files belong; dynamically select a matching cognitive prompt word template from multiple preset domain-specific cognitive prompt word templates according to the domain category; and dynamically render the code difference files onto the matched cognitive prompt word template.

[0081] This application also discloses a code review result optimization device that integrates multi-agent collaborative reasoning. The code review result optimization device that integrates multi-agent collaborative reasoning includes a memory and a processor. The memory stores a computer program that can be loaded by the processor and executed as described above for the code review result optimization method that integrates multi-agent collaborative reasoning.

[0082] This application also discloses a computer-readable storage medium that stores a computer program that can be loaded by a processor and executed as described above for optimizing the code review results of multi-agent collaborative reasoning. The computer-readable storage medium includes, for example, various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0083] It should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.

[0084] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit the scope of protection of the application. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on these embodiments, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

Claims

1. A method for optimizing code review results by integrating multi-agent collaborative reasoning, characterized in that, include: Receive review instructions and obtain the code difference files to be reviewed; The code difference file is dynamically rendered into a preset cognitive prompt word template to generate the first prompt word; The first prompt word is input into a preset large language model, and the final review result is output through the large language model for developers to know.

2. The method for optimizing code review results by integrating multi-agent collaborative reasoning according to claim 1, characterized in that, The process of inputting the first prompt word into a preset large language model, outputting the final review result through the large language model, and providing the final review result to developers includes: The first prompt word is input into a preset large language model, and the preliminary review result is output through the large language model. The preliminary review results and the code difference file are dynamically rendered into a preset verification prompt template to generate a second prompt; wherein, the cognitive prompt template and the verification prompt template include at least output format constraints; The second prompt word is input into the large language model, and the large language model outputs the final review result for the developers to know.

3. The method for optimizing code review results by integrating multi-agent collaborative reasoning according to claim 2, characterized in that, The final review results include several review recommendations, as well as a confidence score for each review recommendation; The step of inputting the first prompt word into a preset large language model, outputting the final review result through the large language model, and outputting the final review result for developers to know also includes: Before outputting the final review result, based on a preset confidence threshold, review suggestions in the final review result output by the large language model are filtered out if their confidence scores are lower than the confidence threshold.

4. The method for optimizing code review results by integrating multi-agent collaborative reasoning according to claim 2, characterized in that, The method further includes: Obtain all review suggestions corresponding to the final review result output by the large language model, wherein each review suggestion includes at least a problem description and / or modification suggestions; A semantic similarity analysis is performed on all the review recommendations, and review recommendations with similar semantics are clustered into the same issue group. Review recommendations belonging to the same issue group are integrated to generate a summary review opinion. Based on the data flow and control flow analysis of the source code to which the code difference file belongs, it is determined whether there is a causal relationship between the code defects pointed to by different review suggestions. For review suggestions with causal relationship, review opinions are generated according to the preset causal logic. The system detects whether there are logical conflicts between the proposed modifications in different review suggestions. For review suggestions with logical conflicts, it generates review opinions with conflict warning information and recommended solutions to resolve the logical conflicts. Based on the generated review comments, the final review result and corresponding review comments are output for the developers to know.

5. The code review result optimization method for multi-agent collaborative reasoning according to claim 4, characterized in that, The method further includes: At specified intervals, acquire and analyze the code difference files and their corresponding final review results and comments within the specified intervals; Pattern mining is performed on the final review results to analyze the correlation between different code types, code locations, and problem type sets, and to generate and store targeted priority review schemes; wherein, the targeted priority review schemes include a set of code locations to be prioritized for review, a set of problem types to be prioritized for review, and early warnings of expected related problems based on the correlation; Whenever a review instruction is received, and before dynamically rendering the code difference file to the preset cognitive prompt template, the code type and / or code location of the code difference file corresponding to the review instruction are identified. Based on the code type and / or code location, a targeted priority review scheme stored in the past period is matched. The matched targeted priority review scheme is dynamically integrated into the preset cognitive prompt template.

6. The method for optimizing code review results by integrating multi-agent collaborative reasoning according to claim 2, characterized in that, The method further includes: Obtain the final review results, and select target review suggestions that meet the automatic repair conditions from the final review results; Based on the type and content of the target review recommendations, corresponding code fixes are generated. Based on the code fixes, the corresponding code is modified, and the modified code file or standard patch file is generated and output.

7. The method for optimizing code review results by integrating multi-agent collaborative reasoning according to claim 2, characterized in that, The step of dynamically rendering the code difference file into a preset cognitive prompt word template includes: The code difference files are subjected to feature analysis and classification to identify the domain category to which the dominant technical features of the code difference files belong; Based on the domain category, a matching cognitive prompt template is dynamically selected from a set of multiple domain-specific cognitive prompt templates; The code difference file is dynamically rendered into the matched cognitive prompt word template.

8. A code review result optimization system integrating multi-agent collaborative reasoning, used to execute the code review result optimization method integrating multi-agent collaborative reasoning as described in claim 3, characterized in that, include: The review instruction acquisition module (201) is used to receive review instructions and acquire the code difference file to be reviewed; The cognitive preliminary review module (202) is used to dynamically render the code difference file to a preset cognitive prompt word template to generate the first prompt word; The first prompt word is input into a preset large language model, and the preliminary review result is output through the large language model. The verification-type optimization review module (203) is used to dynamically render the preliminary review results and the code difference file to a preset verification prompt template to generate a second prompt. The second prompt word is input into the large language model, and the final review result is output through the large language model; wherein, the cognitive prompt word template and the verification prompt word template include at least output format constraints; The final review post-processing output module (204) is used to filter out review suggestions in the final review results output by the large language model based on a preset confidence threshold, where the confidence score is lower than the confidence threshold. The final review results are then output for the developers to see.

9. A code review result optimization device integrating multi-agent collaborative reasoning, characterized in that, It includes a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and executed as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer program is stored that can be loaded by a processor and executed as described in any one of claims 1 to 7.