A method and apparatus for generating a sequence of operations for a code task

By calculating the entropy value of operation sequence nodes and optimizing the pruning agent, the search strategy is dynamically adjusted to solve the problem of low efficiency in operation sequence generation in autonomous software engineering. This achieves efficient and high-quality operation sequence generation, improving the success rate of code tasks.

CN122111602APending Publication Date: 2026-05-29ALIPAY (HANGZHOU) INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
Filing Date
2026-02-06
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In existing autonomous software engineering, the efficiency of code task generation operation sequences is low, especially in the decision-making mechanism where the allocation of computing resources is unreasonable, resulting in excessive computing overhead and token consumption, which cannot effectively cover the solution space and affect the generation quality.

Method used

By calculating the entropy value of the last node in the operation sequence, the search strategy is dynamically adjusted. Low entropy values ​​save computational resources, while high entropy values ​​increase the search intensity. Combined with the pruning agent to optimize the operation sequence, high-quality operation sequences are generated while controlling computational overhead.

Benefits of technology

This approach achieves improved quality and efficiency in operation sequence generation while controlling computational overhead, avoiding misallocation of computational resources, ensuring critical path coverage, and increasing the success rate of code tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122111602A_ABST
    Figure CN122111602A_ABST
Patent Text Reader

Abstract

The embodiment of the specification provides a method for generating an operation sequence for a code task, comprising: obtaining, for a first node at the end of a generated first operation sequence, a first operation corresponding to the first node and an operation result of the first operation. Through a code agent, based on the operation result, a probability of each candidate operation in a plurality of preset candidate operations is obtained. Based on the probability of each candidate operation, an entropy value of the first node is calculated, and the entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node from the plurality of candidate operations. If the entropy value is not higher than a preset first threshold, through the code agent, a first number of child nodes of the first node is determined based on the probability distribution of the plurality of candidate operations. If the entropy value is higher than the first threshold, through the code agent, a second number of target child nodes of the first node is determined based on the probability distribution of the plurality of candidate operations, and the second number is greater than the first number.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of computer technology, and more particularly to a method and apparatus for generating operation sequences for code tasks. Background Technology

[0002] With breakthroughs in artificial intelligence technologies such as Large Language Models (LLM), the boundaries of automation in software engineering are constantly expanding, giving rise to the emerging field of Autonomous Software Engineering (ASE). ASE aims to build intelligent agent systems capable of understanding complex requirements, manipulating large-scale codebases, and autonomously executing software lifecycle tasks, such as automatically fixing code defects in repositories, implementing software functions, or performing code refactoring. In this cutting-edge engineering field, the tasks faced by intelligent agents are typically characterized by long cycles, multiple steps, and strong dependencies, far exceeding the scope of traditional code snippet generation.

[0003] To address these complex coding tasks, the industry widely adopts the Test-Time Scaling (TTS) paradigm as a core solution. The core idea of ​​this paradigm is to improve the success rate by scaling computational resources during task execution (testing or inference phases). Specifically, the code agent does not generate the final answer all at once, but rather through multiple iterations, it generates a sequence of operations (such as code analysis, tool calls, and patch generation) to explore an engineering practice trajectory capable of solving the coding task. Typically, the agent maintains multiple candidate trajectories in parallel and, at each decision step, selects from these candidate operations based on the current state, gradually building a search tree. Finally, the outputs of each trajectory are verified by running tests, and the optimal result is selected.

[0004] However, in existing TTS-based ASE practices, the inefficiency of generating operation sequences for code tasks has always plagued engineers, especially in the decision-making mechanism for generating operation sequences.

[0005] Specifically, to improve the pass rate of code tasks, related technologies often rely on simply and consistently increasing the number of parallel exploration trajectories (such as increasing the search width). This brute-force expansion strategy leads to a proportional or even exponential increase in computational overhead and token consumption, severely damaging the practicality and economy of the solution. The root cause is that the agent lacks awareness of the decision state during trajectory exploration. Regardless of whether the current decision point is simple and clear or complex and ambiguous, the agent uses the same computational resource allocation strategy for exploration, resulting in severe computational resource misallocation. In other words, computational resources are over-consumed at simple decision points, while insufficient computational resources prevent adequate exploration at truly critical decision points with high uncertainty, thus failing to effectively cover the solution space.

[0006] Therefore, the field of autonomous software engineering urgently needs a more intelligent and refined method for generating and deciding on operation sequences. Through technological means, the uncertainty level of each decision point can be evaluated in real time during the reasoning process of the operation sequence. Based on this evaluation, the search strategy and allocation of computing resources can be dynamically and adaptively adjusted, striking a balance between deeply exploring explicit operations and broadly exploring potential operations. This improves computational efficiency, efficiently generates operation sequences for code tasks, enhances the quality of output results, and yields reliable code patches. Summary of the Invention

[0007] One or more embodiments of this specification describe a method and apparatus for generating operation sequences for code tasks, which can achieve the above-mentioned technical effects.

[0008] According to the first aspect, a method for generating operation sequences for code tasks is provided, including:

[0009] For the first node at the end of the generated first operation sequence, obtain the first operation corresponding to the first node and the operation result of the first operation.

[0010] Based on the operation results, the probability of each candidate operation among a set of preset candidate operations is obtained through a code-based intelligent agent.

[0011] Based on the probability of each candidate operation, the entropy value of the first node is calculated. The entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node among the multiple candidate operations.

