Automatic tree-structured prompt optimization

The automatic tree-structured prompt optimization mechanism addresses the limitations of existing methods by revising prompts with conditional branches, improving LLM accuracy in complex scenarios through failure case analysis and pattern-based enhancements.

WO2026007013A1PCT designated stage Publication Date: 2026-01-08MICROSOFT TECHNOLOGY LICENSING LLC +9
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/103233
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2026-01-08

AI Technical Summary

Technical Problem

Existing prompt engineering methods for large language models (LLMs) are ineffective in handling complex scenarios with uneven or highly diverse data distributions, leading to inaccurate model outputs.

Method used

An automatic tree-structured prompt optimization mechanism that utilizes failure cases to revise initial prompts into tree-structured prompts with conditional branches, enhancing adaptability to complex scenarios by determining target patterns and adding conditional branches based on prompt revising suggestions.

Benefits of technology

Facilitates LLMs to generate more accurate model outputs in diverse and complex scenarios by adapting the prompt structure to better handle underlying reasons for failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024103233_08012026_PF_FP_ABST
    Figure CN2024103233_08012026_PF_FP_ABST
Patent Text Reader

Abstract

The present disclosure provides methods, apparatuses and non-transitory computer-readable medium for prompt optimization. An initial prompt may be obtained, wherein the initial prompt comprises multiple sequential instructions. One or more failed cases associated with the initial prompt may be obtained. One or more target patterns may be determined for the one or more failed cases. One or more prompt revising suggestions may be determined for the one or more target patterns. At least one revised prompt may be generated through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.
Need to check novelty before this filing date? Find Prior Art

Description

AUTOMATIC TREE-STRUCTURED PROMPT OPTIMIZATIONBACKGROUND

[0001] In artificial intelligence (AI) field, people now well note that prompts significantly influence performance of large language models (LLMs) . Thus, prompt engineering technique that involves generating suitable prompts for enhancing the performance of LLMs becomes an important technique in AI field. Recently, automatic prompt optimization methods are extensively explored, which automatically optimize prompts, in order to facilitate LLMs generating more accurate outputs.SUMMARY

[0002] This Summary is provided to introduce a selection of concepts that are further described below in the Detailed Description. It is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.

[0003] Embodiments of the present disclosure propose methods, apparatuses and non-transitory computer-readable medium for prompt optimization. An initial prompt may be obtained, wherein the initial prompt comprises multiple sequential instructions. One or more failed cases associated with the initial prompt may be obtained. One or more target patterns may be determined for the one or more failed cases. One or more prompt revising suggestions may be determined for the one or more target patterns. At least one revised prompt may be generated through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.

[0004] It should be noted that the above one or more aspects comprise the features hereinafter fully described and particularly pointed out in the claims. The following description and the drawings set forth in detail certain illustrative features of the one or more aspects. These features are only indicative of the various ways in which the principles of various aspects may be implemented, and this disclosure is intended to include all such aspects and their equivalents.BRIEF DESCRIPTION OF THE DRAWINGS

[0005] The disclosed aspects will hereinafter be described in conjunction with the  appended drawings that are provided to illustrate and not to limit the disclosed aspects.

[0006] FIG. 1 illustrates an exemplary process for automatic tree-structured prompt optimization according to an embodiment.

[0007] FIG. 2 illustrates an exemplary process of creating a prompt template according to an embodiment.

[0008] FIG. 3 illustrates an exemplary process of generating an initial prompt on the basis of a prompt template according to an embodiment.

[0009] FIG. 4 illustrates an exemplary process of obtaining failed cases according to an embodiment.

[0010] FIG. 5 illustrates an exemplary process of performing error analyzing according to an embodiment.

[0011] FIG. 6 illustrates an exemplary process of utilizing a prompt analyzing model to perform error analyzing according to an embodiment.

[0012] FIG. 7 illustrates an exemplary process of generating revised tree-structured prompts based on target patterns and prompt revising suggestions according to an embodiment.

[0013] FIG. 8 illustrates an exemplary process of utilizing a reason summarizing model to generate target patterns according to an embodiment.

[0014] FIG. 9 illustrates an exemplary process of utilizing a prompt revising model to generate revised tree-structured prompts according to an embodiment.

[0015] FIG. 10 illustrates an exemplary process of utilizing a reason summarizing model to generate prompt revising suggestions according to an embodiment.

[0016] FIG. 11 illustrates another exemplary process of utilizing a prompt revising model to generate revised tree-structured prompts according to an embodiment.

[0017] FIG. 12 illustrates an exemplary process of generating target prompts for a next iteration according to an embodiment.

[0018] FIG. 13 illustrates an exemplary process of iteratively performing prompt optimizing according to an embodiment.

[0019] FIG. 14 illustrates a flowchart of an exemplary method for automatic tree-structured prompt optimization according to an embodiment.

[0020] FIG. 15 illustrates an exemplary apparatus for automatic tree-structured prompt optimization according to an embodiment.

[0021] FIG. 16 illustrates an exemplary apparatus for automatic tree-structured prompt optimization according to an embodiment.DETAILED DESCRIPTION

[0022] The present disclosure will now be discussed with reference to several exemplary implementations. It is to be understood that these implementations are discussed only for enabling those skilled in the art to better understand and thus implement the embodiments of the present disclosure, rather than suggesting any limitations on the scope of the present disclosure.

[0023] LLM is a type of pre-trained large-scale language model having the ability of effectively achieving general-purpose language analyzing and interpreting. A prompt is a section of natural language instruction, which, when provided to LLM, may instruct LLM to implement a specific task. A typical prompt usually includes a description for the task to be implemented by LLM, an instruction for instructing LLM to implement the task, etc. Generally, the instruction of the prompt has significantly influence on the quality of the model output. A suitably written instruction will substantially facilitate LLM to generate more accurate output. In existing prompt engineering mechanisms, the instruction is usually written as a sequence of single-flow instructions, for example, ordered steps 1, 2, 3, etc., such that LLM may sequentially follow the single-flow instructions in a step-by-step manner.

[0024] Some prompt optimizing methods have been developed, to optimize an original prompt to be provided to LLM for facilitating LLM to generate accurate model output. These existing prompt optimizing methods focus on optimizing the original prompt while maintaining the single-flow structure of the instruction, for example, through rewriting certain steps of the instruction, adding more details to certain steps of the instruction, etc. However, these existing prompt optimizing methods often exhibit limited effectiveness when faced with some complex scenarios, for example, scenarios with uneven or highly diverse data distributions, etc.

[0025] Embodiments of the present disclosure propose to provide an automatic tree-structured prompt optimization mechanism, which aims to automatically optimize an initial prompt as a tree-structured prompt with conditional branches through using failure cases associated with the initial prompt as feedback. The optimized prompt generated according to the proposed automatic tree-structured prompt optimization mechanism is adaptive to various complex scenarios. Thus, the optimized tree-structured prompt with conditional branches, when being provided to LLM, may facilitate LLM to generate a more accurate model output.

