Code defect positioning method and device

Through the combination of large language model and defect positioning algorithm, automated code defect positioning is realized, the problem of inefficiency of traditional manual positioning is solved, software maintenance efficiency and quality is improved, and it is suitable for a variety of programming languages ​​and defect information forms.

CN119311566APending Publication Date: 2025-01-14ALIPAY (HANGZHOU) INFORMATION TECH CO LTD +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411547291.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-01-14

AI Technical Summary

Technical Problem

The traditional manual code defect positioning method is inefficient and it is difficult to quickly locate defects in large-scale software systems, resulting in high software maintenance efficiency and cost.

Method used

A two-stage screening method based on a large language model is adopted. First, a candidate method sequence is generated through a large language model and a defect location algorithm. In the second stage, the defect location is accurately positioned through interactive inference, and multiple rounds of dialogue and external function search are used to improve positioning accuracy.

Benefits of technology

It realizes automated code defect positioning, improves software debugging efficiency and quality, reduces labor costs, and is suitable for a variety of programming languages ​​and defect information forms, without network connection, and protects user privacy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311566A_ABST
    Figure CN119311566A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a code defect positioning method and device, and the method comprises the steps: firstly, obtaining defect information related to a code defect; then, performing first interaction with a first large language model on the basis of the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defects according to the defect information; and meanwhile, inputting the defect information into a plurality of defect positioning algorithms to obtain a plurality of output second candidate methods. Next, a sequence of candidate methods is formed based on the plurality of first candidate methods and the plurality of second candidate methods. And finally, performing second interaction with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines a plurality of target candidate methods causing the code defects according to the defect information and the candidate method sequence.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of this specification relate to the field of machine learning, and in particular, to a method and apparatus for locating code defects. Background Art

[0002] Due to the increasing scale of software systems and the increasing complexity of code logic, code defects are usually unavoidable during the software development process. Code defects refer to problems that exist in software products and make the products unable to meet user needs and specifications and need to be fixed. Code defects not only affect the application of software products, but also cause economic losses. In order to reduce the adverse effects of code defects, developers need to continuously locate and fix existing code defects to improve the quality of the software. Among them, code defect location (hereinafter referred to as defect location) refers to finding the specific location of the defect in the code file. It is an important step in software maintenance and a prerequisite for defect repair.

[0003] Since the number of code files and codes in modern software systems is extremely large, the traditional manual defect location method is time-consuming, labor-intensive and inefficient for developers. Therefore, a method is needed to automatically locate code defects to reduce manpower consumption and improve the efficiency of overall software maintenance. Summary of the invention

[0004] One or more embodiments of this specification describe a code defect location method and device, which configures a large language model (Large Language Model) as an agent based on prompt engineering, and then inputs defect information into the agent and interacts with it to locate the specific location of the defect.

[0005] In a first aspect, a code defect location method is provided, comprising:

[0006] Get defect information related to code defects;

[0007] Performing a first interaction with a first large language model based on the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defect according to the defect information;

[0008] Inputting the defect information into a plurality of defect location algorithms to obtain a plurality of second candidate methods as output;

[0009] forming a candidate method sequence based on the plurality of first candidate methods and the plurality of second candidate methods;

[0010] A second interaction is performed with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

[0011] In a possible implementation manner, the defect information includes at least one of the following: program running error information, defect report, and test case.

[0012] In a possible implementation manner, the first interaction includes:

[0013] Inputting a first prompt word into the first large language model to set it as a first agent; the first prompt word instructs the first large language model to use an external function in a first external function list to locate the defect position according to the defect information, wherein the external function is used to search for content of a specific part in a code file and return a search result of a specific code element;

[0014] Conducting several rounds of dialogue with the first agent, each round of dialogue generating an execution result of the external function;

[0015] The first agent is instructed to determine a plurality of first candidate methods according to the defect information and contextual contents in each round of dialogue.

[0016] In a possible implementation, any round of dialogue among the multiple rounds of dialogue includes:

[0017] Instruct the first agent to give the external function used in this round according to the context of the dialogue;

[0018] Receiving a first target external function given by a first agent;

[0019] Execute the first target external function in the code file and input the function execution result to the first agent.

[0020] In a possible implementation, the first external function list includes: a first type of external function for accurately acquiring sub-code elements according to a specific code element name, and a second type of external function for fuzzily searching for code elements related to the specific code element name.

[0021] In a possible implementation, the first external function list also includes: an exit function that causes the first agent to actively exit the multi-round dialogue in advance.

[0022] In a possible implementation, the fuzzy search includes:

[0023] Get the full name of each code element in the code file;

[0024] The specific code element name to be searched is matched with the full name of each code element respectively in terms of similarity, and the full name with a similarity greater than a preset first threshold is added to the search results of the fuzzy search.

[0025] In a possible implementation manner, the input parameter of the first target external function is the name of the first code element; executing the first target external function in the code file includes:

[0026] Get the full name of each code element in the code file;

[0027] The first code element name is matched with the full name of each code element in terms of similarity, the first full name with a higher similarity ranking is used as an input parameter of the first target external function, and the first target external function is executed in the code file.

[0028] In a possible implementation manner, the plurality of defect location algorithms include at least one of the following: a defect location algorithm based on information retrieval, and a defect location algorithm based on spectrum.

[0029] In a possible implementation manner, the second interaction includes:

[0030] Inputting a second prompt word into the second large language model to set it as a second agent; the second prompt word instructs the second large language model to use an external function in a second external function list to locate the defect position according to the defect information and the candidate method sequence, wherein the external function is used to search for content of a specific part in the code file and return a search result of a specific code element;

[0031] Conducting several rounds of dialogue with the second agent, each round of dialogue generating an execution result of the external function;

[0032] The second agent is instructed to determine several target candidate methods according to the defect information, the candidate method sequence and the context content in each round of dialogue.

[0033] In a possible implementation, any round of dialogue among the multiple rounds of dialogue includes:

[0034] Instruct the second agent to give the external function used in this round according to the context of the dialogue;

[0035] Receiving a second target external function given by a second agent;

[0036] Execute the second target external function in the code file and input the function execution result to the second agent.

[0037] In a possible implementation manner, the second external function list includes: a fourth external function for acquiring a code snippet therein according to a method name.

[0038] In a possible implementation, the second external function list also includes: an exit function that causes the second agent to actively exit the multi-round dialogue in advance.