[0012] If the entropy value is not higher than a preset first threshold, the code agent determines a first number of child nodes of the first node based on the probability distribution of the multiple candidate operations.

[0013] If the entropy value is higher than the first threshold, the code agent determines a second number of target child nodes for the first node based on the probability distribution of the multiple candidate operations, wherein the second number is greater than the first number.

[0014] According to the second aspect, this specification provides an apparatus for generating operation sequences for code tasks, comprising:

[0015] The acquisition module is configured to, for the first node at the end of the generated first operation sequence, acquire the first operation corresponding to the first node and the operation result of the first operation.

[0016] The module is configured to, through a code-based intelligent agent, obtain the probability of each candidate operation among a preset number of candidate operations based on the operation result.

[0017] The calculation module is configured to calculate the entropy value of the first node based on the probability of each candidate operation. The entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node among the multiple candidate operations.

[0018] The first determining module is configured to, if the entropy value is not higher than a preset first threshold, determine a first number of child nodes of the first node through the code agent based on the probability distribution of the multiple candidate operations.

[0019] The second determining module is configured to, if the entropy value is higher than the first threshold, determine a second number of target child nodes of the first node through the code agent based on the probability distribution of the multiple candidate operations, wherein the second number is greater than the first number.

[0020] According to a third aspect, a computing device is provided, including a memory and a processor, characterized in that the memory stores executable code, and when the processor executes the executable code, it implements the method described in the first aspect.

[0021] In summary, the methods and apparatus provided in the embodiments of this specification propose a method for generating operation sequences for code tasks. This method effectively utilizes the strong correlation between entropy and the decision uncertainty of the code agent, using the entropy of the inference node as the basis for dynamically adjusting the search strategy: low entropy indicates a concentrated probability of candidate operations, allowing the code agent to make definite decisions and ensuring the quality of operation sequence generation without excessive exploration; high entropy indicates a dispersed probability of candidate operations, leading to ambiguous decisions, requiring the code agent to increase search intensity to enhance the diversity of operation sequences and avoid missing key effective paths. This allows the code agent to achieve a balance between exploration and utilization: utilizing known and reliable operations in low-entropy steps to save computational resources, and exploring more potential operations in high-entropy steps to comprehensively cover the solution space of the operation sequence, thereby improving the quality of operation sequence generation while controlling computational overhead. Attached Figure Description

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

[0023] Figure 1 This is a schematic diagram of the entropy distribution of the tools disclosed in this specification;

[0024] Figure 2 This is an implementation framework for a method for generating operation sequences for code tasks, provided according to embodiments of this specification.

[0025] Figure 3 This is a flowchart illustrating a method for generating an operation sequence for a code task, according to an embodiment of this specification.

[0026] Figure 4A This is an exemplary flowchart of a verification candidate patch provided according to an embodiment of this specification;

[0027] Figure 4B This is an exemplary flowchart of determining a target patch according to embodiments of this specification;

[0028] Figure 5 This is a schematic diagram of an apparatus for generating operation sequences for code tasks, according to an embodiment of this specification. Detailed Implementation

[0029] The solutions provided in the embodiments of this specification will now be described with reference to the accompanying drawings.

[0030] As mentioned earlier, autonomous software engineering aims to build intelligent agents capable of understanding complex natural language instructions and autonomously manipulating code repositories to complete software tasks. As an emerging engineering technology that deeply integrates artificial intelligence and software engineering, relying on the powerful reasoning and generation capabilities of large language models, it can now support intelligent agents in autonomously completing complex and long-cycle code tasks such as code repair, function implementation, and code refactoring, significantly improving software development efficiency and quality. In the practice of autonomous software engineering, the quality of the generated operation sequences directly determines the final completion effect of the code task, while computational efficiency relates to the practicality and economy of autonomous software engineering implementation. Therefore, how to generate high-quality, diverse operation sequences while controlling computational overhead (including token consumption and time costs), and simultaneously achieve a dynamic balance between exploring new potentially effective operations and utilizing known reliable operations, has become a core problem that urgently needs to be solved in the field of autonomous software engineering.

[0031] To address this issue in autonomous software engineering, the mainstream technical paradigm in the industry is Test-Time Extended Test-Solution (TTS). This involves not increasing model parameters during training, but rather, during task execution (i.e., inference), allowing the agent executing the code task (hereinafter referred to as the code agent) to explore multiple different task execution paths (i.e., operation sequences or trajectories) to generate diverse candidate results, aiming to increase the success probability by expanding the search scope. In this process, the code agent typically needs to repeatedly select and invoke from a set of various tools or operations (e.g., file reading, file creation, code search, code analysis, code editing, test execution, tool invocation, patch generation) to dynamically construct the operation sequence for the code task.

[0032] The inventors discovered through research that, in practical applications of related technologies during testing, a fixed-scale search and sampling strategy is typically employed. This involves uniformly expanding a fixed number of child nodes at each decision point (i.e., deciding to generate the next operation in the current inference state) to explore diverse operation sequences. This uniform operation sequence expansion strategy suffers from at least two drawbacks:

[0033] First, the existing technologies ignore the differences in uncertainty at different decision points. Specifically, during the operation sequence reasoning process of a code agent, most simple decision points correspond to routine operations with low uncertainty (such as file reading), while a few key decision points (such as choosing between similar code analysis tools) have high uncertainty. The existing technologies fail to distinguish between these two scenarios, leading to a misallocation of computational resources: excessive consumption of computational resources at simple decision points, while insufficient exploration at key decision points with high uncertainty. This not only increases unnecessary token consumption and time overhead but may also introduce low-quality operation sequences, affecting overall search efficiency and making it difficult for the code agent to generate high-quality operation sequences for code tasks.