[0026] In an aspect, the proposed automatic tree-structured prompt optimization mechanism may obtain an initial prompt to be optimized and failed cases associated with the initial prompt. The initial prompt may include multiple sequential instructions in a single-flow structure, for instructing LLM to perform a specific task. In certain cases, under the instructing of the initial prompt, LLM may fail to generate an accurate model output for the specific task, for example, when the specific task involves complex scenarios, etc. These cases may be obtained as the failed cases. The obtained failed cases may be used as guidance for revising the initial prompt as a tree-structured prompt with conditional branches. Thus, obtaining the failed cases may implement a technical effect of providing a basis for enhancing the initial prompt for the failed cases.

[0027] In an aspect, the proposed automatic tree-structured prompt optimization mechanism may then determine target patterns based on the failed cases, for example, through performing error analyzing, reason summarizing, etc. The target patterns may provide information about the underlying common reasons resulting in the failed cases. Bases on the target patterns, prompt revising suggestions may be determined. The prompt revising suggestions provide possible solutions for the target patterns. Thus, determining the target patterns and the prompt revising suggestions may implement a technical effect of enhancing the initial prompt for the failed case.

[0028] In an aspect, according to the prompt revising suggestions, one or more conditional branches may be determined and added to the multiple sequential instructions of the initial prompt. Through adding the conditional branches, the initial prompt may be revised as a tree-structured prompt with conditional branches. The revised tree-structured prompt may facilitate LLM following corresponding conditional branch instructions during performing the specific task. Thus, generating the revised prompt through adding the conditional branches according to the prompt revising suggestions may implement a technical effect of facilitating LLM to generate a more accurate model output for various complex scenarios.

[0029] FIG. 1 illustrates an exemplary process 100 for automatic tree-structured prompt optimization according to an embodiment.

[0030] As illustrated in FIG. 1, a prompt template 110 may be created. The prompt template 110 is a general template for generating prompts adaptive to a type of tasks. In an example, the prompt template 110 may include multiple structurally arranged sections. Thus, the prompt template 110 may also be referred to a structured prompt  template 110. For example, FIG. 1 illustrates that the prompt template 110 may include an objective section 110-1, an output definition section 110-2, an input information section 110-3, an instruction section 110-4, an example section 110-5, and an output format section 110-6, etc. In an example, the instruction section 110-4 may include multiple sequential instructions for instructing LLM to perform corresponding processing respectively. Structurally arranging these sections in the prompt template 110 may implement a technical effect of facilitating LLM to accurately identify the task and perform corresponding analyzing and processing for the task. Details about creating the prompt template 110 will be discussed below with reference to FIG. 2.

[0031] The prompt template 110 may include one or more input parameter placeholders that are reserved for a specific task. One or more input parameters 120 corresponding respectively to the one or more input parameter placeholders may be received, for example, from a user. The input parameters 120 may include data associated with the specific task and are to be filled into the prompt template 110.

[0032] At 130, initial prompt generating may be performed, to generate an initial prompt based on the prompt template 110 and the input parameters 120. In an example, the initial prompt may be generated through filling each of the input parameters 120 to a corresponding input parameter placeholder of the prompt template 110. Details about generating the initial prompt will be discussed below with reference to FIG. 3.

[0033] At 140, failed case obtaining may be performed, to obtain one or more failed cases associated with the initial prompt. A failed case occurs when LLM fails to generate, under the instructing of the initial prompt, an accurate model output for the specific task. In an example, the failed cases may be obtained through evaluating the initial prompt on a training data set. Details about obtaining the failed cases will be discussed below with reference to FIG. 4.

[0034] At 150, error analyzing may be performed on the failed cases obtained at 140, to obtain reasons associated with the failed cases. In an example, the error analyzing may be performed through identifying possible perspectives that may be considered when handling the specific task, and analyzing potential reasons resulting in the failed case based on the perspectives. In an example, the error analyzing may be performed through applying a prompt analyzing model. Details about performing the error analyzing will be discussed below with reference to FIG. 5 and FIG. 6.

[0035] At 160, reason summarizing may be performed on the reasons obtained at 150, to determine target patterns. In an example, the reason summarizing may be performed through summarizing the reasons into candidate patterns, obtaining a respective importance score for each candidate pattern, and selecting the target patterns from the candidate patterns based on the importance scores of the candidate patterns.

[0036] At 170, prompt revising suggestion generating may be performed, to determine prompt revising suggestions for the target patterns obtained at 160. For each target pattern, one or more prompt revising suggestions may be generated. Each prompt revising suggestion may provide a possible strategy for amending the instruction of the initial prompt to make the initial prompt being more adaptive to the target pattern. The prompt revising suggestions may be used to determine conditional branches 171. Each conditional branch may be written in, for example, a “if-then” format, wherein “if” defines a condition, and “then” defines the processing needed to be performed by LLM when the “if” condition is met.

[0037] At 180, tree-structured prompt generating may be performed, to generate revised prompts according to the prompt revising suggestions determined at 170. In an example, the tree-structured prompt generating may be performed through identifying related instruction for each prompt revising suggestion, and adding the conditional branches 171 as determined according to the prompt revising suggestions respectively to the respective related instruction.

[0038] Details about performing the reason summarizing at 160, the prompt revising suggestion generating at 170, and the tree-structured prompt generating at 180 will be discussed below with reference to FIG. 7 to FIG. 11.

[0039] FIG. 1 also illustrates an optional operation 190. At 190, operations for prompt optimizing as discussed above, for example, with reference to 140-180, may be performed iteratively until an iteration stopping condition is met. During performing the iterating, the revised prompts generated in a current iteration may be used as input for a next iteration. Thus, each revised prompt may be further optimized in the next iteration through using failed cases obtained for the revised prompt as a feedback. Performing the prompt optimization iterating may implement a technical effect of progressively enhancing the tree-structured prompt in each iteration. Details about performing the prompt optimization iterating will be discussed below with reference to FIG. 12 and FIG. 13.

[0040] FIG. 2 illustrates an exemplary process 200 of creating a prompt template according to an embodiment. In an example, the prompt template may correspond to the prompt template 110 as discussed above with reference to FIG. 1.

[0041] As discussed above, the prompt template may be parameterized as including multiple structurally arranged sections. Such a parameterization may facilitate LLM to accurately identify a task to be performed and perform corresponding analyzing and processing for the task.

[0042] In an example, the structurally arranged sections may include an objective section, an output definition section, an input information section, an instruction section, an example section, and an output format section, etc.

[0043] The objective section may include general descriptions for the task to be performed by LLM. In an example, the general descriptions may include an explanation for a problem to be handled, a role that LLM should play when handling the problem, etc. For example, when LLM is applied to perform a search query understanding task to generate a predicted personalized query intent by using a user’s current query and the user’s search history as inputs, an example objective section may be written as:

