Code defect positioning method and device based on multiple agents

By decomposing the code defect localization process using a multi-agent architecture and utilizing a large language model for step-by-step analysis and repair, the problem of difficult project-level code diagnosis in existing technologies is solved, and efficient defect localization and repair are achieved.

CN122019347APending Publication Date: 2026-05-12CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD
Filing Date
2026-01-15
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing code defect localization methods based on large language models are difficult to diagnose a wide range of errors in project-level code, and redundant information affects the localization and repair effectiveness.

Method used

A multi-agent architecture is adopted, including a program analysis component, a fault understanding agent, a code repository navigation agent, a method review agent, and a method location agent. By decomposing the defect location process, a large language model is used for step-by-step analysis and repair.

Benefits of technology

It enables automatic defect location and repair at the project level, improves the defect detection rate, and reduces the average time to locate a single bug to 80 seconds, which is better than existing technologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019347A_ABST
    Figure CN122019347A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of code detection, and discloses a code defect positioning method and device based on multiple agents, and the method comprises the steps: a fault understanding agent carries out test behavior analysis and test failure analysis according to a test code, a test practical code and an abnormal stack, and obtains a possible failure reason list; the code library navigation agent performs analysis based on the failure possible reason list, the coverage class list, the coverage method list and the method-level coverage rate of each coverage class to obtain a related method list; the method review agent obtains source codes corresponding to all methods in the related method list in the project code library and reviews the source codes one by one to obtain a suspicious method list; and the method positioning agent generates a defect positioning method according to the suspicious method list and analysis records of the fault understanding agent and the code library navigation agent. According to the method, the problem that errors in a large code range are difficult to diagnose in project-level code defect positioning of a large language model can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of code detection technology, and in particular to a method and apparatus for locating code defects based on multi-agent systems. Background Technology

[0002] Defect localization (FL) and program repair (PR) are indispensable and time-consuming stages in software debugging. Developers may spend nearly half of their debugging time understanding and locating errors before fixing problematic code. To alleviate the burden on developers, automation technologies have been proposed for locating and fixing faults in system code. Automation technologies can automatically identify problematic program entities, such as classes, methods, or statements. In particular, spectrum-based defect localization (SBFL) and learning-based defect localization (LBFL) have been widely researched and applied. With the development of deep learning neural networks, recent advances in large-scale language models (LLMs) have brought new insights into defect localization and repair. Through training on large-scale code and text data, LLMs have demonstrated powerful natural language and code understanding capabilities, including detecting, locating, and fixing errors in code.

[0003] However, current LLM-based defect localization and remediation methods are still largely at the initial application stage, relying on basic hints or fine-tuning. In practical use, even if the general error range can be located, it is difficult to manually construct targeted large-scale model hints. Furthermore, due to input length limitations, it is impractical to input an entire project codebase into the existing large language models, which would inevitably introduce a large amount of redundant information, affecting the final defect localization and remediation results. Summary of the Invention

[0004] This application provides a code defect localization method and apparatus based on multi-agent technology, which can solve the problem that large language models are difficult to diagnose errors in a large code range in project-level code defect localization in the prior art.

[0005] In a first aspect, embodiments of this application provide a code defect localization method based on multi-agent systems, including: The program analysis component obtains test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stacks, and method-level coverage of multiple covered classes based on the test cases that failed and the project code library. The fault understanding agent performs test behavior analysis and test failure analysis based on test code, test utility code, test code execution results and exception stacks, and obtains a list of possible causes of failure. The code repository navigation agent analyzes the list of possible failure causes, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class to obtain the relevant method list; The method review agent obtains the source code corresponding to each method in the relevant method list in the project code library, and reviews the source code corresponding to each method one by one to obtain a list of suspicious methods; The method localization agent generates defect localization methods and corresponding repair code based on the analysis records of the list of suspicious methods, the fault understanding agent, and the code repository navigation agent.