[0034] Secondly, the extensive expansion paradigm implemented by related technologies is prone to computational redundancy. When the uncertainty of the code agent at a certain decision point is high (i.e., the probability distribution of candidate operations is uniform with no obvious dominant term), generating a fixed number of child nodes will lead to insufficient diversity of operation sequences, making it impossible to fully explore potential effective operations, thus missing the key operation sequences that can successfully complete the code task and reducing the success rate of the final task.

[0035] In view of this, after quantitatively analyzing the operation sequence generation process of the code agent, the inventors proposed the following technical discovery: the uncertainty of the operation decision can be quantified by the information entropy (hereinafter referred to as tool entropy) of the code agent in making each operation decision, and in practice, the distribution of tool entropy shows obvious right skewed distribution characteristics.

[0036] The inventors further clarified the definition of the aforementioned instrumental entropy, taking the t-th step of reasoning as an example, the instrumental entropy... As shown below:

[0037]

[0038] in, This refers to a set of multiple preset candidate operations. As mentioned above, the candidate operations can be any of the following: file reading, file creation, file editing, code searching, code analysis, tool invocation, patch generation, etc. This indicates that the code-based intelligent agent is based on the current execution state / operation result. , in set The strategy for making operational decisions, that is, in Select operation The probability of.

[0039] After conducting extensive experiments, the inventors discovered that during the generation of operational sequence reasoning by the code agent, the distribution of tool entropy (hereinafter referred to as entropy value) is not uniform, but rather highly right-skewed, such as... Figure 1 As shown. That is, during the reasoning process of a code agent generating operation sequences for a code task, the entropy values ​​of most reasoning steps are concentrated in a low region, corresponding to routine operations with clear and nearly deterministic objectives (e.g., file reading and writing); only a few reasoning steps have entropy values ​​falling into the high-tail region, corresponding to semantically complex key decision points that have a high impact on the overall operation sequence (e.g., choosing among multiple functionally similar code analysis tools). Based on Figure 1 As shown in the distribution, it can be seen that it is extremely inefficient and unnecessary to allocate computational resources uniformly and indiscriminately to each inference step in generating the operation sequence for the code agent.

[0040] Based on the above-mentioned technical findings, the inventors propose a method for generating operation sequences for code tasks in this specification. Figure 2 A schematic implementation architecture of this method is shown. See also... Figure 2 Once a code agent initiates a code task, it can generate an operation sequence by executing multiple rounds of operations (corresponding to the circular nodes shown in the attached diagram). Figure 2 The first operation sequence is shown below as an example; the remaining operation sequences are represented by ellipses and will not be discussed further. Code tasks typically refer to tasks related to code generation, such as code repair and feature implementation. Code agents are usually built based on large language models and are responsible for understanding the natural language description of the code task and performing reasoning and generating operation sequences.

[0041] Continue reading Figure 2 During the generation of operation sequences by the code agent, taking a certain inference step as an example, the probability of each candidate operation among a preset number of candidate operations can be obtained based on the operation corresponding to the first node at the end of the first operation sequence and the operation result. The concept of the multiple candidate operations has been introduced above and will not be repeated here. Based on the definition of tool entropy shown above, the tool entropy (i.e., entropy value) of the first node can be calculated based on the probabilities of each candidate operation. It can be understood that this entropy value quantifies the state at the first node. Below, the code intelligence platform in the multiple candidate operations The uncertainty of performing operations to select (i.e. determine child nodes).

[0042] In practice, the entropy value of the first node can be calculated. With the preset first threshold Compare. If This indicates that the code-based intelligent agent's decision-making on the first node has high uncertainty, allowing for the allocation of more computing resources to the expansion of the first node, generating a larger number of child nodes (compared to nodes with low entropy). If... This indicates that the uncertainty of the code agent's decision-making on the first node is low. In this case, less computing resources can be used to generate a smaller number (compared to nodes with high entropy) or even a single child node for the first node. This allows the code agent to save computing resources (e.g., reduce the number of inferences or token consumption), quickly complete the expansion of child nodes for nodes with higher determinism, and concentrate valuable computing resources on the inference and generation of child nodes for nodes with lower determinism.

[0043] Therefore, it can be seen that the method disclosed in the embodiments of this specification can effectively utilize the strong correlation between entropy and the decision uncertainty of the code agent, using the entropy of the inference node as the basis for dynamically adjusting the search strategy: a low entropy value means that the probability of candidate operations is concentrated, and the code agent can make a clear decision without excessive exploration to ensure the generation quality of the operation sequence; a high entropy value indicates that the probability of candidate operations is dispersed, and the decision is ambiguous, requiring the code agent to increase the search intensity to improve the diversity of the operation sequence and avoid missing key effective paths. This allows the code agent to achieve a balance between exploration and utilization, that is, to utilize known and reliable operations in low-entropy steps to save computational resources, and to explore more potential operations in high-entropy steps to fully cover the solution space of the operation sequence, thereby improving the generation quality of the operation sequence while controlling computational overhead.

[0044] Following the above technical concept, in Figure 3 The diagram illustrates a method flowchart for generating an operation sequence for a code task according to embodiments of this specification. It is understood that the method disclosed in the embodiments of this specification can be executed by any device, apparatus, platform, or cluster of devices with computing and processing capabilities.