[0044] “# Objective

[0045] You are a personalized search expert. One user typed a query. You are helping a search engine to determine if there are evidence in user's search history that could help personalize user's current query. Your goal is to rate how likely the user's query is personalized based on the user's search history. ”

[0046] The output definition section may include definition for data space of a respective output, which may facilitate LLM to generate model output falling in the data space. For example, for the above search query understanding task, the output definition section may be written as:

[0047] “# Output Definition

[0048] - A score of 1 means strong evidence that the user’s search history does not provide information relevant to personalizing the current query.

[0049] - A score of 2 means some evidence that the user's search history provides little to no relevant information for personalizing the current query.

[0050] - A score of 3 means neutral or unclear evidence on whether the user’s search history provides relevant information for personalizing the current query.

[0051] - A score of 4 means some evidence that the user's search history provides relevant information for personalizing the current query.

[0052] - A score of 5 means strong evidence that the user's search history provides highly relevant information for personalizing the current query. ”

[0053] The input information section may include information about input parameters to be provided. The input information section may include one or more input parameter placeholders, which, in an example, may be specified by user. Each input parameter placeholder may define a type of input parameter. However, the specific input parameters themselves are not included in the prompt template, facilitating the prompt template being generally adaptive to a type of tasks without restricting to specific input parameters. For example, for the above search query understanding task, the input information section may be written as:

[0054] “# Input Information

[0055] The user typed { {query} } .

[0056] The user’s search history includes { {URL} } , { {Title} } , and { {Body} } . ”

[0057] Wherein “query” is an input parameter placeholder reserved for the current query, and “URL” , “Title” and “Body” are input parameter placeholders reserved respectively for URL, title and body of webpages in the search history.

[0058] The instruction section may include instructions for instructing LLM to perform corresponding processing to implement the specific task. The instructions may be sequentially arranged, facilitating LLM to follow the instructions step by step. For example, for the above search query understanding task, the instruction section may be written as:

[0059] “# Instruction

[0060] 1. Carefully read the user's query.

[0061] 2. Examine the user's search history to identify any patterns, topics, or specific terms that are relevant to the current query.

[0062] 3. Assess the level of relevance between the search history and the current query. Consider factors such as the frequency of related searches, the recency of related searches, and the specificity of the information sought.

[0063] 4. Determine if the search history provides no, little, neutral, some or strong evidence relevant to personalizing the current query.

[0064] 5. Provide your rating based on the criteria given in the Output Definition section. ”

[0065] The example section may include at least one example input-output data pairs. Including the example section in the prompt template may facilitate LLM generate accurate model output.

[0066] The output format section may include a specified format of the output. For example, for the above search query understanding task, the output format section may be written as:

[0067] “# Output Format

[0068] Give the rating in JSON format. ”

[0069] The above paragraphs discuss about respective concepts and examples of the structured sections that may be included in the prompt template. Next, the process 200 will be discussed in detail to illustrate how to generate each section respectively and combine the sections as the prompt template.

[0070] In an example, at least one section among the above sections may be provided as user inputs, while remaining sections may be created by utilizing a prompt creating model. In an example, the prompt creating model may sequentially generate the remaining sections one by one based on the user inputs.

[0071] As illustrated in FIG. 2, an objective section 211, an input information section 213 and an output format section 216 may be provided as original inputs 210. The objective section 211, the input information section 213 and the output format section 216 may be provided to a prompt creating model 220, to generate an output definition section 212. The newly generated output definition section 212 may then be provided, together with the objective section 211, the input information section 213 and the output format section 216, to the prompt creating model 220, to generate an instruction section 214. The newly generated instruction section 214 may then be provided, together with the objective section 211, the output definition section 212, the input information section 213, and the output format section 216, to the prompt creating model 220, to generate an example section 215. Till now, all required sections are obtained. Thus, a prompt template 230 may be generated through combing the objective section 211, the output definition section 212, the input information section 213, the instruction section 214, the example section 215 and the output format section 216.

[0072] In an example, the prompt creating model 220 may be implemented by any pre-trained universal AI models, e.g., LLM. In another example, the prompt creating model 220 may be implemented by any specialized AI models, for example, AI model  employing a GPT architecture, etc., that are specially trained to create a corresponding section based on some input sections in a similar way as illustrated above.

[0073] In an example, the prompt creating model 220 may generate multiple options for a respective section to be created. Then, a section to be used for constituting the prompt template 230 may be determined according to an evaluation metric. Taking the creating of the output definition section 212 as an example, the prompt creating model 220 may generate multiple optional output definition sections. The evaluation metric that measures a performance of each optional output definition section may be obtained from an evaluator. In an example, the evaluator may be implemented by any known prompt evaluating tool. Then, according to the evaluation metric, one optimal output definition section may be selected from the multiple optional output definition section, to be used for constituting the prompt template 230.

[0074] Although FIG. 2 illustrate six sections, while in an example, at least one section, for example, the example section 215, etc., may be not included in the prompt template 230. In this case, the operation of generating the example section 215 may be omitted accordingly from FIG. 2.

[0075] FIG. 3 illustrates an exemplary process 300 of generating an initial prompt 340 on the basis of a prompt template 310 according to an embodiment.

[0076] In an example, the prompt template 310 may correspond to the prompt template 230 as discussed above with reference to FIG. 2. The prompt template 310 include sections such as objective, input information, output definition, instruction, example, and output format, etc. The input information section may include input parameter placeholders, for example, a URL placeholder 320-1, a Title placeholder 320-2, and a Body placeholder 320-3, etc.

[0077] Input parameters 330 may be received. In an example, the input parameters 330 may include a URL input parameter 330-1 corresponding to the URL placeholder 320-1, a Title input parameter 330-2 corresponding to the Title placeholder 320-2, and a Body input parameter 330-3 corresponding to the Body placeholder 320-3.

[0078] Each of the input parameters may be filled to a corresponding input parameter placeholder, to generate the initial template. For example, the URL input parameter 330-1 may be filled to the URL placeholder 320-1, the Title input parameter 330-2 may be filled to the Title placeholder 320-2, and the Body input  parameter 330-3 may be filled to the Body placeholder 320-3, thus, the initial prompt 340 may be generated.

[0079] FIG. 4 illustrates an exemplary process 400 of obtaining failed cases according to an embodiment.

[0080] At 410, an initial prompt may be obtained. In an example, the initial prompt may correspond to the initial prompt 340 as discussed above with reference to FIG. 3. The initial prompt may include multiple sequential instructions, for example, in an instruction section, for instructing LLM to perform a specific task.

[0081] At 420, a training data set may be obtained. In an example, the training data set may include multiple training data pairs, each training data pair may include a pair of corresponding input and output. For example, the input-output data pair may be represented as a question and a corresponding answer for the question.