[0006] Furthermore, the aforementioned program analysis component obtains test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stack traces, and method-level coverage of multiple covered classes based on the failed test cases and the project codebase, including: The program analysis component retrieves test cases and project codebases that failed tests; Execute test cases on the project codebase and obtain the test code execution results; The code that executes the test cases is used as the test code, and a lightweight proxy program records the method call path and exception stack of the test cases during the execution of the test cases. Static analysis is performed on the test code and method call traces to obtain practical test code; Analyze the method call history to obtain a list of overridden classes and a list of overridden methods; Search the source code corresponding to each class name in the overriding class list in the project code library; based on the source code corresponding to the class name, obtain the total number of methods of the overriding class corresponding to the class name and the number of overriding methods falling into the overriding method list; and use the ratio of the number of overriding methods to the total number of methods as the method-level coverage of the overriding class. Sort the method coverage rates of each coverage class in the coverage class list in descending order, and use a preset number of method coverage rates in the sorted list as input data for the code library navigation agent.

[0007] Furthermore, the fault understanding agent includes a test behavior analysis agent and a test failure analysis agent; The aforementioned fault-understanding agent performs test behavior analysis and test failure analysis based on the test code, test utility code, test code execution results, and exception stack traces, resulting in a list of possible failure causes, including: The test behavior analysis agent obtains the first prompt word, inputs the first prompt word, test code, and test utility code into the large language model to obtain a test behavior description; The test failure analysis agent obtains the second prompt word, inputs the second prompt word, test behavior description, test code execution result and exception stack into the large language model to obtain a list of possible reasons for failure.

[0008] Furthermore, the codebase navigation agent includes a suspicious class search agent, a method documentation enhancement agent, and a related method lookup agent; The aforementioned codebase navigation agent analyzes the list of possible failure causes, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class to obtain a list of relevant methods, including: Search for suspicious agents to obtain third prompt words, input the third prompt words, a list of possible reasons for failure, a list of covered classes, and the method-level coverage of each covered class into the large language model to obtain the name of the suspicious class; The method document enhancement agent obtains the fourth prompt word and the method document, and inputs the fourth prompt word, the method document and the list of covered methods into the large language model to obtain the enhanced method document. The relevant method search agent obtains the fifth clue word, and inputs the fifth clue word, the suspicious class name, the enhanced method document, and the list of possible reasons for failure into the large language model to obtain the relevant method list.

[0009] Furthermore, the method also includes: The test behavior analysis agent inputs the obtained test behavior descriptions into the result parser; The result parser parses the test behavior description into a structured test behavior description and puts it into the state memory; The test failure analysis agent obtains the test behavior description through the state memory.

[0010] Furthermore, the method also includes: The search agent for suspicious classes inputs the suspicious class names into the result parser. The result parser resolves the suspicious class name into a class name string and puts it into the state memory; The relevant method finds the agent by retrieving the class name string from the state memory and using it as a suspicious class name.

[0011] Furthermore, the method also includes: The method document enhancement agent inputs the enhanced method document into the result parser; The result parser parses the enhanced method document into a mapping structure of method name and document and puts it into the state memory; The relevant methods find that the agent obtains the mapping structure through the state memory and uses it as an enhanced method document.

[0012] Secondly, embodiments of this application provide a code defect localization device based on multiple agents, including a program analysis component, a fault understanding agent, a code library navigation agent, a method review agent, and a method localization agent; The program analysis component is used to obtain test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stacks, and method-level coverage of multiple covered classes based on test cases that failed and the project codebase. The fault understanding agent is used to perform test behavior analysis and test failure analysis based on test code, test utility code, test code execution results and exception stacks, and obtain a list of possible causes of failure. The codebase navigation agent is used to analyze the list of relevant methods based on the list of possible causes of failure, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class. The method review agent is used to obtain the source code corresponding to each method in the relevant method list in the project code library, and to review the source code corresponding to each method one by one to obtain a list of suspicious methods; The method localization agent is used to generate defect localization methods and corresponding repair code based on the analysis records of the list of suspicious methods and the fault understanding agent and code repository navigation agent.

[0013] Thirdly, embodiments of this application provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the steps of the multi-agent-based code defect localization method as described in any of the above embodiments.

[0014] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the multi-agent-based code defect localization method as described in any of the above embodiments.