[0045] See Figure 3In one embodiment, the method includes at least the following steps: S301, for the first node at the end of the generated first operation sequence, obtaining the first operation corresponding to the first node and the operation result of the first operation; S303, using a code agent, obtaining the probability of each candidate operation among a preset plurality of candidate operations based on the operation result; S305, calculating the entropy value of the first node based on the probability of each candidate operation, the entropy value representing the uncertainty of the code agent in determining the child nodes of the first node among the plurality of candidate operations; S307, if the entropy value is not higher than a preset first threshold, using the code agent, determining a first number of child nodes of the first node based on the probability distribution of the plurality of candidate operations; S309, if the entropy value is higher than the first threshold, using the code agent, determining a second number of target child nodes of the first node based on the probability distribution of the plurality of candidate operations, the second number being greater than the first number.

[0046] As mentioned earlier, the code tasks that intelligent code agents can perform can cover complex scenarios in the field of Autonomous Software Engineering (ASE) that require multi-step collaboration, and are not limited to generating single code snippets. In conventional engineering practice, these code tasks typically include, but are not limited to: code defect repair (e.g., fixing logical errors, syntax anomalies, boundary condition vulnerabilities, etc. marked in the code repository), software function implementation (e.g., developing new modules based on natural language requirements, adding interfaces, or extending existing software functions), and codebase refactoring (e.g., unifying coding style, optimizing redundant logic, migrating outdated dependency libraries, etc.). Taking code defect repair as an example, it often requires the intelligent code agent to perform the following operations in sequence: locating the defective file and specific line of code, analyzing the cause of the error, generating a repair patch, and verifying the patch's repair effect. This series of operations cannot be completed through a single code generation. Therefore, the intelligent code agent needs to output an operation sequence consisting of multiple ordered steps to simulate the step-by-step thinking and execution logic of human engineers in solving complex problems.

[0047] In summary, an operation sequence refers to an ordered set of operations generated by a code agent in order to complete a code task. Each operation serves to advance the code task, and there are dependencies between operations. Ultimately, the endpoint of the operation sequence usually corresponds to the generation of a patch. For example, in a code defect fixing task, a patch can be a code snippet that modifies a code file. Applying it (committing or applying) to the code repository can fix the code defect identified by the task. Furthermore, the core reason for generating operation sequences lies in the complex nature of code tasks. If the final patch is generated directly, the code agent cannot handle multiple dimensions of operations such as code repository context understanding, problem localization, code design, and testing verification all at once. By breaking down the code task into steps (i.e., nodes in the operation sequence), the code agent can dynamically adjust its strategy based on the results of preceding operations at each step, while also preserving the intermediate decision-making process and providing traceable reasoning.

[0048] Returning to the main process, the following section will combine the implementation architecture and diagrams described above to... Figure 3 The specific steps of each method are explained in detail.

[0049] First, in step S301, for the first node at the end of the generated first operation sequence, obtain the first operation corresponding to the first node and the operation result of the first operation.

[0050] During the autonomous execution of code tasks by a code-based intelligent agent, one or more operation sequences (or trajectories) can be constructed by progressively invoking various tools. The first operation sequence can be the one that the code-based intelligent agent is currently expanding or evaluating. The first node, which is the last node of the first operation sequence, is the latest state point of the first operation sequence and a decision point in the current inference process. Its corresponding first operation is the specific action to be performed at that node. Therefore, the operation result can encompass the execution status, output data, and environmental feedback of the first operation. For example, if the first operation is executed successfully, the operation result can include a success flag and the result data generated by executing the first operation; if the first operation fails, the operation result can include a failure flag and the error message generated by executing the first operation.

[0051] Next, in step S303, the probability of each candidate operation among a preset plurality of candidate operations can be obtained by the code agent based on the operation result.

[0052] In practice, the multiple candidate operations are not randomly generated, but rather a set of operations that can be pre-set based on the needs of the code task and the capabilities of various tools. In an optional implementation, the candidate operations can be one of the following:

[0053] read_file: Reads the contents of a file within a selected range of lines as needed.

[0054] write_file: Creates or overwrites an existing file.

[0055] edit_file: Edit the contents of a file.

[0056] grep: A fast file content search based on ripgrep.

[0057] glob: File search.

[0058] bash: Executes shell commands.

[0059] The code agent can evaluate a sequence of first operations based on the first operation and its result, calculating the probability of each candidate operation among multiple candidate operations in the current state. The code agent can perform probability calculations based on a semantic understanding of the operation results. For example, if the operation result indicates a syntax error in the code, the probability of calling a syntax checking tool is likely higher, while the probability of executing a test case is lower. In other words, the probability distribution of the candidate operations among the multiple candidate operations can reflect the code agent's tendency and confidence in subsequent actions in the current state.

[0060] Next, in step S305, based on the probability of each candidate operation, the entropy value of the first node is calculated. The entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node among the multiple candidate operations.

[0061] The entropy value can be the information entropy calculated based on the probability distribution of the multiple candidate operations, i.e., referring to the tool entropy given above. The formula for calculation is omitted here. The entropy value reflects the uncertainty of the code agent's decision-making. When the probability distribution of candidate operations is relatively uniform, the probabilities of multiple candidate operations are similar, resulting in a higher entropy value, indicating that the code agent's decision-making is ambiguous; when the probability is concentrated on a few candidate operations, the entropy value is lower, indicating that the code agent's decision-making is clear.