[0082] At 430, the initial prompt may be evaluated on the training data set. Evaluating the initial prompt on the training data set may include, providing an input in one input-output data pair and the initial prompt to LLM, and evaluating whether the LLM outputs an accurate output corresponding to the input. In an example, the evaluating may be implemented by any known prompt evaluating tool.

[0083] At 440, one or more failed cases may be determined based on a result of the evaluation. For example, if the result of the evaluation indicates that LLM fails to output an accurate output, the input-output data pair may be considered as a failed case. The failed cases obtained according to the process 400 may be used as guidance for enhancing the initial prompt.

[0084] FIG. 5 illustrates an exemplary process 500 of performing error analyzing according to an embodiment. The process 500 aims to obtain one or more reasons associated with the one or more failed cases through performing error analyzing on the one or more failed cases.

[0085] At 510, possible perspectives may be identified for an objective associated with the initial prompt. The objective is a description for a specific task to be performed by LLM under the instructing of the initial prompt. In an example, the objective may be determined according to the objective section of the initial sections. A perspective is aspect, direction, point of view, etc., that may be related to the specific task, and thus should be taken into full consideration when handling the specific task. For example, for the above search query understanding task, a possible perspective may be the task could be influenced by recency and frequency of user’s  search history, since out-of-date search history may be misleading for handling the task.

[0086] At 520, for each failed case, each instruction of the initial prompt may be analyzed based on the perspectives to determine at least one reason resulting in the failed case. A reason, which may also be termed as a failure reason, etc., provides information about why a failed case occurs. Through performing the operation at 520 to all failed cases, possible reasons that could have resulting in the failed cases may be determined. Determining these reasons may facilitate providing throughout failure analysis by taking the possible perspectives into full consideration.

[0087] In an example, the operations for performing error analyzing on failed cases as illustrated in FIG. 5 may be performed through utilizing a prompt analyzing model.

[0088] In an example, the prompt analyzing model may be implemented by any AI models that are specially trained to perform an error analyzing task. In this case, the specialized trained model may be trained with multiple training data pairs. Each training data pair may comprise an initial prompt and a failed case as an input, and possible reasons that could leading to the failed case as an output. The specialized trained model may employ any suitable model architecture, e.g., various GPT variants, etc.

[0089] In another example, the prompt analyzing model may be implemented by LLM, as discussed in detail with reference to FIG. 6. FIG. 6 illustrates an exemplary process 600 of utilizing a prompt analyzing model 620 to perform error analyzing according to an embodiment, wherein the prompt analyzing model 620 is implemented by LLM.

[0090] As illustrated in FIG. 6, a meta prompt 610 may be generated, which may be used for instructing the prompt analyzing model 620 to perform the error analyzing. In the present disclosure, any prompt used for instructing LLM to perform operations associated with the prompt optimization process may be referred to a meta prompt, to be distinguished with any one of an initial prompt, an optimized prompt, etc. The meta prompt 610 may include an initial prompt 611, failed cases 612, and instructions 613 for instructing the prompt analyzing model 620 to analyze reasons that may resulting in the failed cases. In an example, the operations 510 and 520 for performing the error analyzing as discussed above with reference to FIG. 5 may be written as sequential steps in the instructions 613. In an example, the instructions 613 may  include further steps except the operations 510 and 520, for facilitating the prompt analyzing model 620 to perform the error analyzing.

[0091] The prompt analyzing model 620 may generate a model output under the instructing of the meta prompt 610. The model output may include multiple reasons 630 that are analyzed for the failed cases.

[0092] FIG. 7 illustrates an exemplary process 700 of generating revised tree-structured prompts based on target patterns and prompt revising suggestions according to an embodiment.

[0093] At 710, reasons that are obtained as discussed above with reference to FIG. 5 and FIG. 6 may be summarized into multiple candidate patterns. A pattern is a higher level generalization or summarization for a set of reasons with a certain common inherent characteristic. Summarizing the reasons into patterns may facilitate exploring the kernel natures of the failed cases and thus facilitate efficiently finding solutions for enhancing the initial prompt for the failed cases. For example, for the above search query understanding task, one possible candidate pattern may be “the current prompt fails to consider the recency and frequency of related searches or recognize indirect but relevant aspects of interest in the search history” .

[0094] At 720, an importance score may be obtained for each candidate pattern. The importance score may measure a degree of the pattern will influence LLM to generate an accurate model output. For example, if omitting a pattern will cause a significant decrease on accuracy of the model output, then the pattern should be assigned with a higher importance score.

[0095] At 730, highest-ranked N candidate patterns may be selected based on importance scores of the multiple candidate patterns, as the one or more target patterns, wherein N is a positive integer. Selecting partial of the candidate patterns as the target patterns may facilitate the prompt optimizing process to focus on more important patterns and avoid to generate too much revised prompts in one iteration. In an example, N may be set to be equal to 1, and thus only one most important pattern is to be selected from the multiple candidate patterns as the target pattern.

[0096] At 740, after the target patterns are obtained, prompt revising suggestions may be determined for the target patterns. In an example, for each target pattern, one or more prompt revising suggestions may be generated. Generating prompt revising suggestions may be implemented through analyzing the target pattern and proposing possible strategies for amending the instruction of the initial prompt to make the  initial prompt being more adaptive to the target pattern. Wherein each strategy may be referred to as a prompt revising suggestion. For example, for the above discussed pattern “the current prompt fails to consider the recency and frequency of related searches or recognize indirect but relevant aspects of interest in the search history” , a possible exemplary prompt revising suggestion may be “the prompt should consider both the influence of recency and frequency of related searches on the score and the influence of relevant aspects of interest in the search history on the score” . The prompt revising suggestions may then be used to determine conditional branches to be added to the instruction of the initial prompt.

[0097] At 750, for each prompt revising suggestion, at least one instruction among the multiple sequential instructions that is related to the prompt revising suggestion may be identified. In an example, identifying the related instruction may be implemented through traversing each instruction among the multiple sequential instructions to analyze which instruction is related to the prompt revising suggestion. In an example, there may be one or more instructions being related to one prompt revising suggestion.

[0098] At 760, for each instruction that is related to the prompt revising suggestion, at least one conditional branch may be determined according to the prompt revising suggestion, and then the at least one conditional branch may be added to the instruction. Each conditional branch may be written in, for example, a “if-then” format, wherein “if” defines a condition, and “then” defines the processing needed to be performed by LLM when the “if” condition is met. For example, for the above exemplary prompt revising suggestion “the prompt should consider both the influence of recency and frequency of related searches on the score and the influence of relevant aspects of interest in the search history on the score” , three exemplary conditional branches may be determined and added to step 4 of the instruction section of the initial prompt as discussed above with reference to FIG. 2:

[0099] “# Instruction

[0100] 1. Carefully read the user's query.