[0015] In summary, compared with the prior art, the beneficial effects of the technical solution provided in this application include at least the following: This application provides a multi-agent-based code defect localization method that decomposes the defect localization process in a project codebase into multiple steps executed by a program analysis component and multiple agents. This multi-step approach allows for more controllable model input. First, the program analysis component constructs an intelligent retrieval mechanism for the project codebase based on failed test cases, extracting and generating information related to code defects and inputting it into agents with different functions. Then, multiple agents use this defect-related information and a large language model to gradually perform fault analysis and defect localization in the project codebase. This avoids excessively long contexts without losing the structure and functionality between different methods and functions, achieving automatic defect localization and repair at the project level. Furthermore, this application outperforms other existing LBFL technologies and LLM-based methods on Defects4j-v1.2.0 and Defects4J-v2.0.0, detecting over 70% of bugs and providing a repair solution for a single bug in an average of only 80 seconds. Attached Figure Description

[0016] Figure 1 A flowchart of a multi-agent-based code defect localization method provided for an exemplary embodiment of this application.

[0017] Figure 2 A flowchart of a multi-agent-based code defect localization method provided as another exemplary embodiment of this application. Detailed Implementation

[0018] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0019] 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.

[0020] Please see Figure 1 This application provides a multi-agent-based code defect localization method, including: Step S1: The program analysis component obtains the test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stack traces, and method-level coverage of multiple covered classes based on the failed test cases and the project codebase. Specifically, the above step may include the following sub-steps: Step S11: The program analysis component obtains the test cases and project code library that failed the test.

[0021] In this application, test cases refer to code files for unit tests or integration tests, or manual test scripts written according to templates. The project code library refers to the code objects for which defects need to be detected in this application.

[0022] Step S12: Execute test cases on the project codebase to obtain the test code execution results.

[0023] Step S13: Use the code that executes the test cases as the test code, and record the method call trace and exception stack of the test cases through a lightweight proxy program during the execution of the test cases.

[0024] Step S14: Perform static analysis on the test code and method call trace to obtain the test utility code.

[0025] Specifically, existing algorithms are used to statically analyze the test code and the corresponding method call traces, identify non-@Test helper methods and extract the called utility methods to obtain practical test code.

[0026] Step S15: parse the method call trace to obtain the list of overridden classes and the list of overridden methods.

[0027] Specifically, the method names in the method call trace are added to the list of overridden methods, the class names in the method call trace are added to the list of overridden classes, and the overridden code blocks are marked so that the source code of the classes can be determined more quickly in the next step.

[0028] Step S16: Search the source code corresponding to each class name in the overriding class list in the project code library; obtain the total number of methods of the overriding class corresponding to the class name and the number of overriding methods falling into the overriding method list based on the source code corresponding to the class name, and use the ratio of the number of overriding methods to the total number of methods as the method coverage rate of the overriding class.

[0029] Step S17: Sort the method coverage rates of each coverage class in the coverage class list in descending order, and use a preset number of method coverage rates in the sorted list as input data for the code library navigation agent.

[0030] It should be noted that, in order to address the issue of too many classes involved, and considering that fixes tend to occur in classes with high method-level coverage, this application effectively reduces the number of classes involved by retaining a preset number of classes with relatively high method-level coverage, while ensuring that performance is not affected. In the specific implementation, this application sets the preset number to 50, thereby ensuring that defective method-level coverage is retained with a probability of over 98%.

[0031] In step S2, the fault understanding agent performs test behavior analysis and test failure analysis based on the test code, test utility code, test code execution results, and exception stack, and obtains a list of possible causes of failure.

[0032] Please see Figure 2 Among them, the fault understanding agent includes the test behavior analysis agent and the test failure analysis agent.

[0033] Specifically, the aforementioned fault-understanding agent performs test behavior analysis and test failure analysis based on the test code, test utility code, test code execution results, and exception stack traces, obtaining a list of possible failure causes, including: Step S21: The test behavior analysis agent obtains the first prompt word, inputs the first prompt word, test code, and test utility code into the large language model to obtain the test behavior description.

[0034] The first prompt word is generated by the prompt generator and is used to instruct the large language model to understand the test logic in the initial test process, summarize the test behavior, and obtain a description of the test behavior based on the test code and test utility code.