[0062] Therefore, based on the entropy value, the strategy for the code agent to generate child nodes for the first node can be dynamically adjusted. The entropy value is then compared with a predefined threshold (…). The first threshold (hereinafter referred to as the first threshold) is compared with the second threshold. The first threshold is the boundary between low uncertainty and high uncertainty, and its value can be determined based on the statistical data of historical code tasks, expert experience or analysis.

[0063] In step S307, if the entropy value is not higher than a preset first threshold, the code agent can determine a first number of child nodes of the first node based on the probability distribution of the multiple candidate operations.

[0064] When the entropy value is not higher than the first threshold, it indicates that the uncertainty of the code agent generating child nodes for the first node is low. The code agent can determine the first number (e.g., 1 or 2) of candidate operations with the highest probability ranking as child nodes of the first node based on the probability distribution. In this way, child nodes can be quickly determined and the operation sequence expanded with lower computational overhead.

[0065] In step S309, if the entropy value is higher than the first threshold, the code agent can determine a second number of target child nodes of the first node based on the probability distribution of the multiple candidate operations, wherein the second number is greater than the first number.

[0066] When the entropy value exceeds a first threshold, it indicates a high degree of uncertainty in the code agent's generation of child nodes for the first node. The code agent faces multiple potentially feasible choices. In this case, determining a limited number of candidate operations as child nodes easily excludes effective operations, losing the opportunity to generate high-quality operation sequences. To avoid local optima and explore a broader solution space, the code agent can determine a second number of candidate operations as child nodes of the first node based on the probability distribution of the multiple candidate operations. Generally, the second number is greater than the first number, meaning the code agent will allocate more computational resources to explore multiple different candidate operations simultaneously, increasing the likelihood of discovering potentially high-quality operation sequences.

[0067] In a practical application, after the code agent generates child nodes for the first node, in order to effectively manage the search space, control computational overhead, and focus on generating high-quality operation sequences, it can filter the currently generated operation sequences. This involves retaining sequences with a high probability of completing the code task and discarding low-quality sequences or those deviating from the task. This ensures that the code agent can consistently explore along high-potential directions with limited computational resources, avoiding unlimited expansion of the solution space.

[0068] Specifically, firstly, several generated operation sequences are obtained, including a first operation sequence and a target child node. As the code agent continuously explores the code task, several more operation sequences will be generated, each representing a possible solution to the code task. Then, a pruning agent filters effective operation sequences based on their respective sequence scores. The sequence score can be a comprehensive evaluation index used to quantify the degree of correlation between each operation in an operation sequence from its starting node to its current node and the code task. It can be understood that a higher sequence score indicates a higher degree of correctness in the exploration direction of the operation sequence, meaning that each step is closer to the requirements of the code task, and vice versa.

[0069] The pruning agent can filter valid operation sequences based on their respective sequence scores. In a specific application, the operation sequences can be sorted according to their sequence scores, retaining the top M sequences as valid operation sequences, and deleting the remaining sequences (deletion can also be called pruning). M is a preset search width, which can be dynamically adjusted based on the complexity of the code task, available computing resources, etc. A higher M value means retaining a more diverse range of operation sequences, which is beneficial for covering a wider solution space in high-uncertainty scenarios and avoiding the loss of potentially high-quality operation sequences due to premature convergence; while a lower M value means that computing resources can be concentrated on a few operation sequences for further expansion, which can achieve faster convergence speed in scenarios with limited computing resources.

[0070] By introducing a pruning agent, global pruning can be performed based on the aforementioned dynamic generation of a first / second number of child nodes according to entropy values. This allows the code agent to both conduct thorough exploratory expansion on high-entropy nodes and comprehensively evaluate operation sequences, eliminating low-quality operation sequences, thereby controlling the size of the solution space and achieving intelligent allocation of computing resources during code task execution.

[0071] The following section will describe a sequence score calculation method in one embodiment.

[0072] For any sequence of operations (referred to as the second sequence of operations here to distinguish it from the first sequence of operations mentioned earlier), calculate the operation score of any second operation contained within it. Specifically, the code agent can determine the second operation... Confidence level As the first sub-fraction This indicates the state (i.e., the result) of the second operation sequence on the second operation, and the pruning agent... Based on the scoring rules, for subsequences Calculated mass fraction As a second fraction, the subsequence is the second operation sequence up to the second operation. sequence segment The weighted sum of the first and second subfractions yields the operation score for the second operation. It can be represented as:

[0073]

[0074] in, It is the weighting coefficient.

[0075] After determining the operation scores of each operation in the second operation sequence, these operation scores can be summed to obtain the total operation score of the second operation sequence. The sequence fraction determined as the second operation sequence. It can be represented as:

[0076]

[0077] in, This represents the current inference step number of the second operation sequence.

[0078] The aforementioned pruning agent This can be achieved based on pre-trained large language models, providing reliable and traceable quality scores. For example, contrastive learning can be used to train large language models to learn code semantics and structural features, enabling quality assessment of code or operations based on scoring rules.

[0079] In practice, the input to a pruning agent typically includes: a code task and operations to be evaluated. The subsequence corresponding to the operation to be scored The scoring rule is Rubric. Therefore, the input to the pruning agent... It can be defined as:

[0080]

[0081] It can be seen that in the second operation sequence there is In a scenario with one node, .