[0101] 2. Examine the user's search history to identify any patterns, topics, or specific terms that are relevant to the current query.

[0102] 3. Assess the level of relevance between the search history and the current query. Consider factors such as the frequency of related searches, the recency of related searches, and the specificity of the information sought.

[0103] 4. Determine if the search history provides no, little, neutral, some or strong evidence relevant to personalizing the current query, by considering the following conditions:

[0104] - If the user's search history contains recent and multiple searches related to the current query, then the score should be higher, indicating strong evidence for personalization.

[0105] - If the user's search history contains searches that are not directly related to the current query or are outdated (more than 30 days ago) , then the score should be lower, indicating weak or no evidence for personalization.

[0106] - If the user's search history shows an aspect of interest in a specific topic or related topics to the current query, even if not recent, then the score should reflect possible evidence for personalization, but not as high as with recent searches.

[0107] 5. Provide your rating based on the criteria given in the Output Definition section. ”

[0108] Through adding the conditional branches to the related instruction of the initial prompt, the initial prompt may be revised as a tree-structured prompt with conditional branches. The revised tree-structured prompt may facilitate LLM following corresponding conditional branch instructions during performing the specific task, and thus generating more accurate model output.

[0109] Although in the above example revised instruction section, other steps 1-3 and 5 are not changed, while in an example, these other steps may also be adjusted according to the prompt revising suggestions, to be adapted to the added conditional branches.

[0110] At 770, an optional branch pruning operation may be performed after the one or more conditional branches are added. Performing the branch pruning operation may facilitate removing redundant conditional branches, which may be beneficial for avoiding prompt overfitting.

[0111] In an example, the operations for generating the revised tree-structured prompts based on target patterns and prompt revising suggestions as illustrated in FIG. 7 may be performed through utilizing various AI models, for example, a reason summarizing model, a prompt revising model, etc. It may be flexibly designed about which operations will be implemented by which models. In an example, the reason summarizing model may be applied to generate the target patterns based on reasons for the failed cases, for example, through implementing the operations discussed above in combination with 710-730, and the prompt revising model may be applied to  revise the initial prompt based on the target patterns, for example, through implementing the operations discussed above in combination with 740-770, as discussed below with reference to FIG. 8 to FIG. 9. In another example, the reason summarizing model may be applied to generate the prompt revising suggestions based on reasons for the failed cases, for example, through implementing the operations discussed above in combination with 710-740, and the prompt revising model may be applied to revise the initial prompt based on the prompt revising suggestions, for example, through implementing the operations discussed above in combination with 750-770, as discussed below with reference to FIG. 10 to FIG. 11.

[0112] FIG. 8 illustrates an exemplary process 800 of utilizing a reason summarizing model 820 to generate target patterns according to an embodiment, wherein the reason summarizing model 820 is implemented by LLM.

[0113] As illustrated in FIG. 8, an exemplary meta prompt 810 may be generated, which may be used for instructing the reason summarizing model 820 to generate target patterns based on reasons identified for the failed cases. The meta prompt 810 may include an initial prompt 811, reasons for failed cases 812, and instructions 813. The instructions 813 may be used for instructing the reason summarizing model 820 to generate target patterns based on reasons identified for the failed cases. In this case, the operations 710 to 730 as discussed above with reference to FIG. 7 may be written as sequential steps in the instructions 813. In an example, the expressions as used in the sequential steps may be not strictly in line with the expressions as used in the operations 710 to 730, without departing from the scope of the present disclosure. In an example, the instructions 813 may include further steps except the operations 710 to 730, for facilitating the reason summarizing model 820 to generate the target patterns based on the reasons. As illustrated in FIG. 8, the reason summarizing model 820 may generate a model output under the instructing of the meta prompt 810. The model output may include the target patterns 830.

[0114] FIG. 9 illustrates an exemplary process 900 of utilizing a prompt revising model 920 to generate revised tree-structured prompts according to an embodiment, wherein the prompt revising model 920 is implemented by LLM.

[0115] As illustrated in FIG. 9, an exemplary meta prompt 910 may be generated, which may be used for instructing the prompt revising model 920 to revise the initial prompt based on the target patterns. The third meta prompt 910 may include an initial prompt 911, target patterns 912, and instructions 913. The instructions 913 may be  used for instructing the prompt revising model 920 to revise the initial prompt based on the target patterns. In this case, the operations 740 to 770 as discussed above with reference to FIG. 7 may be written as sequential steps in the instructions 913. In an example, the expressions as used in the sequential steps may be not strictly in line with the expressions as used in the operations 740 to 770, without departing from the scope of the present disclosure. In an example, the instructions 913 may include further steps except the operations 740 to 770, for facilitating the prompt revising model 920 to revise the initial prompt based on the target patterns. As illustrated in FIG. 9, the prompt revising model 920 may generate a model output under the instructing of the meta prompt 910. The model output may include one or more revised prompts 930, each revised prompt may be a tree-structured prompt with conditional branches.

[0116] FIG. 10 illustrates an exemplary process 1000 of utilizing a reason summarizing model 1020 to generate prompt revising suggestions according to an embodiment, wherein the reason summarizing model 1020 is implemented by LLM.

[0117] As illustrated in FIG. 10, an exemplary meta prompt 1010 may be generated, which may be used for instructing the reason summarizing model 1020 to generate prompt revising suggestions based on reasons identified for the failed cases. The meta prompt 1010 may include an initial prompt 1011, reasons for failed cases 1012, and instructions 1013. The instructions 1013 may be used for instructing the reason summarizing model 1020 to generate prompt revising suggestions based on reasons identified for the failed cases. In this case, the operations 710 to 740 as discussed above with reference to FIG. 7 may be written as sequential steps in the instructions 1013. In an example, the expressions as used in the sequential steps may be not strictly in line with the expressions as used in the operations 710 to 740, without departing from the scope of the present disclosure. In an example, the instructions 1013 may include further steps except the operations 710 to 740, for facilitating the reason summarizing model 1020 to generate the prompt revising suggestions based on the reasons. As illustrated in FIG. 10, the reason summarizing model 1020 may generate a model output under the instructing of the meta prompt 1010. The model output may include the prompt revising suggestions 1030.

[0118] FIG. 11 illustrates another exemplary process 1100 of utilizing a prompt revising model 1120 to generate revised tree-structured prompts according to an embodiment, wherein the prompt revising model 1120 is implemented by LLM.