[0039] In a possible implementation manner, the input parameter of the second target external function is the name of the second code element; executing the second target external function in the code file includes:

[0040] Get the full name of each code element in the code file;

[0041] The second code element name is matched with the full name of each code element in terms of similarity, the second full name with a higher similarity ranking is used as an input parameter of the second target external function, and the second target external function is executed.

[0042] In a possible implementation, the code elements include: code files, classes, methods, and code snippets.

[0043] In a possible implementation, the similarity is determined based on the edit distance.

[0044] In a second aspect, a code defect location device is provided, comprising:

[0045] An acquisition unit configured to acquire defect information related to a code defect;

[0046] A first interaction unit is configured to perform a first interaction with a first large language model based on the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defect according to the defect information;

[0047] A defect location algorithm calling unit is configured to input the defect information into a plurality of defect location algorithms to obtain a plurality of output second candidate methods;

[0048] a candidate sequence determining unit, configured to form a candidate method sequence based on the plurality of first candidate methods and the plurality of second candidate methods;

[0049] The candidate method determination unit is configured to perform a second interaction with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

[0050] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method of the first aspect.

[0051] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method of the first aspect is implemented.

[0052] The code defect location method and device proposed in the embodiments of this specification are screened in two stages based on a large language model. In the first stage of rough screening, the method uses a large language model and several defect location algorithms to locate defects based on defect information, and obtains a preliminary candidate method sequence consisting of methods that may cause defects. Specifically, in the first stage, the large language model is configured as an intelligent agent through a prompting project, and then interacts with the intelligent agent based on the defect information, so that it uses a preset external function to search the content in the code file to locate the defect location according to the defect information.

[0053] In the second stage of fine screening, the method uses a large language model to further locate defects based on defect information and the candidate method sequence of the first stage to obtain the final candidate method that causes the code defect. Specifically, in the second stage, the large language model is configured as an intelligent agent through prompt engineering, and then interacts with the intelligent agent based on the defect information and the candidate method sequence, so that it uses preset external functions to search the content in the code file based on the defect information and the candidate method sequence to accurately locate the defect location.

[0054] The embodiments of this specification use an automated defect location method, which is more efficient and labor-saving than manual location, and does not rely on the skills and experience of developers. At the same time, since a large language model is used, it can accept defect information in various forms and is suitable for defect location needs in various development scenarios. In the selection of a large language model, any large language model that supports dialogue is suitable, especially a lightweight open source model. In addition, since the technical solution of the embodiments of this specification does not require networking, a locally deployed open source large language model that does not require a network connection can be used as an intelligent agent, and user privacy can be well protected. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the technical solutions of the multiple embodiments disclosed in this specification, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only the multiple embodiments disclosed in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0056] Figure 1 A schematic diagram showing an implementation scenario of a code defect location method according to an embodiment is shown;

[0057] Figure 2 A flowchart showing a method for locating a code defect according to an embodiment is shown;

[0058] Figure 3 A flow chart showing a round of dialogue with a first agent according to one embodiment;

[0059] Figure 4 A schematic diagram showing a scenario of a first interaction with a first agent according to an embodiment;

[0060] Figure 5 A flow chart showing a conversation with a second agent according to one embodiment;

[0061] Figure 6 A schematic diagram showing a scenario of performing a second interaction with a second agent according to one embodiment;

[0062] Figure 7 A schematic block diagram of a code defect location device according to an embodiment is shown. DETAILED DESCRIPTION

[0063] The solution provided in this specification is described below in conjunction with the accompanying drawings.

[0064] The task of code defect localization is to locate the location of defects in the software system based on defect information. Efficient and accurate defect localization can significantly improve debugging efficiency, thereby improving software quality and the productivity of software developers.

[0065] In reality, defect information exists in many forms, such as code error information when a program fails to run, description text of software defects reported by users and testers (hereinafter referred to as defect reports), and relevant information when a test case reports an error.

[0066] Traditional manual defect location is highly dependent on the skills and experience of engineers, and has limited efficiency. Due to the wide variety of programming languages ​​and defect information forms, some automated defect location methods in related technologies also have great limitations and are difficult to support multiple programming languages ​​and multiple forms of defect information. At the same time, some defect location methods in related technologies must rely on specific forms of defect information to locate defects, which is very limited.

[0067] Based on the above analysis, the embodiments of this specification propose a code defect location method to overcome the above problems and automatically locate code defects without limiting the type of programming language and the form of defect information. Figure 1 A schematic diagram of an implementation scenario of a code defect location method according to an embodiment is shown. Figure 1 In the example, first, defect information related to the code defect is obtained. The defect information may include one or more specific forms of information, such as program running error information, defect report, and test case. At the same time, optionally, the relevant code file that generates the defect is also obtained.

[0068] Then, using the first language model ( Figure 1 The first round of rough screening is performed using the corresponding large language model 1) and several defect location algorithms. The main purpose of the rough screening is to narrow the search space, and reduce the search space by several orders of magnitude from the set of all methods or functions (depending on the specific programming language, and the following takes the method as an example) in the code file to form a list of suspicious methods. Among them, the first interaction is performed with the first large language model based on the defect information, so that the first large language model determines multiple first candidate methods that cause code defects according to the defect information. Specifically, the first prompt word ( Figure 1 The corresponding prompt word 1) is input into the first language model, which is set as the first agent, and then multiple rounds of interactions are carried out with the first agent based on the defect information, so that it can gradually think and reason, and finally determine multiple first candidate methods. The specific content of the first prompt word and the specific process of multiple rounds of interactions will be described in detail in the subsequent parts of this specification.

[0069] At the same time, the defect information is input into several defect localization algorithms to obtain multiple second candidate methods as output. The defect localization algorithm can be a traditional defect localization method that is not based on a large language model. These methods each have corresponding limitations, such as the limited form of acceptable defect information, etc., and the flexibility is relatively insufficient, so the accuracy is also relatively limited. However, the localization results of these methods can be used as a supplement to the output results of the first intelligent agent, so in the rough screening stage, traditional defect localization methods will also be introduced.

[0070] Then, a candidate method sequence of the rough screening stage is formed based on the plurality of first candidate methods and the plurality of second candidate methods, which includes a plurality of suspicious methods. The ordering method of each suspicious method in the candidate method sequence will also be described in detail later.