[0082] The second operation sequence The quality score corresponding to the operation during each step can be represented as:

[0083]

[0084] In a specific practice, the Rubric scoring rule can be used to instruct pruning agents to perform multi-dimensional quality assessments of operations in an operation sequence, and may include one or more of the following:

[0085] Operational consistency: Evaluate whether the operations in the operation sequence are logically coherent, consistent, and free of redundancy.

[0086] Context coverage: Evaluates whether the code agent effectively utilizes and dynamically updates the inference context to avoid duplication or conflict.

[0087] Task relevance: Determine whether the code agent correctly identifies and prioritizes key subtasks based on the code task, preventing misallocation of computing resources.

[0088] Tool Invocation Correctness: Analyze whether the code agent selected, invoked, and ordered the correct tools, used appropriate parameters to minimize redundancy, and employed suitable error handling and verification methods. Special emphasis should be placed on evaluating whether the code agent handled boundary cases and performed code optimizations within the codebase.

[0089] Attribution accuracy: Evaluates whether the code agent accurately identifies the root cause of code problems (if any) in the code task and provides targeted explanations or solutions for the causes, without overgeneralizing or misjudging the code problems.

[0090] By implementing the above steps, the pruning agent can obtain the total operation score of the second operation sequence based on the evaluation rules. It is understandable that the total operation score is obtained by summing the operation scores of each operation in the operation sequence. If the total operation score is directly used as the main criterion for selecting effective sequences, it may introduce an implicit and undesirable optimization bias, that is, the pruning agent will tend to encourage the code agent to generate longer operation sequences.

[0091] Therefore, in order to solve the above problems, in a specific practice, the total score of the operations obtained through the above steps can be used as a basis for calculation. Multiplying the result by a penalty coefficient, which is inversely proportional to the number of operations in the second operation sequence, yields the sequence score of the second operation sequence. , shown as:

[0092]

[0093] in, The penalty coefficient is... The more operations a sequence of operations contains, the smaller its penalty coefficient; conversely, the shorter the sequence, the larger the penalty coefficient. By multiplying the total operation score by the penalty coefficient, the total operation score of lengthy sequences can be effectively reduced, while the sequence score of refined sequences can be relatively increased. This encourages the code agent to explore and generate concise and efficient operation sequences.

[0094] The above describes a method for generating operation sequences for code tasks based on one or more embodiments. It should be noted that as the code agent continues to reason, the above steps S301-S309 can be executed multiple times. During the generation of operation sequences, the child node generation strategy is continuously adjusted based on the entropy value, thereby improving the generation quality of operation sequences while controlling computational overhead.

[0095] Furthermore, although the aforementioned entropy-based dynamic node generation strategy effectively optimizes computational resource allocation and improves the quality of operation sequence generation during the process, the inventors also recognized that simply optimizing the operation sequence generation process is insufficient to ensure that the final output code patch can reliably solve the code task. In some related technologies, the quality evaluation of operation sequences is often black-box and performed ex-post, heavily relying on completed inference and single-dimensional test results to judge the entire operation sequence, ignoring the large amount of valuable intermediate operation results and debugging information generated during the inference process. This approach of evaluating quality only at the end of the operation sequence may lead to the selection of an engineering solution or patch that, while passing the test, is actually inefficient and cannot fundamentally solve the code task, resulting in insufficient generalization ability and robustness.

[0096] Therefore, in order to comprehensively verify the quality of the patches generated by the operation sequence, in a specific embodiment, after the code agent generates several operation sequences for the code task, it can integrate the various test cases involved in the operation sequence generation process, combine the code library context to generate a test file that can cover multi-dimensional test scenarios, and verify the patches generated for each operation sequence based on the test file, so as to select a high-quality and reliable solution that can solve the core requirements of the code task. Figure 4A An exemplary flowchart corresponding to this implementation is shown.

[0097] See Figure 4A Specifically, it is possible to obtain several generated operation sequences (corresponding to the set of operation sequences in the attached diagram). ), and the candidate patches corresponding to the second node at the end of each of the plurality of operation sequences (corresponding to the candidate patch set in the attached figure). The aforementioned sequence of operations can be generated by the code agent based on the methods described above. Each sequence represents a complete inference chain completed by the code agent, from code task analysis and tool invocation to patch generation. The second node can refer to the final node of each sequence, representing the final state after all operations have been performed. At the second node, the code agent typically generates a specific code change suggestion, i.e., a candidate patch. These candidate patches are solutions that the code agent generates after multiple rounds of exploration, and they may have differences in quality, correctness, or robustness.

[0098] Therefore, the next step is to verify the agent based on the test file (corresponding to the test file in the attached figure). From a pool of candidate patches, select the valid patches (corresponding to those in the attached diagram). The pass rate of the effective patch on the test file is higher than the preset second threshold (corresponding to the pass rate threshold in the attached figure). The verification agent can be a module specifically designed to perform tests and evaluate patch quality, typically built upon a rule engine or large language model. The test file can include multiple test cases to cover multi-dimensional testing and verification scenarios, comprehensively examining the quality of the patch.

[0099] The verification agent can apply each candidate patch to the original code repository (corresponding to the code repository in the attached figure) corresponding to the code task. The test file is then run, the test results for each patch are statistically analyzed, and the pass rate is calculated. For example, this could be the ratio of successfully passed test cases to the total number of test cases. When the pass rate of a candidate patch exceeds a preset second threshold, the candidate patch is determined to be a valid patch.