[0119] As illustrated in FIG. 11, an exemplary meta prompt 1110 may be generated, which may be used for instructing the prompt revising model 1120 to revise the initial prompt based on prompt revising suggestions. The meta prompt 1110 may include an initial prompt 1111, prompt revising suggestions 1112, and instructions 1113. The instructions 1113 may be used for instructing the prompt revising model 1120 to revise the initial prompt based on the prompt revising suggestions. In this case, the operations 750 to 770 as discussed above with reference to FIG. 7 may be written as sequential steps in the instructions 1113. In an example, the expressions as used in the sequential steps may be not strictly in line with the expressions as used in the operations 750 to 770, without departing from the scope of the present disclosure. In an example, the instructions 1113 may include further steps except the operations 750 to 770, for facilitating the prompt revising model 1120 to revise the initial prompt based on the prompt revising suggestions. As illustrated in FIG. 11, the prompt revising model 1120 may generate a model output under the instructing of the meta prompt 1110. The model output may include one or more revised prompts 1130, each revised prompt may be a tree-structured prompt with conditional branches.

[0120] Although it is discussed above about implementing the reason summarizing model and the prompt revising model with LLM, in other examples, the reason summarizing model and the prompt revising model may be implemented with other AI models that are specially trained to perform respective tasks. In this case, each specialized trained model may be trained with multiple training data pairs. For example, when the reason summarizing model is applied to generate the target patterns based on reasons for the failed cases, each training data pair may comprise an initial prompt and reasons for the failed cases as an input, and target patterns as an output. For example, when the reason summarizing model is applied to generate the prompt revising suggestions based on reasons for the failed cases, each training data pair may comprise an initial prompt and reasons for the failed cases as an input, and prompt revising suggestions as an output. For example, when the prompt revising model is applied to revise the initial prompt based on the target patterns, each training data pair may comprise an initial prompt and target patterns as an input, and revised tree-structured prompts with conditional branches as an output. For example, when the prompt revising model is applied to revise the initial prompt based on the prompt revising suggestions, each training data pair may comprise an initial prompt and  prompt revising suggestions as an input, and revised tree-structured prompts with conditional branches as an output. In an example, such specialized trained models may employ any suitable model architecture, e.g., various GPT variants, etc.

[0121] As discussed above with reference to FIG. 1, prompt optimizing operations may be performed iteratively, to progressively enhance the prompt by using failed cases as feedback. In each iteration, a current prompt may be optimized to generate one or more optimized prompts for entering the next iteration. FIG. 12 illustrates an exemplary process 1200 of generating target prompts for a next iteration according to an embodiment.

[0122] A current prompt 1210 is a prompt to be optimized in a current iteration. In an example, the current prompt may be an initial prompt or one of revised prompts coming from a previous iteration.

[0123] In an example, tree-structured prompt optimizing 1220-1 may be performed to the current prompt 1210, to add new conditional branches to the current prompt 1210 by using failed cases as guidance as detailed above. Through performing the tree-structured prompt optimizing 1220-1, one or more revised prompts with new conditional branches 1230-1 may be obtained.

[0124] In an example, non tree-structured prompt optimizing 1220-2 may be performed to the current prompt 1210. Performing the non tree-structured prompt optimizing 1220-2 may comprise revising the instructions of the current prompt 1210 according to the prompt revising suggestions without adding new conditional branches. For example, during performing the non tree-structured prompt optimizing 1220-2, existing instructions and / or existing conditional branches may be further enhanced according to the prompt revising suggestions. Through performing the non tree-structured prompt optimizing 1220-2, one or more revised prompts without new conditional branches 1230-2 may be obtained.

[0125] In an example, a determining operation may be added on the basis of the operations for performing the prompt revising as discussed above with reference to FIG. 9. The determining operation may determine which one of tree-structured prompt optimizing 1220-1 and non tree-structured prompt optimizing 1220-2 is more suitable, thus facilitating generating optimized prompts with various different structure to adapt different task scenarios.

[0126] In an example, the one or more revised prompts with new conditional branches 1230-1 and the one or more revised prompts without new conditional  branches 1230-2 may be combined together as a set of candidate prompts 1240. Next, prompt evaluating 1250 may be performed on the set of candidate prompts 1240 to generate a ranking result 1260. In an example, performing the prompt evaluating 1250 may comprise evaluating each candidate prompt on a validation data set. In an example, the validation data set may be as subset of the above-mentioned training data set. In an example, the evaluating may be implemented by any known prompt evaluating tool. In the ranking result 1260, the candidate prompts may be ranked from high to low according to a result of the evaluating.

[0127] Next, one or more prompts with higher ranks may be selected, according to the ranking result, from the set of candidate prompts 1240 as target prompts 1270 for entering the next iteration. The number of target prompt selected in each iteration may be pre-determined. In an example, the number may be set as a relatively small value for facilitating performing the whole optimizing process in an efficient way.

[0128] FIG. 13 illustrates an exemplary process 1300 of iteratively performing prompt optimizing according to an embodiment.

[0129] At 1310, a current prompt may be determined. The current prompt is a prompt to be optimized in a current iteration. In an example, the current prompt may be an initial prompt or one of revised prompts coming from a previous iteration.

[0130] At 1320, it is decided whether an iteration stopping condition is met.

[0131] In an example, the iteration stopping condition is associated with an iteration count threshold T. If a current iteration count t is larger than the iteration count threshold T, the iteration stopping condition is met. Otherwise, if the current iteration count t is not larger than the iteration count threshold T, the iteration stopping condition is not met. Setting such an iteration stopping condition may restrict the iterations in a limited number and thus facilitate improving efficiency of the whole prompt optimizing process.

[0132] In another example, the iteration stopping condition is associated with a cross-validation result obtained for the current prompt. If the cross-validation result shows that the performance of the current prompt is not significantly improved after the previous iteration, the iteration stopping condition is met. Otherwise, if the cross-validation result shows that the performance of the current prompt is significantly improved after the previous iteration, the iteration stopping condition is not met. Setting such an iteration stopping condition may facilitate early-stopping the iterations once the performance improving of the prompt entering a relative stable state and  avoiding potential prompt overfitting by maintaining a simpler prompt structure.

[0133] If the iteration stopping condition is met, the process may proceed to 1340, wherein the iteration may be ended. If the iteration stopping condition is not met, the process may proceed to 1330, wherein at least one target prompt to be used for the next iteration may be generated, for example, according to the operations as detailed above with reference to FIG. 12. Then the process may proceed to 1340 to end the iteration or go back to 1310 to perform the next iteration.

[0134] FIG. 14 illustrates a flowchart of an exemplary method 1400 for automatic tree-structured prompt optimization according to an embodiment.

[0135] At 1410, an initial prompt may be obtained, wherein the initial prompt comprises multiple sequential instructions.

[0136] At 1420, one or more failed cases associated with the initial prompt may be obtained.

[0137] At 1430, one or more target patterns may be determined for the one or more failed cases.

[0138] At 1440, one or more prompt revising suggestions may be determined for the one or more target patterns.

[0139] At 1450, at least one revised prompt may be generated through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.

[0140] In an implementation, the determining one or more target patterns may comprise: performing error analyzing on the one or more failed cases to obtain one or more reasons associated with the one or more failed cases; and performing reason summarizing on the one or more reasons to obtain the one or more target patterns.