[0071] After obtaining the candidate method sequence, the second round of fine screening begins. The main purpose of fine screening is to reconfirm whether each suspicious method in the candidate method sequence is the method that causes the code defect, so as to further refine the final defect location result. Figure 1 The second interaction is performed with the corresponding large language model 2 in the code, so that the second large language model determines several target candidate methods that cause code defects based on the defect information and the candidate method sequence. Specifically, the second prompt word ( Figure 1 The corresponding prompt word 2) is input into the second language model, which is set as the second agent, and then multiple rounds of interactions are carried out with the second agent based on the defect information and the candidate method sequence, so that it can gradually think and reason, and finally determine several candidate methods that cause the defect. The specific content of the second prompt word and the specific process of multiple rounds of interactions will be described in detail in the subsequent parts of this specification.

[0072] Based on the narrowing of the search space in the first round of coarse screening and the refinement of the search results in the second round of fine screening, a defect location result with higher accuracy can be obtained.

[0073] The specific implementation steps of the above code defect location method are described below in conjunction with a specific embodiment.

[0074] Figure 2 A flowchart of a method for locating code defects according to an embodiment is shown. The execution subject of the method can be any platform or server or device cluster with computing and processing capabilities. Figure 2 As shown, the method at least includes: step 202, obtaining defect information related to the code defect. Step 204, performing a first interaction with the first large language model based on the defect information, so that the first large language model determines multiple first candidate methods that cause the code defect according to the defect information. Step 206, inputting the defect information into a number of defect location algorithms to obtain multiple second candidate methods as output. Step 208, forming a candidate method sequence based on the multiple first candidate methods and the multiple second candidate methods. Step 210, performing a second interaction with the second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

[0075] The specific execution process of each of the above steps is described below.

[0076] First, in step 202, defect information related to code defects is obtained.

[0077] The code can be a program code written in any programming language, such as C++, Java, etc. The following examples take Java as an example.

[0078] Code defects can be code snippets that cause software programs to fail to run, code snippets that cause test cases to fail to run, defects reported by users and testers, and so on.

[0079] Corresponding to code defects, defect information can also have many forms, such as code error information when the program fails to run, defect reports reported by users and testers, and test case information.

[0080] The test case may include a code snippet of the test case and the result of whether the software program passes or fails the test case. When the software program fails a test case, the test case will generate an error message. That is, the test case includes the test case code and the test case result.

[0081] For example, a bug report might look like this:

[0082] "Subject: DateTimeZone.getOffsetFromLocal has an error during daylight saving time transition.

[0083] Description: This may be due to a misunderstanding on my part, but from the comments in DateTimeZone.getOffsetFromLocal, given an ambiguous local time, the system returns the offset corresponding to the later of the two possible UTC moments - i.e. the larger offset..."

[0084] The error message of a test case can be as follows:

[0085] "public void test_DateTime_constructor_Moscow_Autumn(){

[0086] DateTime dt=new DateTime(2007,10,28,2,30,ZONE_MOSCOW);

[0087] assertEquals("2007-10-28T02:30:00.000+04:00",dt.toString());

[0088] The last line shown above failed with the following stack trace.

[0089] junit.framework.ComparisonFailure:expected:<...10-28T02:30:00.000+0[4]:00>but was:<...10-28T02:30:00.000+0[3]:00>

[0090] at junit.framework.Assert.assertEquals(Assert.java:100)

[0091] at

[0092] org.joda.time.TestDateTimeZoneCutover.test_DateTime_constructor_Moscow_Autumn(TestDateTimeZoneCutover.java:922)”

[0093] From the above examples, we can see that the content of different forms of defect information varies greatly. Some are in natural language form, some are output text of the program console, and there is no unified format. Traditional methods are difficult to be compatible with all types of defect information. With the stronger semantic understanding ability of the large language model, it can be better compatible with more types of defect information.

[0094] In one embodiment, the defect information includes at least one of the following: program running error information, defect report, and test case.

[0095] Then, in step 204, a first interaction is performed with a first large language model based on the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defect according to the defect information.

[0096] The first language model may be any pre-trained language model, or any open source or closed source language model, and is not limited here. The interaction with the first language model may be based on a prompt.

[0097] In some possible implementations, the first interaction includes three parts: task assignment, multi-round dialogue based on external functions, and summary. These three parts correspond to step 2041, step 2042, and step 2043, respectively, that is, the first interaction includes steps 2041 to 2043.

[0098] In the task assignment of step 2041, a first prompt word is input into the first large language model to set it as the first agent; the first prompt word instructs the first large language model to use an external function in a first external function list to locate the defect position according to the defect information, and the external function is used to search for the content of a specific part in the code file and return the search result of a specific code element.

[0099] The first prompt word includes at least the following contents: text describing the role played by the large language model, text describing the task of the large language model, text giving a list of external functions and explaining the purpose of each external function, and text describing specific defect information.

[0100] In one embodiment, the first prompt word may be as follows:

[0101] "You are a debugging assistant for Java software. You will receive a bug report, some test case error information, and tools for accessing the software source code (external functions). Your task is to find the top k methods that are most likely to have problems based on the bug report, test cases, and the information retrieved through the given external functions. The list of external functions you can use is as follows: [list of external functions]. The specific contents of the bug report are as follows: [bug report]. The specific contents of the test case are as follows: [test case]."

[0102] Among them, [External Function List], [Defect Report], and [Test Case] ​​are placeholders, which are used to fill in the specific contents of the external function list, defect report, and test case respectively.

[0103] It should be noted that there can be multiple test cases, and only a small number of test cases may fail to pass during the test, generating error messages. In the embodiments of this specification, when using prompt words to interact with the agent, in order to save context length, the specific content of the test case input in the prompt word can be the error message of the failed test case and the specific code of the test case, rather than all the test cases.

[0104] Depending on the specific content contained in the defect information, the specific content of the part showing the defect information in the first prompt word will also be different. It usually includes two parts: explanatory text and specific content. The explanatory text can be, for example: "The specific content of xxx is as follows:". The content in the first prompt word can be adjusted according to the specific content in the input defect information. For example, if there is no defect report, the content related to the defect report will be deleted from the example of the first prompt word mentioned above.

[0105] In other embodiments, other content may be added to the first prompt word according to specific needs, for example, text for setting the maximum number of rounds of multi-round dialogue in step 2042.