[0035] Step S22: The test failure analysis agent obtains the second prompt word, inputs the second prompt word, test behavior description, test code execution result and exception stack into the large language model to obtain a list of possible reasons for failure.

[0036] The second prompt word is generated by the prompt generator and is used to instruct the large language model to obtain a list of possible causes of failure based on the test behavior description, the test code execution result, and the exception stack output.

[0037] It can be assumed that, given the provision of test code, this application requires the LLM to describe the behavior of failed test cases in detail through a test behavior analysis task. Then, in the test failure analysis task, the previously obtained test behavior descriptions are combined with other test failure information (including exception stacks, test code execution results, etc.) to encourage the LLM to list possible causes of failure. As part of the intermediate thinking, these possible causes will provide guidance for the next step of the codebase navigation agent.

[0038] Furthermore, the method may also include: the test behavior analysis agent inputting the obtained test behavior description into the result parser; the result parser parsing the test behavior description into a structured test behavior description (e.g., JSON format) and placing it into a state memory; and the test failure analysis agent retrieving the test behavior description through the state memory.

[0039] Specifically, the result parser structures the data passed between different agents for use in subsequent tasks. Similarly, the list of possible failure reasons can also be parsed into a structured list of possible failure reasons by the result parser for the code library navigation agent to read. Example of a structured list of possible failure reasons: possible_causes: [reason 1, reason 2, …].

[0040] Step S3: The code repository navigation agent analyzes the list of possible causes of failure, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class to obtain the relevant method list.

[0041] Please see Figure 2 The code repository navigation agent includes a suspicious class search agent, a method documentation enhancement agent, and a related method lookup agent. These code repository navigation agents analyze a list of possible failure causes, a list of covered classes, a list of covered methods, and the method-level coverage of each covered class to obtain a list of related methods, including: Step S31: Search for suspicious class agents to obtain third prompt words, input the third prompt words, a list of possible reasons for failure, a list of coverage classes, and the method-level coverage of each coverage class into the large language model to obtain the suspicious class name.

[0042] The third prompt word is generated by the prompt generator and is used to instruct the large language model to output the most suspicious class name in the list of coverage classes based on the list of possible reasons for failure and the method-level coverage of each coverage class.

[0043] Step S32: The method document enhancement agent obtains the fourth prompt word and the method document, and inputs the fourth prompt word, the method document, and the list of covered methods into the large language model to obtain the enhanced method document.

[0044] The method documentation is the code documentation of various methods in the prior art. It may not be completely consistent with the code that implements the corresponding method in the project code library, or it may lack the implementation code of a certain method in the project code library.

[0045] The fourth prompt word is generated by the prompt generator and is used to instruct the large language model to generate or correct the code of each method in the project codebase based on the content of the method documentation, and use the corrected code as the enhanced method documentation.

[0046] The method may further include: the agent searching for suspicious classes inputs the obtained suspicious class names into the result parser; the result parser parses the suspicious class names into class name strings and puts them into the state memory; the agent searching for related methods retrieves the class name string from the state memory and uses it as the suspicious class name; it can be assumed that the data put into the state memory at this time is suspected_class: class name.

[0047] Step S33: The relevant method search agent obtains the fifth prompt word, and inputs the fifth prompt word, the suspicious class name, the enhanced method document, and the list of possible reasons for failure into the large language model to obtain the relevant method list.

[0048] The fifth prompt word is generated by the prompt generator and is used to instruct the large language model to filter the methods in the enhanced method documentation that may be related to the defect based on the list of possible causes of failure and the methods included in the class corresponding to the suspicious class name, so as to obtain a list of relevant methods.

[0049] Furthermore, the method also includes: a method document enhancement agent inputting the enhanced method document into a result parser; the result parser parsing the enhanced method document into a mapping structure of method name and document and placing it into a state memory; and a related method lookup agent obtaining the mapping structure through the state memory and using it as the enhanced method document.

[0050] Specifically, the mapping structure is enhanced_method_docs: {method name: enhanced documentation}. In addition, the list of related methods can also be parsed into a list of method names by the result parser, for example, related_methods: [method name 1, method name 2, …].