[0141] In an implementation, the performing error analyzing may comprise: identifying perspectives for an objective associated with the initial prompt; and for each failed case among the one or more failed cases, analyzing, based on the perspectives, each instruction among the multiple sequential instructions to determine at least one reason resulting in the failed case.

[0142] In an implementation, the performing error analyzing may comprise: generating a first meta prompt for instructing a prompt analyzing model to perform the error analyzing; providing the first meta prompt to the prompt analyzing model; and receiving the one or more reasons from the prompt analyzing model.

[0143] In an implementation, the performing reason summarizing may comprise:  summarizing the one or more reasons into multiple candidate patterns; obtaining, for each candidate pattern among the multiple candidate patterns, an importance score; and selecting, based on importance scores of the multiple candidate patterns, highest-ranked N candidate patterns among the multiple candidate patterns as the one or more target patterns.

[0144] In an implementation, the one or more target patterns or the one or more prompt revising suggestions may be determined through: generating a second meta prompt, the second meta prompt at least comprising the initial prompt and the one or more reasons; providing the second meta prompt to a reason summarizing model; and receiving the one or more target patterns or the one or more prompt revising suggestions from the reason summarizing model.

[0145] In an implementation, the generating at least one revised prompt may comprise: identifying, for each prompt revising suggestion among the one or more prompt revising suggestions, at least one instruction among the multiple sequential instructions that is related to the prompt revising suggestion; and for each instruction among the at least one instruction, determining at least one conditional branch according to the prompt revising suggestion, and adding the at least one conditional branch to the instruction.

[0146] In an implementation, the generating at least one revised prompt may further comprise: performing a branch pruning operation after the one or more conditional branches are added.

[0147] In an implementation, the generating at least one revised prompt may comprise: generating a third meta prompt, the third meta prompt at least comprising the initial prompt and the one or more target patterns, or at least comprising the initial prompt and the one or more prompt revising suggestions; providing the third meta prompt to a prompt revising model; and receiving the at least one revised prompt from the prompt revising model.

[0148] In an implementation, the obtaining an initial prompt may comprise: creating a prompt template, the prompt template comprising one or more input parameter placeholders; receiving one or more input parameters corresponding respectively to the one or more input parameter placeholders; and generating the initial prompt through filling each of the one or more input parameters to a corresponding input parameter placeholder.

[0149] In an implementation, wherein the prompt template comprises multiple  sections, the multiple sections comprise at least one of an objective section, an output definition section, an input information section, an instruction section, an example section, and an output format section, and the instruction section comprises the multiple sequential instructions.

[0150] In an implementation, wherein at least one section among the multiple sections is generated by a prompt creating model.

[0151] In an implementation, the method 1300 may further comprise: determining a set of candidate prompts including the at least one revised prompt; and determining, from among the set of candidate prompts, at least one target prompt.

[0152] In an implementation, wherein the set of candidate prompts further include one or more prompts generated through revising the multiple sequential instructions according to the one or more prompt revising suggestions without adding the conditional branches.

[0153] In an implementation, the determining at least one target prompt may comprise: obtaining a ranking result of the set of candidate prompts through evaluating each candidate prompt among the set of candidate prompts; and selecting, among the set of candidate prompts, the at least one target prompt according to the ranking result.

[0154] It should be appreciated that the method 1400 may further comprise any steps / processes for automatic tree-structured prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0155] FIG. 15 illustrates an exemplary apparatus 1500 for automatic tree-structured prompt optimization according to an embodiment. The apparatus 1500 may comprise: an initial prompt obtaining module 1510, for obtaining an initial prompt, the initial prompt comprising multiple sequential instructions; a failed case obtaining module 1520, for obtaining one or more failed cases associated with the initial prompt; a target pattern determining module 1530, for determining, for the one or more failed cases, one or more target patterns; a prompt revising suggestion determining module 1540, for determining, for the one or more target patterns, one or more prompt revising suggestions; and a revised prompt generating module 1550, for generating at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions. Moreover, the apparatus 1500 may also comprise any other modules configured for performing any steps and operations of the methods for automatic tree- structured prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0156] FIG. 16 illustrates an exemplary apparatus 1600 for automatic tree-structured prompt optimization according to an embodiment. The apparatus 1600 may comprise at least one processor 1610 and a memory 1620 storing computer-executable instructions. When the computer-executable instructions are executed, the at least one processor 1610 may: obtain an initial prompt, the initial prompt comprising multiple sequential instructions; obtain one or more failed cases associated with the initial prompt; determine, for the one or more failed cases, one or more target patterns; determine, for the one or more target patterns, one or more prompt revising suggestions; and generate at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions. The at least one processor 1610 may be further configured for performing any operations of the methods for automatic tree-structured prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0157] The embodiments of the present disclosure may be embodied in a non-transitory computer-readable medium for automatic tree-structured prompt optimization. The non-transitory computer readable medium may include instructions that, when executed, cause one or more processors to: obtain an initial prompt, the initial prompt comprising multiple sequential instructions; obtain one or more failed cases associated with the initial prompt; determine, for the one or more failed cases, one or more target patterns; determine, for the one or more target patterns, one or more prompt revising suggestions; and generate at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions. The instructions, when executed, may further cause one or more processors to perform any operations of the methods for automatic tree-structured prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0158] The embodiments of the present disclosure may be embodied in a computer program product for automatic tree-structured prompt optimization. The computer program product may include instructions that, when executed, cause at least one processor to: obtain an initial prompt, the initial prompt comprising multiple sequential instructions; obtain one or more failed cases associated with the initial  prompt; determine, for the one or more failed cases, one or more target patterns; determine, for the one or more target patterns, one or more prompt revising suggestions; and generate at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions. The instructions, when executed, may further cause the at least one processor to perform any operations of the methods for automatic tree-structured prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0159] It should be appreciated that all the operations in the methods described above are merely exemplary, and the present disclosure is not limited to any operations in the methods or orders of these operations, and should cover all other equivalents under the same or similar concepts.

[0160] It should also be appreciated that all the modules in the apparatuses described above may be implemented in various approaches. These modules may be implemented as hardware, software, or a combination thereof. Moreover, any of these modules may be further functionally divided into sub-modules or combined together.

[0161] Processors have been described in connection with various apparatuses and methods. These processors may be implemented using electronic hardware, computer software, or any combination thereof. Whether such processors are implemented as hardware or software will depend upon the particular application and overall design constraints imposed on the system. By way of example, a processor, any portion of a processor, or any combination of processors presented in the present disclosure may be implemented with a micro-processor, micro-controller, digital signal processor (DSP) , a field-programmable gate array (FPGA) , a programmable logic device (PLD) , a state machine, gated logic, discrete hardware circuits, and other suitable processing components configured to perform the various functions described in the present disclosure. The functionality of a processor, any portion of a processor, or any combination of processors presented in the present disclosure may be implemented with software being executed by a microprocessor, micro-controller, DSP, or other suitable platform.