[0106] The first agent after setting can be called Agent4SR.

[0107] The first external function list may include multiple external functions, which are used to help the first agent obtain relevant information about defects in the code file. The external function is used to search for the content of a specific part of the code file and return the search result of a specific code element.

[0108] Code elements are components of code and are divided into different levels. For example, in the Java language, code elements can include: code files, classes, methods, and code snippets. There is a preset inclusion relationship between them.

[0109] In theory, all the code content in the code file can be input into the first agent, and it can be made to search the code content in the code file by itself without using external functions. However, this approach will not only consume a lot of resources, but also greatly increase the computational complexity of the large language model. At the same time, due to the long context length, it will also greatly reduce the performance of the large language model. Therefore, the embodiment of this specification introduces external functions to assist the first agent in obtaining the code snippets it needs to overcome the above problems.

[0110] In some possible implementations, the first external function list includes: a first type of external function for accurately obtaining sub-code elements in a specific code element according to a specific code element name, and a second type of external function for fuzzily searching for code elements related to the specific code element name.

[0111] In one embodiment, the first category of external functions may include: a first external function get_paths for obtaining the path of a code file, a second external function get_classes_of_path for obtaining all classes in the code file, a third external function get_methods_of_class for obtaining all methods in a specific class, and a fourth external function get_code_snippet_of_method for obtaining a code snippet in a specific method.

[0112] The last three of the four external functions above receive arguments that are fully qualified names (FQNs) of code elements. Fully qualified names are used to uniquely identify specific code elements in a code file. For example, in Java, the fully qualified name of a method includes the file path, class name, method name, and method signature. Formally, it can be written as PathName.ClassName.MethodName(ArgTypeList). For example, the fully qualified name of the method getOffsetFromLocal in the defect report in the previous example can be org.joda.time.DateTimeZone.getOffsetFromLocal(long), where org.joda.time is the file path, DateTimeZone is the class name, getOffsetFromLocal is the method name, and (long) is the method signature.

[0113] In one embodiment, the second type of external functions may include: a fifth external function find_class for fuzzy searching a class according to a class name, and a sixth external function find_method for fuzzy searching a method according to a method name.

[0114] Since the first-class external functions often return a list of all sub-code elements of a specific code element, among which there may be only 1-2 sub-code elements that are actually related to the code defect, and the others are irrelevant code elements, this will greatly waste the context length and token resources of the large language model. Moreover, the use of the first-class external functions often requires starting from the first external function and accessing specific classes and code snippets layer by layer, which will also consume more dialogue resources. At the same time, due to the hallucination problem common in large language models, the agent may not be able to fully say the fully qualified name, but may only say part of the name, such as for a method, only say its method name. Alternatively, the agent may not be able to accurately say the name of a specific code element, for example, saying FixedDateTimeZone as DateTimeZone.

[0115] In order to solve the aforementioned problem, the embodiment of this specification designs a second type of external function, which can fuzzily search for various classes or methods related thereto based on an incomplete class name or method name.

[0116] Specifically, the fuzzy search includes: obtaining the full name of each code element in the code file; performing similarity matching between the specific code element name to be searched and the full name of each code element, and adding the full name with a similarity greater than a preset first threshold to the search results of the fuzzy search.

[0117] The complete name above may be a fully qualified name.

[0118] For example, for the incomplete method name getOffsetFromLocal, the results of executing the sixth external function find_method(getOffsetFromLocal) may include org.joda.time.DateTimeZone.getOffsetFromLocal(long) and org.joda.time.tz.FixedDateTimeZone.getOffsetFromLocal(long).

[0119] In one embodiment, the similarity in the aforementioned fuzzy search can be determined based on the edit distance (Levenshtein distance). The edit distance is used to measure the difference between two strings. It is defined as the minimum number of editing operations required to convert one string into another string. These operations include inserting, deleting, and replacing single characters. Using the edit distance to measure similarity can well deal with the hallucination problem of large language models, especially when inaccurate code element names are spoken. The smaller the edit distance between two strings, the greater the similarity.

[0120] At the same time, it should be noted that, since only a part of the fully qualified name is directly related to a specific code element, before the specific code element name to be searched is matched with the full name of each code element for similarity, a string segmentation operation, such as spilt, is required. The full name is split into multiple string fragments, and each string fragment is matched for similarity with the specific code element name. For example, the full name org.joda.time.DateTimeZone.getOffsetFromLocal is split into five parts: org, joda, time, DateTimeZone, and getOffsetFromLocal according to the period symbol ".", and then the five parts are matched for similarity with the specific code element name, and the similarity of the part with the greatest similarity is taken as the result of the similarity matching.

[0121] In some possible implementations, the first external function list also includes: an exit function exit that enables the first agent to actively exit the multi-round dialogue in step 2042 in advance.

[0122] When the agent believes that the contextual information it has collected in the conversation is sufficient for reasoning, it can choose to use the exit function to exit the multi-round conversation early to save token resources.

[0123] The above seven external functions can be summarized as shown in Table 1.

[0124] Table 1 External function list

[0125] name parameter describe get_paths none Get the code file path get_classes_of_path Code file path name Get all classes in the code file get_methods_of_class Class Name Get all methods in a class get_code_snippet_of_method Method Name Get the code snippet in the method find_class Class Name Fuzzy search for similar classes based on class name find_method Method Name Fuzzy search similar methods according to method exit none Exit multi-turn conversation

[0126] In other possible implementations, other types of external functions may be set, for example, external functions for searching for specific code snippets, etc., which are not limited here.

[0127] Then, returning to the first interaction, in the multi-round dialogue based on the external function in step 2042, several rounds of dialogue are conducted with the first agent, and each round of dialogue generates the execution result of the external function.

[0128] Specifically, any of the multiple rounds of dialogue in step 2042 may include: Figure 3 Steps 302 to 306 are shown. Figure 3 A flow chart of conducting a conversation with a first agent according to one embodiment is shown.

[0129] In step 302, the first agent is instructed to give an external function to be used in this round according to the context of the dialogue.

[0130] The prompt words can be used to instruct the first agent. For example, the prompt words "Now in a line of text, call an external function in the following form without any other explanation: FunctionName(Argument)" are input into the first agent.

[0131] By using this prompt word, the first agent can focus on the use of the external function instead of focusing on the explanation. At the same time, it is also easier to extract the first target external function to be executed from the first agent's reply.