[0100] By following the steps above, high-quality patches that can effectively solve the code task can be selected from several candidate patches obtained through code inference. It's easy to understand that the quality and test coverage of the test files, serving as the screening benchmark, determine the quality of the selected effective patches.

[0101] According to one implementation, the test file can be generated in the following way.

[0102] First, extract several test operations contained in the several operation sequences, the test operations including executing test cases.

[0103] During the process of a code agent exploring and generating operation sequences, in order to debug or verify the generated partial trajectories, the code agent may actively invoke tools to generate or execute test cases during the inference and generation of operation sequences. For example, it might use pytest to run test cases and generate new unit tests to verify a function. These operations, known as test operations, are scattered throughout the various operation sequences. By extracting the test operations from the generated operation sequences, multi-dimensional potential test scenarios and their corresponding test cases can be summarized. The set of extracted test operations corresponds to the set of test operations shown in the attached figure. .

[0104] Then, by testing the integrated agent, test files are generated based on the test semantics of the various test operations.

[0105] The test integration agent can parse the aforementioned test operations, understand their test intent (e.g., verifying functional correctness, detecting boundary conditions, etc.), remove redundant or conflicting test operations, and finally integrate them into a unified test file, which is convenient for downstream verification agents to execute.

[0106] According to one implementation, a test integration agent can perform semantic analysis on the several test operations based on the code library corresponding to the code task, and generate a test file containing several test cases.

[0107] Test integration agents are typically built upon large language models, capable of analyzing and understanding the context of the codebase (e.g., code structure, dependencies, and data flow) and combining this with the semantics of various test operations (e.g., test objectives, expected inputs and outputs) to generate test cases covering code tasks from multiple test dimensions. This ensures that the test file can comprehensively evaluate the correctness of candidate patches. In one example, the test cases can be any of the following: boundary tests (to verify the behavior of code under specific input data), regression tests (to ensure that the modifications introduced by the candidate patch do not cause new code errors), and functional tests (to verify whether the code applying the candidate patch meets functional requirements). The combination of these test cases allows the test file to examine the quality of candidate patches from multiple dimensions, reducing the risk of missed detections.

[0108] Furthermore, in a specific application scenario of the above-described implementation, if the number of effective patches is greater than one, the agent can be evaluated using multiple patches, and a first effective patch (corresponding to the one in the attached figure) can be selected from the effective patches. ), Figure 4B An exemplary flowchart for determining the target patch corresponding to this application scenario is shown.

[0109] See appendix Figure 4B The patch evaluates the agent. This can be an independent evaluation model implemented based on different large models or different evaluation preferences. Each patch evaluation agent can score the effective patches based on different evaluation criteria (e.g., code coding standardization, code execution efficiency, code maintainability, etc.), and select a first effective patch based on the score. This avoids evaluation bias caused by a single evaluation perspective and improves the comprehensiveness of the evaluation through diverse evaluation methods. The process of multiple patch evaluation agents evaluating and selecting effective patches can be parallel, with each agent making independent decisions without interference. The set of first effective patches selected by each of the multiple patch evaluation agents corresponds to the one shown in the attached figure. .

[0110] See attached document Figure 4B The figure shown The patch selected most frequently by the multiple patch evaluation agents is then identified as the target patch for the code task. In other words, by analyzing the selection results of each patch evaluation agent, the patch selected most frequently is determined as the target patch for the code task (i.e., the one shown in the attached diagram). ).

[0111] The foregoing, based on one or more embodiments, details a method for generating operation sequences for code tasks. Using the method provided in the embodiments of this specification, the strong correlation between entropy and the decision-making uncertainty of the code agent can be effectively utilized. The entropy value of the inference node is used as the basis for dynamically adjusting the search strategy, enabling the code agent to save computational resources by utilizing known and reliable operations in low-entropy steps, and to explore more potential operations in high-entropy steps to fully cover the solution space of the operation sequence. This improves the quality of generated operation sequences while controlling computational overhead.

[0112] In this specification, the terms "first" in phrases such as "first node" and "first number," as well as the corresponding terms "second" and "third" (if any) in the text, are used merely for ease of distinction and description and do not have any limiting meaning.

[0113] The foregoing description describes specific embodiments of this specification; other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than those shown in the embodiments, and the desired result may still be achieved. Furthermore, the processes depicted in the drawings do not necessarily need to follow the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0114] Figure 5 This is a schematic diagram of an apparatus for generating operation sequences for code tasks, according to an embodiment of this specification. The apparatus 500 is deployed in a computing device, which can be implemented using any device, equipment, platform, device cluster, etc., with computing and processing capabilities. This apparatus embodiment is similar to... Figure 3 Corresponding to the method embodiment shown, the apparatus 500 includes:

[0115] The acquisition module 501 is configured to acquire the first operation corresponding to the first node at the end of the generated first operation sequence, and the operation result of the first operation.

[0116] The module 502 is configured to obtain the probability of each candidate operation among a preset number of candidate operations based on the operation result through a code-based intelligent agent.

[0117] The calculation module 503 is configured to calculate the entropy value of the first node based on the probability of each candidate operation. The entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node among the multiple candidate operations.

[0118] The first determining module 504 is configured to, if the entropy value is not higher than a preset first threshold, determine a first number of child nodes of the first node through the code agent based on the probability distribution of the multiple candidate operations.