[0162] Software shall be construed broadly to mean instructions, instruction sets, code, code segments, program code, programs, subprograms, software modules, applications, software applications, software packages, routines, subroutines, objects, threads of execution, procedures, functions, etc. The software may reside on a  computer-readable medium. A computer-readable medium may include, by way of example, memory such as a magnetic storage device (e.g., hard disk, floppy disk, magnetic strip) , an optical disk, a smart card, a flash memory device, random access memory (RAM) , read only memory (ROM) , programmable ROM (PROM) , erasable PROM (EPROM) , electrically erasable PROM (EEPROM) , a register, or a removable disk. Although a memory is shown as being separate from the processor in various aspects presented in this disclosure, the memory may also be internal to the processor (e.g., a cache or a register) .

[0163] Moreover, the articles “a” and “an” as used in this specification and the appended claims should generally be construed to mean “one” or “one or more” unless specified otherwise or clear from the context to be directed to a singular form. The previous description is provided to enable any person skilled in the art to practice the various aspects described herein. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects. Thus, the claims are not intended to be limited to the aspects shown herein. All structural and functional equivalents to the elements of the various aspects described throughout the present disclosure that are known or later come to be known to those of ordinary skilled in the art are intended to be encompassed by the claims.

Claims

1.A method for prompt optimization, comprising:obtaining an initial prompt, the initial prompt comprising multiple sequential instructions;obtaining one or more failed cases associated with the initial prompt;determining, for the one or more failed cases, one or more target patterns;determining, for the one or more target patterns, one or more prompt revising suggestions; andgenerating at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.2.The method of claim 1, wherein the determining one or more target patterns comprises:performing error analyzing on the one or more failed cases to obtain one or more reasons associated with the one or more failed cases; andperforming reason summarizing on the one or more reasons to obtain the one or more target patterns.3.The method of claim 2, wherein the performing error analyzing comprises:identifying perspectives for an objective associated with the initial prompt; andfor each failed case among the one or more failed cases, analyzing, based on the perspectives, each instruction among the multiple sequential instructions to determine at least one reason resulting in the failed case.4.The method of claim 2, wherein the performing error analyzing comprises:generating a first meta prompt for instructing a prompt analyzing model to perform the error analyzing;providing the first meta prompt to the prompt analyzing model; andreceiving the one or more reasons from the prompt analyzing model.5.The method of claim 2, wherein the performing reason summarizing comprises:summarizing the one or more reasons into multiple candidate patterns;obtaining, for each candidate pattern among the multiple candidate patterns, an importance score; andselecting, based on importance scores of the multiple candidate patterns, highest-ranked N candidate patterns among the multiple candidate patterns as the one or more target patterns.6.The method of claim 1, wherein the one or more target patterns or the one or more prompt revising suggestions are determined through:generating a second meta prompt, the second meta prompt at least comprising the initial prompt and the one or more reasons;providing the second meta prompt to a reason summarizing model; andreceiving the one or more target patterns or the one or more prompt revising suggestions from the reason summarizing model.7.The method of claim 1, wherein the generating at least one revised prompt comprises:identifying, for each prompt revising suggestion among the one or more prompt revising suggestions, at least one instruction among the multiple sequential instructions that is related to the prompt revising suggestion; andfor each instruction among the at least one instruction, determining at least one conditional branch according to the prompt revising suggestion, and adding the at least one conditional branch to the instruction.8.The method of claim 7, wherein the generating at least one revised prompt further comprises:performing a branch pruning operation after the one or more conditional branches are added.9.The method of claim 1, wherein the generating at least one revised prompt comprises:generating a third meta prompt, the third meta prompt at least comprising the initial prompt and the one or more target patterns, or at least comprising the initial prompt and the one or more prompt revising suggestions;providing the third meta prompt to a prompt revising model; andreceiving the at least one revised prompt from the prompt revising model.10.The method of claim 1, wherein the obtaining an initial prompt comprises:creating a prompt template, the prompt template comprising one or more input parameter placeholders;receiving one or more input parameters corresponding respectively to the one or more input parameter placeholders; andgenerating the initial prompt through filling each of the one or more input parameters to a corresponding input parameter placeholder.11.The method of claim 10, whereinthe prompt template comprises multiple sections,the multiple sections comprise at least one of an objective section, an output definition section, an input information section, an instruction section, an example section, and an output format section, andthe instruction section comprises the multiple sequential instructions.12.The method of claim 11, wherein at least one section among the multiple sections is generated by a prompt creating model.13.The method of claim 1, further comprising:determining a set of candidate prompts including the at least one revised prompt; anddetermining, from among the set of candidate prompts, at least one target prompt.14.The method of claim 13, wherein the set of candidate prompts further include one or more prompts generated through revising the multiple sequential instructions according to the one or more prompt revising suggestions without adding the conditional branches.15.The method of claim 13, wherein the determining at least one target prompt comprises:obtaining a ranking result of the set of candidate prompts through evaluating each candidate prompt among the set of candidate prompts; andselecting, among the set of candidate prompts, the at least one target prompt according to the ranking result.16.An apparatus for prompt optimization, comprising:at least one processor; anda memory storing computer-executable instructions that, when executed, cause the at least one processor to:obtain an initial prompt, the initial prompt comprising multiple sequential instructions;obtain one or more failed cases associated with the initial prompt;determine, for the one or more failed cases, one or more target patterns;determine, for the one or more target patterns, one or more prompt revising suggestions; andgenerate at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.17.The apparatus of claim 16, wherein the determining one or more target patterns comprises:performing error analyzing on the one or more failed cases to obtain one or more reasons associated with the one or more failed cases; andperforming reason summarizing on the one or more reasons to obtain the one or more target patterns.18.The apparatus of claim 17, wherein the performing error analyzing comprises:identifying perspectives for an objective associated with the initial prompt; andfor each failed case among the one or more failed cases, analyzing, based on the perspectives, each instruction among the multiple sequential instructions to determine at least one reason resulting in the failed case.19.A non-transitory computer-readable medium, comprising instructions that, when executed, cause at least one processor to:obtain an initial prompt, the initial prompt comprising multiple sequential instructions;obtain one or more failed cases associated with the initial prompt;determine, for the one or more failed cases, one or more target patterns;determine, for the one or more target patterns, one or more prompt revising suggestions; andgenerate at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.20.A computer program product, comprising instructions that, when executed, cause at least one processor to:obtain an initial prompt, the initial prompt comprising multiple sequential instructions;obtain one or more failed cases associated with the initial prompt;determine, for the one or more failed cases, one or more target patterns;determine, for the one or more target patterns, one or more prompt revising suggestions; andgenerate at least one revised prompt through adding one or more conditional branches to the multiple sequential instructions according to the one or more prompt revising suggestions.