[0051] It is worth noting that, based on the list of possible causes of failure obtained by the fault understanding agent, the codebase navigation agent aims to identify all methods in the entire project codebase that are related to the list of possible causes of failure; the suspicious class search agent finds the most suspicious class among all covered classes during test execution and outputs it as a suspicious class name, while the related method search agent filters out methods that may be related to the suspicious class name. Since LLMs have demonstrated powerful capabilities in code summarization, this application further sets up a method documentation enhancement agent to enhance method documentation to address documentation inconsistencies.

[0052] Step S4: The method review agent obtains the source code corresponding to each method in the relevant method list in the project code library, and reviews the source code corresponding to each method one by one to obtain a list of suspicious methods.

[0053] Specifically, the method review agent obtains the sixth prompt word through the prompt generator, and inputs the sixth prompt word, the source code of a certain method, and all the information output by the program analysis component into the large language model. The sixth prompt word is used to instruct the large language model to judge whether the input method is suspicious and explain the reason. Then, it traverses the relevant method list and uses a multi-turn dialogue strategy to put the review result of each method (whether it is suspicious and the reason) into the suspicious method list.

[0054] To review all relevant methods, a straightforward approach is to submit the source code of all methods in a single request and ask the LLM to select the most suspicious method. However, in practice, it has been found that as the amount of code in the context increases, it becomes more difficult for the LLM to focus on the fault location, leading to a significant performance degradation. Therefore, this application requires a strategy to verify all suspicious methods while ensuring the accuracy of the review. A multi-turn dialogue strategy is employed in the above steps, enabling the LLM to analyze relevant methods one by one.

[0055] Furthermore, the list of suspicious methods can be parsed into a structured list of suspicious methods by the result parser so that the method location agent can read it, for example, method_review_results: [{method name: whether it is suspicious, reason},…].

[0056] Step S5: The method localization agent generates the defect localization method and corresponding repair code based on the analysis records of the suspicious method list, the fault understanding agent, and the code library navigation agent.

[0057] Specifically, the method localization agent obtains the seventh prompt word through the prompt generator, and then inputs the seventh prompt word and the list of suspicious methods back into the large language model. The seventh prompt word is used to instruct the large language model to refer to the context information (i.e., analysis records) generated by the previous agents, summarize all suspicious methods in the list of suspicious methods and the review results, and then determine the method most likely to be defective (i.e., the method with the most likely defect). Figure 2 The Top-1 method in the code provides a repair solution, outputting the defect location method, defect cause, and repair code.

[0058] The data obtained by the method-localized agent can be parsed by the result parser and output in the following format: top1_method: method name, defect_reason: reason, fix_solution: Fix code / description, suspicious_classes: [list of class names], other_suspicious_methods: [{method name, reason, fix}] It should be noted that the aforementioned suspicious search agents and related method search agents belong to the same type of agents, only the tasks they handle in this application are slightly different. This type of task agent is good at focusing on software architecture and is good at discovering program areas that may have problems. The method document enhancement agent, method review agent, and method location agent belong to the same type of task agent and are good at handling all tasks related to analyzing, verifying, and fixing test failures.

[0059] This application integrates four different types of task agents to drive the same large language model. Each task agent can be customized with specific system instructions and can use external components such as program analysis and result parser.

[0060] Regarding the external components set up in this application, it can be considered that standalone LLMs suffer from limited context length and performance instability. Therefore, this application integrates multiple external components to enhance the memory, reasoning, and tool usage capabilities of LLM-driven agents. In other words, the LLM acts as the brain of each agent, while the other components provide external capabilities to enable the LLM to effectively utilize the debugging context. First, the program analysis component is equipped with a lightweight agent program and static analysis driver, providing the necessary tools (such as testing and source code analysis) to perceive the test execution process. That is, the program analysis component acts as "external memory," retrieving relevant information from the entire project codebase on demand and inputting only the relevant parts into the LLM, thereby solving the problem of limited LLM context. Second, the result parser, state storage, and prompt generator components enable loops to drive pipeline operations of multiple tasks. Furthermore, the data from the program analysis component can also be stored in the state storage for individual agents to read.