[0119] The second determining module 505 is configured to, if the entropy value is higher than the first threshold, determine a second number of target child nodes of the first node through the code agent based on the probability distribution of the multiple candidate operations, wherein the second number is greater than the first number.

[0120] According to another embodiment, this specification also provides a computing device, including a memory and a processor, characterized in that the memory stores executable code, and when the processor executes the executable code, it implements the foregoing combination. Figure 3 The steps of the method are described.

[0121] Those skilled in the art will recognize that the functions described in the embodiments of the present invention in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.

[0122] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the embodiments of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made based on the technical solutions of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for generating an operation sequence for a code task, comprising: For the first node at the end of the generated first operation sequence, obtain the first operation corresponding to the first node and the operation result of the first operation; Based on the operation results, the probability of each candidate operation among a preset number of candidate operations is obtained through a code-based intelligent agent. Based on the probability of each candidate operation, the entropy value of the first node is calculated. The entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node among the multiple candidate operations. If the entropy value is not higher than a preset first threshold, the code agent determines a first number of child nodes of the first node based on the probability distribution of the multiple candidate operations. If the entropy value is higher than the first threshold, the code agent determines a second number of target child nodes for the first node based on the probability distribution of the multiple candidate operations, wherein the second number is greater than the first number.

2. The method according to claim 1, wherein, If the entropy value is higher than the first threshold, the method further includes: Obtain several generated operation sequences, including the first operation sequence and the target child node; The pruning agent filters valid operation sequences based on their respective sequence scores; the sequence scores represent the degree of association between each operation in the operation sequence and the code task.

3. The method according to claim 2, wherein, Based on the sequence scores corresponding to each of the aforementioned operation sequences, valid operation sequences are filtered, including: Sort the plurality of operation sequences according to the sequence scores; The top M operation sequences are retained as valid operation sequences, and the remaining operation sequences are deleted; M is the preset search width.

4. The method according to claim 2, wherein, The sequence score is obtained in the following way: Calculate the operation score of any second operation contained in any second operation sequence; the operation score is a weighted sum of a first sub-score and a second sub-score, the first sub-score is the confidence of the code agent in determining the second operation, the second sub-score is the quality score calculated by the pruning agent for the sub-sequence based on the scoring rules, and the sub-sequence is the sequence segment of the second operation sequence up to the second operation; The sequence score of the second operation sequence is determined based on the operation scores corresponding to the operations contained in the second operation sequence.

5. The method according to claim 4, wherein, The step of determining the sequence score of the second operation sequence based on the operation scores corresponding to each of the operations contained in the second operation sequence includes: The total operation score is obtained by summing the operation scores corresponding to each of the operations contained in the second operation sequence. The total score of the operation is multiplied by the penalty coefficient to obtain the sequence score of the second operation sequence; the penalty coefficient is inversely proportional to the number of operations contained in the second operation sequence.

6. The method according to claim 4, wherein, The scoring rules include one or more of the following: operational consistency, context coverage, task relevance, correctness of tool invocation, and accuracy of attribution analysis.

7. The method according to claim 1, further comprising: Obtain several generated operation sequences, and candidate patches corresponding to the second node at the end of each of the operation sequences; By verifying the intelligent agent, effective patches are selected from several candidate patches based on the test file; the pass rate of the effective patches on the test file is higher than a preset second threshold.

8. The method according to claim 7, wherein, The test file was generated in the following way: Extract several test operations contained in the several operation sequences, wherein the test operations include executing test cases; By integrating the intelligent agent through testing, test files are generated based on the test semantics of the various test operations.

9. The method according to claim 8, wherein, The process of integrating the intelligent agent through testing, and generating test files based on the test semantics of the various test operations, includes: By integrating the testing agent, based on the code library corresponding to the code task, semantic analysis is performed on the several test operations to generate a test file containing several test cases; the test cases are any one of the following: boundary testing, regression testing, and functional testing.

10. The method of claim 7, further comprising: If the number of valid patches is more than one, the agent is evaluated through multiple patches, and the first valid patch is selected from the valid patches respectively; The first valid patch selected most frequently by the multiple patch evaluation agents is determined as the target patch for the code task.

11. The method according to claim 1, wherein, The candidate operation is any one of the following: file reading, file creation, file editing, code search, code analysis, tool invocation, and patch generation.

12. The method according to claim 1, wherein, The entropy value is the information entropy calculated based on the probability distribution of the multiple candidate operations.

13. An apparatus for generating an operation sequence for a code task, comprising: The acquisition module is configured to, for the first node at the end of the generated first operation sequence, acquire the first operation corresponding to the first node and the operation result of the first operation; The module is configured to, through a code-based intelligent agent, obtain the probability of each candidate operation among a preset number of candidate operations based on the operation result; The calculation module is configured to calculate the entropy value of the first node based on the probability of each candidate operation, wherein the entropy value is used to represent the uncertainty of the code agent in determining the child node of the first node among the multiple candidate operations; The first determining module is configured to, if the entropy value is not higher than a preset first threshold, determine a first number of child nodes of the first node through the code agent based on the probability distribution of the multiple candidate operations; The second determining module is configured to, if the entropy value is higher than the first threshold, determine a second number of target child nodes of the first node through the code agent based on the probability distribution of the multiple candidate operations, wherein the second number is greater than the first number.

14. A computing device, comprising a memory and a processor, characterized in that, The memory stores executable code, and when the processor executes the executable code, it implements the method of any one of claims 1-12.