CN-122019347-A - Code defect positioning method and device based on multiple agents
Abstract
The application belongs to the technical field of code detection and discloses a code defect positioning method and device based on multiple intelligent agents, wherein the method comprises the steps that a fault understanding intelligent agent performs test behavior analysis and test failure analysis according to test codes, test practical codes and abnormal stacks to obtain a failure possible reason list; the method comprises the steps of obtaining a fault possible cause list, a coverage class list, a coverage method list and method level coverage rate of each coverage class by a code library navigation agent, obtaining a related method list by the code library navigation agent, obtaining a suspicious method list by the method examination agent after obtaining source codes corresponding to each method in a project code library in the related method list, and generating a defect positioning method by the method positioning agent according to the suspicious method list, the fault understanding agent and analysis records of the code library navigation agent. The application can solve the problem that the large language model is difficult to diagnose errors in a large code range in the project-level code defect positioning.
Inventors
- ZHANG SHUAI
- ZHOU YUE
- XU JIE
Assignees
- 中移(苏州)软件技术有限公司
- 中国移动通信集团有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260115
Claims (10)
- 1. The code defect positioning method based on the multiple agents is characterized by comprising the following steps of: The program analysis component obtains test codes, test code execution results, test practical codes, a coverage class list, a coverage method list, an abnormal stack and method level coverage rate of a plurality of coverage classes according to test cases and project code libraries which fail to be tested; the fault understanding agent analyzes test behaviors and test failures according to the test codes, the test practical codes, the test code execution results and the abnormal stacks to obtain a possible failure reason list; The code base navigation agent analyzes based on the failure possible cause 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 examination agent acquires source codes corresponding to all methods in the related method list in the project code library, and examines the source codes corresponding to all the methods one by one to obtain a suspicious method list; And the method positioning agent generates a defect positioning method and a corresponding repair code according to the suspicious method list, the fault understanding agent and the analysis record of the code base navigation agent.
- 2. The multi-agent based code defect localization method of claim 1, wherein the program analysis component obtains the test code, test code execution results, test utility code, overlay class list, overlay method list, exception stack and method level coverage of a plurality of overlay classes from a test case and project code library that failed the test, comprising: The program analysis component acquires a test case and an item code base which fail to be tested; executing the test case on the project code library to obtain a test code execution result; Taking the code for executing the test case as the test code, and recording the method call track and the exception stack of the test case through a lightweight agent program in the process of executing the test case; Performing static analysis on the test code and the method call track to obtain the test practical code; Analyzing the method call track to obtain the coverage class list and the coverage method list; The method comprises the steps of searching source codes corresponding to each class name in a coverage class list in the item code library, obtaining the total method quantity of the coverage class corresponding to the class name and the coverage method quantity falling into the coverage method list according to the source codes corresponding to the class name, and taking the ratio of the coverage method quantity to the total method quantity as the coverage rate of the coverage class; And carrying out descending order sorting on the method level coverage rate of each coverage class in the coverage class list, and taking the method level coverage rate of the preset number in the sorting as the input data of the code base navigation intelligent agent.
- 3. The multi-agent based code defect localization method of claim 2, wherein the fault understanding agents comprise a test behavior analysis agent and a test failure analysis agent; The fault understanding agent performs test behavior analysis and test failure analysis according to the test code, the test practical code, the test code execution result and the exception stack to obtain a failure possible reason list, and the fault understanding agent comprises the following components: The test behavior analysis agent acquires a first prompt word, and inputs the first prompt word, the test code and the test practical code into a large language model to obtain test behavior description; And the test failure analysis agent acquires a second prompt word, and inputs the second prompt word, the test behavior description, the test code execution result and the abnormal stack into a large language model to obtain a failure possible reason list.
- 4. The multi-agent based code defect localization method of claim 3, wherein the code library navigation agents comprise search suspicious class agents, method document enhancement agents, and related method search agents; the code base navigation agent analyzes 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, and the code base navigation agent comprises the following steps: the suspicious class searching agent acquires a third prompting word, and inputs the third prompting word, the failure possible reason list, the coverage class list and the method-level coverage rate of each coverage class into a large language model to obtain suspicious class names; The method document enhancement agent acquires a fourth prompt word and a method document, and inputs the fourth prompt word, the method document and the coverage method list into a large language model to obtain an enhanced method document; And searching an agent by the related method to obtain a fifth prompt word, and inputting the fifth prompt word, the suspicious class name, the enhanced method document and the failure possible reason list into a large language model to obtain the related method list.
- 5. The multi-agent based code defect localization method of claim 3, further comprising: the test behavior analysis agent inputs the obtained test behavior description to a result analyzer; the result analyzer analyzes the test behavior description into a structured test behavior description and puts the structured test behavior description into a state memory; and the test failure analysis agent acquires the test behavior description through the state memory.
- 6. The multi-agent based code defect localization method of claim 4, further comprising: the suspicious class name obtained by the suspicious class searching agent is input to a result analyzer; the result parser parses the suspicious class name into class name strings and places the class name strings into a state memory; The correlation method searches the intelligent agent to obtain the class name symbol string through the state memory and uses the class name symbol string as the suspicious class name.
- 7. The multi-agent based code defect localization method of claim 4, further comprising: The method document enhancement agent inputs the enhanced method document to a result analyzer; The result analyzer analyzes the enhanced method document into a mapping structure of a method name and the document and puts the mapping structure into a state memory; The related method searches the agent to acquire the mapping structure through the state memory and uses the mapping structure as an enhanced method document.
- 8. The code defect positioning device based on the multiple agents is characterized by comprising a program analysis component, a fault understanding agent, a code library navigation agent, a method inspection agent and a method positioning agent; the program analysis component is used for obtaining test codes, test code execution results, test practical codes, an overlay class list, an overlay method list, an exception stack and method level coverage rate of a plurality of overlay classes according to test cases and project code libraries which fail to be tested; The fault understanding agent is used for carrying out test behavior analysis and test failure analysis according to the test code, the test practical code, the test code execution result and the abnormal stack to obtain a possible failure reason list; The code base navigation agent is used for analyzing 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 examination agent is used for acquiring source codes corresponding to all methods in the related method list in the project code library, and carrying out one-by-one examination on the source codes corresponding to all the methods to obtain a suspicious method list; the method positioning agent is used for generating a defect positioning method and a corresponding repair code according to the suspicious method list, the fault understanding agent and the analysis record of the code base navigation agent.
- 9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the multi-agent based code defect localization method according to any of claims 1 to 7 when the computer program is executed.
- 10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the multi-agent based code defect localization method according to any one of claims 1 to 7.
Description
Code defect positioning method and device based on multiple agents Technical Field The application relates to the technical field of code detection, in particular to a code defect positioning method and device based on multiple intelligent agents. Background Defect localization (FL) and Program Repair (PR) are indispensable and time-consuming phases in the software debugging process. A developer may take approximately half the debugging time to understand and locate the error before repairing the problematic code. To alleviate the burden on developers, automated techniques have been proposed for locating and repairing faults in system code. Automated techniques, which can automatically find problematic program entities, such as classes, methods, or statements, particularly spectrum-based defect localization (SBFL) and learning-based defect localization (LBFL), have been widely studied and applied. With the development of deep learning neural networks, the latest progress of Large Language Models (LLMs) brings new implications for defect localization repair. Through extensive code and text data training LLMs exhibits powerful natural language and code understanding capabilities, including detecting, locating, and repairing errors in code. However, existing LLMs-based defect localization repairs remain largely in the preliminary application phase through basic hints or fine tuning. In the actual use process, even if the large model prompt can be positioned to a rough error range, the large model prompt with pertinence is difficult to manually construct, the input of the whole project code library into the large language model is not realistic due to the input length limitation of the existing large language model, and a large amount of redundant information is inevitably introduced to influence the final defect positioning and repairing effect. Disclosure of Invention The application provides a code defect positioning method and device based on multiple agents, which can solve the problem that a large language model is difficult to diagnose errors in a large code range in project-level code defect positioning in the prior art. In a first aspect, an embodiment of the present application provides a code defect positioning method based on multiple agents, including: The program analysis component obtains test codes, test code execution results, test practical codes, a coverage class list, a coverage method list, an abnormal stack and method level coverage rate of a plurality of coverage classes according to test cases and project code libraries which fail to be tested; the fault understanding agent analyzes test behaviors and test failures according to the test codes, the test practical codes, the test code execution results and the abnormal stacks to obtain a possible failure reason list; the code base navigation agent analyzes based on the possible failure 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 examination agent acquires source codes corresponding to all methods in the related method list in the project code library, and examines the source codes corresponding to all the methods one by one to obtain a suspicious method list; And the method positioning agent generates a defect positioning method and a corresponding repair code according to the suspicious method list, the fault understanding agent and the analysis record of the code base navigation agent. Further, the program analysis component obtains a test code, a test code execution result, a test utility code, a coverage class list, a coverage method list, an exception stack and a method level coverage rate of a plurality of coverage classes according to a test case and an item code library which fail the test, and the program analysis component comprises: The program analysis component acquires a test case and an item code base which fail to be tested; Executing the test cases on the project code library to obtain test code execution results; Taking the code for executing the test case as a test code, and recording a method call track and an exception stack of the test case through a lightweight agent program in the process of executing the test case; performing static analysis on the test codes and the method call tracks to obtain test practical codes; Analyzing the method call track to obtain an overlay class list and an overlay method list; The method comprises the steps of searching source codes corresponding to each class name in a coverage class list in an item code library, obtaining the total method quantity of the coverage class corresponding to the class name and the coverage method quantity falling into the coverage method list according to the source codes corresponding to the class name, and taking the ratio of the coverage method quantity to the total method quantity as the coverage rate of the coverage class; and carr