[0132] Then, in step 304, a first target external function given by the first agent is received.

[0133] In one embodiment, the first target external function may be a first-class external function, such as get_methods_of_class("DateTimeZone"). In another embodiment, the first target external function may be a second-class external function, such as find_class("DateTimeZone").

[0134] It should be noted that the first agent may be a large language model without the ability to call functions. Therefore, in the single-round dialogue of step 2042, the subject that calls and executes the function is the method execution subject of the embodiment of this specification, rather than the first agent.

[0135] Next, in step 306, the first target external function is executed in the code file, and the function execution result is input to the first agent.

[0136] In one embodiment, the first target external function is a first type of external function, that is, an external function that accurately returns search results, and the input parameter of the first target external function is the first code element name. Step 306 of executing the first target external function in the code file includes: obtaining the complete name of each code element in the code file; performing similarity matching between the first code element name and the complete name of each code element, using the first complete name with the highest similarity ranking as the input parameter of the first target external function, and executing the first target external function in the code file.

[0137] The first complete name may be a fully qualified name. The similarity matching may be based on the edit distance, and the first complete name with the smallest edit distance to the first code element name is used as an input parameter of the first target external function. Then, the first target external function is executed in the code file, and a function execution result is obtained and input to the first agent.

[0138] The above embodiments are still intended to address the hallucination problem of large language models. When the first agent cannot accurately give the fully qualified name to be searched, a similarity match is first performed to determine the corresponding fully qualified name, and then the corresponding external function is executed to obtain a more accurate search result.

[0139] For example, when the first target external function is get_methods_of_class("DateTimeZone"), first perform similarity matching between "DateTimeZone" and the full name of each code element to obtain the first full name org.joda.time.DateTimeZone with the highest similarity ranking, and then execute get_methods_of_class("org.joda.time.DateTimeZone") in the code file to obtain all methods in the class and input them into the first agent.

[0140] For another example, when the first target external function is find_class("DateTimeZone"), since find_class belongs to the second category of external functions and has its own fuzzy search function, find_class("DateTimeZone") is directly executed in the code file to obtain the search result org.joda.time.DateTimeZone and input it into the first agent.

[0141] By having the method execution subject of the embodiment of this specification be responsible for the specific function call in step 306, more types of large language models can be compatible, rather than being limited to large language models with function call capabilities.

[0142] In one embodiment, when the first target external function is an exit function, the multi-round dialogue is ended and the process proceeds to step 2043 .

[0143] When the number of rounds of the multi-round dialogue exceeds a preset maximum value, the multi-round dialogue is terminated and the process proceeds to step 2043 .

[0144] In other embodiments, step 2042 may also use other forms of single-round dialogue. For example, after the first agent gives the first target external function, it checks whether the input parameters of the first target external function are complete. If not, it instructs the first agent to check its own output and give the first target external function again. This is not limited here.

[0145] In some possible implementations, before the several rounds of dialogue in step 2042, the method further includes:

[0146] Instruct the first agent to perform step-by-step reasoning based on the execution result of the external function to locate the defect position.

[0147] In this step, a prompt word may be used to instruct the first agent. In one embodiment, the prompt word may be: "Let us locate the defective method step by step through reasoning and the execution results of the external function. Now let us reason and plan how to locate the defective method."

[0148] Through this prompt, the first agent is first prompted to reason and plan how to use the external function to help it organize its thoughts and develop a corresponding defect location strategy. Through reasoning, the first agent is able to form clear hypotheses about the possible location of the defect and the cause of the defect. This prepares the first agent for subsequent interactions with the external function, allowing it to take corresponding actions based on these hypotheses to collect more specific information or confirm its hypothesis.

[0149] Next, in the summary of step 2043, the first agent is instructed to determine multiple first candidate methods based on the defect information and the contextual content in each round of dialogue.

[0150] The first agent can be instructed using a prompt. For example, the prompt is “Based on the available information, please provide the full names of the top k methods that are most likely to cause the defect. Since your answer will be processed automatically, please provide your answer in the following format:

[0151] Top_1:

[0152] PathName.ClassName.MethodName(ArgType1,ArgType2)

[0153] Top_2:

[0154] ..."

[0155] Input into the first agent.

[0156] Through this prompt word, it can be emphasized again that the first agent should give multiple first candidate methods that it has inferred based on the defect information and the context content in each round of dialogue.

[0157] In other possible implementations, the defect information may be directly input into the first large language model, and the model is instructed to infer multiple first candidate methods that cause the code defect based on the defect information. For example, the prompt "Please infer the possible method that causes the code defect based on the following defect information: [defect information]" is input into the first large language model, and then multiple first candidate methods are directly determined from the output of the first large language model. [defect information] represents a placeholder for filling in specific defect information text.

[0158] The first candidate method is a method that is determined by the first agent based on the defect information and that may cause code defects.

[0159] The above is the specific implementation process of step 204. A specific example of step 204 will be described below in conjunction with the accompanying drawings. Figure 4 A schematic diagram of a scene for performing a first interaction with a first agent according to an embodiment is shown. Figure 4 In the example of , the programming language is Java, and the defect information includes defect reports and test cases. In each dialog box, the display icon on the left represents the execution subject of the method of the embodiment of this specification, and the light bulb icon on the right represents the first agent.

[0160] In the task assignment of the first part, the first prompt word is input into the first large language model and it is set as the first agent.

[0161] In the second part of the multi-round dialogue based on external functions, the first agent is first instructed to perform step-by-step reasoning based on the execution results of the external function to locate the defect. Correspondingly, the first agent gives its preliminary conclusion based on the defect report and test case. Then, several rounds of dialogue are conducted with the first agent. In one round of dialogue, the first agent is first instructed to give the external function used in this round according to the context of the dialogue, and then the first target external function given by the first agent is obtained. Next, the first target external function is executed in the code file, and the function execution result is input into the first agent in the form of a dialogue to complete one round of dialogue. The multi-round dialogue ends after a maximum of MAX rounds (preset value), or ends when the first agent gives the exit function exit().

[0162] Then, in the summary of the third part, the first agent is instructed to determine k first candidate methods based on the defect information and the context content in each round of dialogue. Accordingly, the first agent outputs a list of top k candidate methods. The first interaction is completed.

[0163] Next, in step 206, the defect information is input into a plurality of defect location algorithms to obtain a plurality of second candidate methods as output.