[0061] The above embodiments provide a multi-agent-based code defect localization method that decomposes the defect localization process in a project codebase into multiple steps executed by a program analysis component and multiple agents. This multi-step approach allows for more controllable model input. First, the program analysis component constructs an intelligent retrieval mechanism for the project codebase based on failed test cases, extracting and generating information related to code defects and inputting it into agents with different functions. Then, multiple agents use this defect-related information and a large language model to gradually perform fault analysis and defect localization in the project codebase. This avoids excessively long contexts without losing the structure and functionality between different methods and functions, achieving automatic defect localization and repair at the project level. Furthermore, this application outperforms other existing LBFL technologies and LLM-based methods on Defects4j-v1.2.0 and Defects4J-v2.0.0, detecting over 70% of bugs and providing a repair solution for a single bug in an average of only 80 seconds.

[0062] Another embodiment of this application provides a code defect localization device based on multiple agents, including a program analysis component, a fault understanding agent, a code library navigation agent, a method review agent, and a method localization agent.

[0063] The program analysis component is used to obtain test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stacks, and method-level coverage of multiple covered classes based on failed test cases and the project codebase.

[0064] The fault understanding agent is used to analyze test behavior and test failure based on test code, test utility code, test code execution results, and exception stacks, and obtain a list of possible causes of failure.

[0065] The codebase navigation agent is used to analyze the list of relevant methods based on the list of possible causes of failure, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class.

[0066] The method review agent is used to obtain the source code corresponding to each method in the relevant method list in the project code library, and to review the source code corresponding to each method one by one to obtain a list of suspicious methods.

[0067] The method localization agent is used to generate defect localization methods and corresponding repair code based on the analysis records of the list of suspicious methods and the fault understanding agent and code repository navigation agent.

[0068] The specific limitations of the code defect localization device based on multi-agent systems provided in this embodiment can be found in the embodiment of the code defect localization method based on multi-agent systems described above, and will not be repeated here. Each module in the above-described code defect localization device based on multi-agent systems can be implemented entirely or partially through software, hardware, or a combination thereof. Each module can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0069] This application provides a computer device that may include a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it causes the processor to perform the steps of a multi-agent code defect localization method as described in any of the above embodiments.

[0070] The working process, working details, and technical effects of the computer device provided in this embodiment can be found in the embodiment of a code defect localization method based on multi-agent systems described above, and will not be repeated here.

[0071] This application provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the steps of a multi-agent-based code defect localization method as described in any of the above embodiments. The computer-readable storage medium refers to a data storage carrier, which may include, but is not limited to, floppy disks, optical disks, hard disks, flash memory, USB flash drives, and / or Memory Sticks. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The working process, details, and technical effects of the computer-readable storage medium provided in this embodiment can be found in the embodiments of a multi-agent-based code defect localization method described above, and will not be repeated here.

[0072] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM).

[0073] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0074] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A code defect localization method based on multi-agent systems, characterized in that, include: The program analysis component obtains test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stacks, and method-level coverage of multiple covered classes based on the test cases that failed and the project code library. The fault understanding agent performs test behavior analysis and test failure analysis based on the test code, the test utility code, the test code execution result, and the exception stack, and obtains a list of possible causes of failure. The code repository navigation agent analyzes the list of possible failure reasons, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class to obtain a list of relevant methods; The method review agent obtains the source code corresponding to each method in the relevant method list in the project code library, and reviews the source code corresponding to each method one by one to obtain a list of suspicious methods; The method localization agent generates defect localization methods and corresponding repair code based on the list of suspicious methods and the analysis records of the fault understanding agent and the code library navigation agent.

2. The code defect localization method based on multi-agent technology according to claim 1, characterized in that, The program analysis component obtains test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stack traces, and method-level coverage of multiple covered classes based on the failed test cases and the project codebase, including: The program analysis component retrieves test cases and project codebases that failed tests; The test cases are executed on the project codebase to obtain the test code execution results; The code that executes the test cases will be used as the test code, and a lightweight proxy program will be used to record the method call path and exception stack of the test cases during the execution of the test cases. Static analysis is performed on the test code and the method call trajectory to obtain the test utility code; Analyze the method call trace to obtain the list of overridden classes and the list of overridden methods; Search the source code corresponding to each class name in the overriding class list in the project code library; obtain the total number of methods of the overriding class corresponding to the class name and the number of overriding methods falling into the overriding method list based on the source code corresponding to the class name; and take the ratio of the number of overriding methods to the total number of methods as the method-level coverage rate of the overriding class. The method-level coverage rates of each coverage class in the coverage class list are sorted in descending order, and a preset number of method-level coverage rates in the sorted list are used as input data for the code library navigation agent.