[0164] The defect localization algorithm may be a traditional defect localization algorithm not based on a large language model, for example, a defect localization algorithm based on information retrieval, a defect localization algorithm based on spectrum, and a hybrid method of the above two methods.

[0165] It should be noted that, since these defect localization algorithms each require different types of defect information to be input, when the defect information obtained in step 202 cannot meet the requirements of a certain defect localization algorithm, the defect localization algorithm is not used, and only other defect localization algorithms that can meet the input requirements are used.

[0166] The second candidate method is a method that is determined by the defect localization algorithm based on defect information and that may cause code defects.

[0167] Then, in step 208, a candidate method sequence is formed based on the plurality of first candidate methods and the plurality of second candidate methods.

[0168] The first language model outputs multiple first candidate methods, and each defect location algorithm outputs multiple second candidate methods. These candidate methods need to be organized into a candidate method sequence.

[0169] The candidate method sequence may be unordered, that is, there is no order between the multiple first candidate methods and the multiple second candidate methods.

[0170] Preferably, the candidate method sequence can be ordered. If a candidate method ranks high in the sequence, it means that it is more likely to be the method that causes the defect. Specifically, according to the accuracy of each defect localization algorithm determined in advance, the second candidate method output by the defect localization algorithm with high accuracy can be arranged at the front of the sequence, and the second candidate method output by the defect localization algorithm with low accuracy can be arranged at the back of the sequence. Then, the first candidate methods output by the first language model are arranged at the end of the sequence.

[0171] Since the second agent used in the subsequent fine screening is similar to the first agent in configuration and information received, it can be considered that the second agent can pay attention to similar information as the first agent, that is, it can also draw conclusions similar to the multiple first candidate methods. Therefore, the multiple first candidate methods output by the first agent are arranged at the end of the sequence, so that the second agent pays more attention to the second candidate methods output by other defect location algorithms.

[0172] Finally, in step 210, a second interaction is performed with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

[0173] The second largest language model can be any pre-trained large language model, or any open source or closed source large language model, and is not limited here. The interaction with the second largest language model can be based on the prompt word.

[0174] In some possible implementations, the second interaction includes three parts: task assignment, multi-round dialogue based on external functions, and summary. These three parts correspond to step 2101, step 2102, and step 2103, respectively, that is, the second interaction includes steps 2101 to 2103.

[0175] In the task assignment of step 2101, a second prompt word is input into the second large language model to set it as a second agent; the second prompt word instructs the second large language model to use an external function in a second external function list to locate the defect position according to the defect information and the candidate method sequence, and the external function is used to search for the content of a specific part in the code file and return the search result of a specific code element.

[0176] The second prompt word includes at least the following: text describing the role played by the large language model, text describing the task of the large language model, text giving a list of external functions and explaining the purpose of each external function, text describing specific defect information, and text describing a candidate method sequence.

[0177] In one embodiment, the second prompt word may be as follows:

[0178] "You are a debugging assistant for Java software. You will receive a bug report, some test case error information, a list of candidate method sequences that may cause bugs, and tools for accessing the software source code (external functions). Your task is to find the top k methods that are most likely to cause problems from the list of candidate method sequences based on the bug report, test cases, and information retrieved through the given external functions. The list of external functions you can use is as follows: [external function list]. The specific content of the bug report is as follows: [defect report]. The specific content of the test case is as follows: [test case]. The specific content of the candidate method sequence is as follows: [candidate method sequence]."

[0179] Among them, [External function list], [Defect report], [Test case], and [Candidate method sequence] are placeholders, which are used to fill in the specific contents of the external function list, defect report, test case, and candidate method sequence, respectively.

[0180] Depending on the specific content contained in the defect information, the specific content of the part showing the defect information in the second prompt word will also be different. This can be referred to the record of the first prompt word in step 2041, which will not be repeated here.

[0181] In other embodiments, other content may be added to the second prompt word according to specific needs, for example, text for setting the maximum number of rounds of multi-round dialogue in step 2102.

[0182] The second agent after setting can be called Agent4LR.

[0183] Similar to the first external function list, the second external function list may also include multiple external functions, which are used to help the second agent obtain relevant information about defects in the code file.

[0184] Based on similar reasons as the first agent, the embodiment of this specification also does not input all code content into the second agent, but uses external functions to assist the second agent in obtaining the code fragments it needs.

[0185] In some possible implementations, the second external function list includes: a fourth external function get_code_snippet_of_method for obtaining a code snippet of a method according to the method name.

[0186] In a more specific embodiment, the parameter received by the fourth external function is the index of the method to be searched in the candidate method sequence.

[0187] Since each method in the candidate method sequence is given in the form of a fully qualified name, and the large language model has difficulty repeating these fully qualified names due to the hallucination problem, in this embodiment, the parameter received by the fourth external function is changed from the name of the method (fully qualified name) to the index number of the method, which can help the second agent better focus on the review of the candidate method. For example, 1 in get_code_snippet_of_method(1) represents the first method in the candidate method sequence.

[0188] In some possible implementations, the second external function list also includes: an exit function exit that enables the second agent to actively exit the multi-round dialogue in advance.

[0189] Unlike the first agent, in the preferred embodiment, only the fourth external function get_code_snippet_of_method is provided to the second agent. Since the main task of the second agent is to further streamline the methods in the list of candidate method sequences and find out the multiple methods that are most likely to cause defects. Therefore, the second agent does not need to search layer by layer from the beginning like the first agent, but can directly evaluate the possibility of each method in the candidate method sequence causing defects. Therefore, the second agent can only use the fourth external function get_code_snippet_of_method to save more attention and context length, and focus on checking the code snippets in each method in the candidate method sequence.

[0190] Then, in the multi-round dialogue based on the external function in step 2102, several rounds of dialogue are conducted with the second agent, and each round of dialogue generates the execution result of the external function.

[0191] Specifically, any of the multiple rounds of dialogue in step 2102 may include: Figure 5 Steps 502 to 506 are shown. Figure 5 A flow chart of conducting a conversation with a second agent according to one embodiment is shown.

[0192] In step 502, the second agent is instructed to give the external function used in this round according to the context of the dialogue.

[0193] The prompt words can be used to instruct the second agent. For example, the prompt words "Now in a line of text, call an external function in the following form without any other explanation: FunctionName(Argument)" are input into the second agent.