3. The code defect localization method based on multi-agent technology according to claim 2, characterized in that, The fault understanding agent includes a test behavior analysis agent and a test failure analysis agent; The fault understanding agent performs test behavior analysis and test failure analysis based on the test code, the test utility code, the test code execution result, and the exception stack, obtaining a list of possible failure causes, including: The test behavior analysis agent obtains the first prompt word, and inputs the first prompt word, the test code, and the test utility code into the large language model to obtain a test behavior description. The test failure analysis agent obtains a second prompt word, and inputs the second prompt word, the test behavior description, the test code execution result, and the exception stack into a large language model to obtain a list of possible reasons for failure.

4. The code defect localization method based on multi-agent technology according to claim 3, characterized in that, The code repository navigation agent includes a suspicious class search agent, a method document enhancement agent, and a related method search agent; The codebase navigation agent analyzes the list of possible failure causes, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class to obtain a relevant method list, including: The search agent for suspicious classes obtains a third prompt word, and inputs the third prompt word, the list of possible reasons for failure, the list of coverage classes, and the method-level coverage of each coverage class into the large language model to obtain the name of the suspicious class. The method document enhancement agent obtains the fourth prompt word and the method document, and inputs the fourth prompt word, the method document, and the list of covered methods into the large language model to obtain the enhanced method document; The relevant method searches for the agent to obtain the fifth prompt word, and inputs the fifth prompt word, the suspicious class name, the enhanced method document, and the list of possible reasons for failure into the large language model to obtain the relevant method list.

5. The code defect localization method based on multi-agent technology according to claim 3, characterized in that, Also includes: The test behavior analysis agent inputs the obtained test behavior description into the result parser; The result parser parses the test behavior description into a structured test behavior description and puts it into the state memory; The test failure analysis agent obtains the test behavior description through the state memory.

6. The code defect localization method based on multi-agent technology according to claim 4, characterized in that, Also includes: The search agent for suspicious categories inputs the obtained suspicious category names into the result parser. The result parser parses the suspicious class name into a class name string and puts it into the state memory; The relevant method finds the agent by retrieving the class name string from the state memory and using it as the suspected class name.

7. The code defect localization method based on multi-agent technology according to claim 4, characterized in that, Also includes: The method document enhancement agent inputs the enhanced method document into the result parser; The result parser parses the enhanced method document into a mapping structure of method name and document and puts it into the state memory; The relevant method finds the agent by obtaining the mapping structure through a state memory and using it as an enhanced method document.

8. A code defect localization device based on multi-agent systems, characterized in that, This includes a program analysis component, a fault understanding agent, a codebase navigation agent, a method review agent, and a method location agent; The program analysis component is used to obtain test code, test code execution results, test utility code, a list of covered classes, a list of covered methods, exception stacks, and method-level coverage of multiple covered classes based on test cases that failed and the project codebase. The fault understanding agent is used to perform test behavior analysis and test failure analysis based on the test code, the test utility code, the test code execution result and the exception stack, and obtain a list of possible causes of failure. The code repository navigation agent is used to analyze the list of possible failure causes, the list of covered classes, the list of covered methods, and the method-level coverage of each covered class to obtain a list of relevant methods; The method review agent is used to obtain the source code corresponding to each method in the relevant method list in the project code library, and to review the source code corresponding to each method one by one to obtain a list of suspicious methods; The method localization agent is used to generate defect localization methods and corresponding repair code based on the analysis records of the suspected method list, the fault understanding agent, and the code library navigation agent.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the multi-agent-based code defect localization method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the multi-agent-based code defect localization method as described in any one of claims 1 to 7.