[0194] Through this prompt word, the second agent can focus on reasoning instead of focusing on the explanation. At the same time, it is also easier to extract the second target external function to be executed from the second agent's reply.

[0195] Then, in step 504, a second target external function given by the second agent is received.

[0196] It should be noted that the second agent may be a large language model without the ability to call functions. Therefore, in the single-round dialogue of step 2102, the subject that calls and executes the function is the method execution subject of the embodiment of this specification, rather than the second agent.

[0197] Next, in step 506, the second target external function is executed in the code file, and the function execution result is input to the second agent.

[0198] In one embodiment, the second target external function is the fourth external function get_code_snippet_of_method, and the input parameter of the second target external function is the second code element name. Step 506 of executing the second target external function in the code file includes: obtaining the complete name of each code element in the code file; performing similarity matching between the second code element name and the complete name of each code element, using the second complete name with the highest similarity ranking as the input parameter of the second target external function, and executing the second target external function.

[0199] The specific process of similarity matching and executing external functions can refer to the specific content of step 306, which will not be repeated here.

[0200] By having the method execution subject of the embodiment of this specification be responsible for the specific function call in step 506, more types of large language models can be compatible, rather than being limited to large language models with function call capabilities.

[0201] In one embodiment, when the second target external function is an exit function, the multi-round dialogue is ended and the process proceeds to step 2103 .

[0202] When the number of rounds of the multi-round dialogue exceeds a preset maximum value, the multi-round dialogue is terminated and the process proceeds to step 2103 .

[0203] In other embodiments, step 2102 may also use other forms of single-round dialogue. For example, after the second agent gives the second target external function, check whether the input parameters of the second target external function are complete. If not, instruct the second agent to check its own output and give the second target external function again. This is not limited here.

[0204] In some possible implementations, before the several rounds of dialogue in step 2102, the method further includes:

[0205] Instruct the second agent to perform step-by-step reasoning based on the execution result of the external function to locate the defect position.

[0206] In this step, a prompt word may be used to instruct the second agent. In one embodiment, the prompt word may be: "Let us locate the defective method step by step through reasoning and the execution results of the external function. Now let us reason and plan how to locate the defective method."

[0207] The reasons and beneficial effects of using this prompt word can be referred to the relevant records of the first intelligent agent, which will not be repeated here.

[0208] Next, in step 2103, the second agent is instructed to determine several target candidate methods based on the defect information, the candidate method sequence and the context content in each round of dialogue.

[0209] You can use prompt words to instruct the second agent. For example, the prompt word is "Based on the available information, please provide the full names of the top k methods that are most likely to cause the defect. Since your answer will be processed automatically, please provide your answer in the following format:

[0210] Top_1:

[0211] PathName.ClassName.MethodName(ArgType1,ArgType2)

[0212] Top_2:

[0213] ..."

[0214] Input into the second agent.

[0215] Through this prompt, it can be emphasized again that the second agent should select several target candidate methods that it thinks are most likely to cause defects from the candidate method sequence according to the defect information and the context content in each round of dialogue. In this step, the target candidate method output by the second agent may be one or more.

[0216] In other possible implementations, the defect information and candidate method sequence can also be directly input into the second largest language model, and it can be instructed to infer several target candidate methods that cause the code defect based on the defect information. For example, the prompt "Please infer the possible methods that cause the code defect based on the following defect information and candidate method sequence: [defect information], [candidate method sequence]" is input into the second largest language model, and then several target candidate methods are directly determined from the output of the second largest language model. Among them, [defect information] and [candidate method sequence] represent placeholders, which are used to fill in specific defect information text and candidate method sequence respectively.

[0217] The above is the specific implementation process of step 210. A specific example of step 210 will be described below in conjunction with the accompanying drawings. Figure 6 A schematic diagram of a scenario for performing a second interaction with a second agent according to an embodiment is shown. Figure 6 In the example of , the programming language is Java, and the defect information includes defect reports and test cases. In each dialog box, the display icon on the left represents the execution subject of the method of the embodiment of this specification, and the light bulb icon on the right represents the second agent.

[0218] In the task assignment of the first part, the first prompt word is input into the first large language model and it is set as the second agent.

[0219] In the second part of the multi-round dialogue based on external functions, the second agent is first instructed to perform step-by-step reasoning based on the execution results of the external function to locate the defect. Correspondingly, the second agent gives its preliminary conclusion based on the defect report, test cases, and candidate method sequences. Then, several rounds of dialogue are conducted with the second agent. In one round of dialogue, the second agent is first instructed to give the external function used in this round based on the context of the dialogue, and then the second target external function given by the second agent is obtained. Next, the second target external function is executed in the code file, and the function execution result is input into the second agent in the form of a dialogue to complete one round of dialogue. The multi-round dialogue ends after a maximum of MAX rounds (preset value), or ends when the second agent gives the exit function exit().

[0220] Then, in the summary of the third part, the second agent is instructed to determine k target candidate methods from the candidate method sequence based on the defect information and the context content in each round of dialogue. Accordingly, the second agent outputs a list of top k target candidate methods. The second interaction is completed.

[0221] The several target candidate methods obtained through the second interaction are the final results of the code defect location method of the embodiment of this specification, that is, the methods that cause code defects.

[0222] The code defect location method of the embodiment of this specification has the following advantages.

[0223] First, the two large language model-based intelligent agents in the embodiments of this specification share a similar interaction process, which does not presuppose or limit any form of defect information, thereby ensuring the flexibility of the method.

[0224] Secondly, the embodiment of this specification uses a combination of a defect localization algorithm that is not based on a large language model and the first agent in the rough screening stage. An appropriate defect localization algorithm is selected according to the specific form of the defect information to improve the overall flexibility. In addition, the use of a defect localization algorithm can effectively narrow the search space and exclude methods that are not related to the defect.

[0225] Third, the embodiments of this specification adopt a two-stage process. After the coarse screening in the first stage performs space reduction, the second stage of fine screening based on the large language model can make full use of the large language model's ability in code understanding and reasoning, and focus on checking the code snippets of the most suspicious methods. This design alleviates the impact of the limited context length of the large language model and its poor performance under long input contexts, which is particularly serious for open source large language models. Therefore, the embodiments of this specification can construct an agent based on any large language model to complete the corresponding task.

[0226] Fourth, since most large language models do not have the ability to call functions themselves, the embodiments of this specification design multiple external functions and use them as the main body for calling external functions, so that large language models without calling capabilities can also search code files and obtain corresponding information.

[0227] In addition, due to the hallucination problem of large language models, the embodiments of this specification use fuzzy search and similarity matching to enable the intelligent agent to accurately locate the specific code element that the intelligent agent really wants to output when generating incomplete or inaccurate code element names.

[0228] According to an embodiment of another aspect, a code defect locating device is also provided. Figure 7 FIG. 1 is a schematic block diagram of a code defect location device according to an embodiment, which can be deployed in any device, platform or device cluster with computing and processing capabilities. Figure 7 As shown, the device 700 includes:

[0229] The acquisition unit 702 is configured to acquire defect information related to the code defect;

[0230] A first interaction unit 704 is configured to perform a first interaction with a first large language model based on the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defect according to the defect information;

[0231] The defect localization algorithm calling unit 706 is configured to input the defect information into a plurality of defect localization algorithms to obtain a plurality of output second candidate methods;

[0232] A candidate sequence determining unit 708, configured to form a candidate method sequence based on the multiple first candidate methods and the multiple second candidate methods;

[0233] The candidate method determination unit 710 is configured to perform a second interaction with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

[0234] According to another aspect of the embodiment, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in any of the above embodiments.

[0235] According to yet another embodiment, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in any one of the above embodiments is implemented.

[0236] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0237] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0238] It should be noted that, in this article, relational terms such as first and second, etc. are only used 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. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0239] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0240] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A code defect location method, comprising: Get defect information related to code defects; Performing a first interaction with a first large language model based on the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defect according to the defect information; Inputting the defect information into a plurality of defect location algorithms to obtain a plurality of second candidate methods as output; forming a candidate method sequence based on the plurality of first candidate methods and the plurality of second candidate methods; A second interaction is performed with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

2. The method according to claim 1, wherein: The defect information includes at least one of the following: program running error information, defect report, and test case.

3. The method according to claim 1, wherein: The first interaction includes: Inputting a first prompt word into the first large language model to set it as a first agent; the first prompt word instructs the first large language model to use an external function in a first external function list to locate the defect position according to the defect information, wherein the external function is used to search for content of a specific part in a code file and return a search result of a specific code element; Conducting several rounds of dialogue with the first agent, each round of dialogue generating an execution result of the external function; The first agent is instructed to determine a plurality of first candidate methods according to the defect information and contextual contents in each round of dialogue.

4. The method according to claim 3, wherein: Any round of dialogue among the multiple rounds of dialogues includes: Instruct the first agent to give the external function used in this round according to the context of the dialogue; Receiving a first target external function given by a first agent; Execute the first target external function in the code file and input the function execution result to the first agent.

5. The method according to claim 3, wherein: The first external function list includes: a first type of external function for accurately obtaining sub-code elements in a specific code element according to a specific code element name, and a second type of external function for fuzzily searching for code elements related to the specific code element name.

6. The method according to claim 5, wherein: The first external function list also includes: an exit function that enables the first language model to actively exit the multi-round dialogue in advance.

7. The method according to claim 5, wherein: The fuzzy search includes: Get the full name of each code element in the code file; The specific code element name to be searched is matched with the full name of each code element respectively in terms of similarity, and the full name with a similarity greater than a preset first threshold is added to the search results of the fuzzy search.

8. The method according to claim 4, wherein the input parameter of the first target external function is a first code element name; Executing the first target external function in the code file includes: Get the full name of each code element in the code file; The first code element name is matched with the full name of each code element in terms of similarity, the first full name with a higher similarity ranking is used as an input parameter of the first target external function, and the first target external function is executed in the code file.

9. The method according to claim 1, wherein: The several defect location algorithms include at least one of the following: a defect location algorithm based on information retrieval, and a defect location algorithm based on spectrum.

10. The method according to claim 1, wherein: The second interaction includes: Inputting a second prompt word into the second large language model to set it as a second agent; the second prompt word instructs the second large language model to use an external function in a second external function list to locate the defect position according to the defect information and the candidate method sequence, wherein the external function is used to search for content of a specific part in the code file and return a search result of a specific code element; Conducting several rounds of dialogue with the second agent, each round of dialogue generating an execution result of the external function; The second agent is instructed to determine several target candidate methods according to the defect information, the candidate method sequence and the context content in each round of dialogue.

11. The method according to claim 10, wherein: Any round of dialogue among the multiple rounds of dialogues includes: Instruct the second agent to give the external function used in this round according to the context of the dialogue; Receiving a second target external function given by a second agent; Execute the second target external function in the code file and input the function execution result to the second agent.

12. The method according to claim 10, wherein: The second external function list includes: a fourth external function for obtaining a code snippet therein according to a method name.

13. The method according to claim 12, wherein: The second external function list also includes: an exit function that enables the second agent to actively exit the multi-round dialogue in advance.

14. The method according to claim 11, wherein the input parameter of the second target external function is a second code element name; Executing the second target external function in the code file includes: Get the full name of each code element in the code file; The second code element name is matched with the full name of each code element in terms of similarity, the second full name with a higher similarity ranking is used as an input parameter of the second target external function, and the second target external function is executed.

15. The method according to any one of claims 3, 5, 7, 8, 10, and 14, wherein: The code elements include: code files, classes, methods, and code snippets.

16. The method according to any one of claims 7, 8 and 14, wherein: The similarity is determined based on the edit distance.

17. A code defect location device, comprising: An acquisition unit configured to acquire defect information related to a code defect; A first interaction unit is configured to perform a first interaction with a first large language model based on the defect information, so that the first large language model determines a plurality of first candidate methods causing the code defect according to the defect information; A defect location algorithm calling unit is configured to input the defect information into a plurality of defect location algorithms to obtain a plurality of output second candidate methods; a candidate sequence determining unit, configured to form a candidate method sequence based on the plurality of first candidate methods and the plurality of second candidate methods; The candidate method determination unit is configured to perform a second interaction with a second large language model based on the defect information and the candidate method sequence, so that the second large language model determines several target candidate methods that cause the code defect according to the defect information and the candidate method sequence.

18. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 16.

19. A computing device comprising a memory and a processor, wherein: The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 16 is implemented.

Citation Information

Cited By

  • Business strategy determination method and device based on intelligent agent and intelligent agent

    CN122450632A