Prompt word optimization method and device, electronic equipment and storage medium

By extracting the feature vectors of current failed tasks and retrieving historical data from the context memory, a semantic pseudo-gradient signal is generated and fused with a general task strategy to optimize the prompt words. This solves the problem that prompt word updates are prone to getting trapped in local optima and achieves cross-task generalization and improved stability.

CN121920385APending Publication Date: 2026-04-24SHANG FEI ZHI NENG JI SHU YOU XIAN GONG SI
View PDF 9 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANG FEI ZHI NENG JI SHU YOU XIAN GONG SI
Filing Date
2026-03-26
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing prompt optimization mechanisms can only make partial repairs to local errors, which makes prompt updates prone to getting stuck in local optima and makes it difficult to achieve stable and automated evolution with cross-task generalization capabilities.

Method used

By extracting the feature vector of the current failed task, retrieving historical scenario data from the context memory, generating a semantic pseudo-gradient signal, and integrating it with a general task strategy, the current task prompt words are optimized, including operations such as increasing or decreasing instruction weights according to preset step size coefficients, rearranging the order of constraints, and inserting error type labels.

Benefits of technology

It achieves both accurate repair for specific failed tasks and guidance based on general rules, significantly improving the targeting, stability, and cross-task generalization ability of prompt word optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121920385A_ABST
    Figure CN121920385A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, and provides a cue word optimization method and device, electronic equipment and a storage medium, and the method comprises the steps: extracting a case feature vector of a current failure task, fusing a semantic pseudo-gradient signal obtained through mapping based on historical scene data with a general task strategy, and obtaining a case feature vector of the current failure task; and optimizing the current task cue word based on the fused pseudo gradient signal. According to the method provided by the invention, the case feature vector of the current failure task is extracted, the matched historical scene data is retrieved, the semantic pseudo-gradient signal obtained by analyzing the historical scene data is fused with the general task strategy, and the current task cue word is optimized according to the fused semantic pseudo-gradient signal. According to the method, the cue word automatic directional evolution based on memory retrieval and a semantic back propagation mechanism is realized, the guidance of a cross-task general rule is taken into account while accurate repair for a specific failure task is ensured, and the pertinence and stability of cue word optimization and the cross-task generalization ability are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method, apparatus, electronic device, and storage medium for optimizing prompt words. Background Technology

[0002] With the widespread application of large language models in task planning, code generation, and complex decision-making, prompt words, as the core input driving model behavior, directly determine the accuracy and reliability of the model's output. Therefore, how to automatically optimize prompt words in multi-task scenarios to continuously improve the reasoning and decision-making performance of intelligent agent systems has become an urgent problem to be solved. Existing prompt word optimization techniques typically employ experience replay based on external memory or semantic feedback methods based on large language models. Specifically, when the model fails or outputs poorly in the current task, existing techniques mainly rely on single-step semantic feedback instructions to directly repair and replace the current prompt word text, hoping to obtain better output results in the next execution.

[0003] However, most current prompt optimization mechanisms are single-step and isolated feedback adjustments. When faced with the failure of the current task, they can only make partial repairs to the current local error, which makes the prompt updates prone to getting stuck in local optima and makes it difficult to achieve stable and automated evolution with cross-task generalization capabilities. Summary of the Invention

[0004] This invention provides a prompt word optimization method, apparatus, electronic device, and storage medium to address the shortcomings of existing prompt word optimization mechanisms, which can only partially repair local errors, leading to prompt word updates easily getting stuck in local optima and making it difficult to achieve stable and cross-task generalized automated evolution.

[0005] This invention provides a method for optimizing prompt words, including: Extract the case feature vector of the currently failed task; Historical scenario data matching the feature vector of the case are retrieved from the scenario memory database; Based on the historical context data, a semantic pseudo-gradient signal is obtained through mapping. The semantic pseudo-gradient signal and the general task strategy generated based on the context memory are fused to obtain the fused pseudo-gradient signal. Based on the fused pseudo-gradient signal, the current task prompt word of the current failed task is optimized to obtain the optimized prompt word.

[0006] According to the prompt word optimization method provided by the present invention, the historical context data includes historical similar cases, high-frequency error patterns, and transferable strategies; The process of mapping semantic pseudo-gradient signals based on the historical context data includes: Align the execution trajectory of the currently failed task with the historical similar cases to obtain local anomaly decision points; Based on the high-frequency error pattern, the error attribution verification is performed on the local abnormal decision points, and the structural defects of the prompt words are located by referring to the transferable strategy, and reflective structural information is generated. Perform semantic analysis on the aforementioned reflective structural information and output linguistic feedback results; The language feedback result is subjected to semantic parameter mapping processing to generate the semantic pseudo-gradient signal; the semantic pseudo-gradient signal includes numerical adjustment amount and / or logical rule instruction.

[0007] According to the prompt word optimization method provided by the present invention, the case feature vector includes the current task vector, the intermediate inference vector, and the execution result vector; The process of retrieving historical context data that matches the case feature vector from the context memory database includes: Retrieve historical similar cases that match the current task vector from the context memory database; Based on the current task vector and the execution result vector, the high-frequency error pattern is retrieved from the context memory. Based on the current task vector and the intermediate inference vector, the transferable strategy is retrieved from the context memory.

[0008] According to a prompt word optimization method provided by the present invention, the generation step of the general task strategy includes: Extract multiple historical scenario cases from the aforementioned scenario memory bank; Semantic clustering was performed on the multiple historical scenario cases to obtain the case clustering results; Extract the cross-task general patterns from the clustering results of the cases, and generate the general task strategy.

[0009] According to a prompt word optimization method provided by the present invention, the step of optimizing the current task prompt word of the currently failed task based on the fused pseudo-gradient signal to obtain optimized prompt words includes: Based on the large language model and following the indication of the fused pseudo-gradient signal, an optimization operation is performed on the current task prompt word to obtain the optimized prompt word; The optimization operations include at least one of the following: increasing or decreasing the activation weight of any instruction by a preset step size coefficient, rearranging the order of constraints in the context, and inserting a task label for the current error type.

[0010] According to a prompt word optimization method provided by the present invention, the current task prompt word of the currently failed task is optimized based on the fused pseudo-gradient signal to obtain an optimized prompt word, and then the method includes: Obtain the optimization feedback results after executing the currently failed task using the optimization suggestion words; Based on the optimization feedback results, the current optimization strategy is adjusted to obtain the next optimization strategy; The current optimization strategy includes current optimization parameters and current meta-hints; the current optimization parameters are used to control the running parameters of each execution stage during the hint word optimization process; The current meta-hint refers to the hint word used to generate the optimized hint word.

[0011] The present invention also provides a prompt word optimization device, comprising: Extraction unit: Extracts the feature vector of the current failed task. The matching unit retrieves historical scenario data that matches the feature vector of the case from the scenario memory database; The mapping unit maps the historical scenario data to obtain a semantic pseudo-gradient signal. The fusion unit fuses the semantic pseudo-gradient signal and the general task strategy generated based on the context memory bank to obtain a fused pseudo-gradient signal. The optimization unit optimizes the current task prompt word of the currently failed task based on the fused pseudo gradient signal to obtain the optimized prompt word.

[0012] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the prompt word optimization method as described above.

[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the prompt word optimization method as described above.

[0014] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the prompt word optimization method as described above.

[0015] The prompt word optimization method, apparatus, electronic device, and storage medium provided by this invention extract case feature vectors of the current failed task and retrieve matching historical context data. The semantic pseudo-gradient signal obtained by analyzing the historical context data is fused with a general task strategy generated based on a context memory bank, and the prompt words for the current task are optimized accordingly. This achieves automated and directional evolution of prompt words based on memory retrieval and semantic backpropagation mechanisms. While ensuring accurate repair for specific failed tasks, it also takes into account the guidance of general rules, significantly improving the targeting, stability, and cross-task generalization ability of prompt word optimization. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0017] Figure 1 This is a flowchart illustrating the prompt word optimization method provided by the present invention; Figure 2 This is a schematic diagram of the method for obtaining semantic pseudo-gradient signals by mapping provided by the present invention; Figure 3 This is a schematic diagram of the prompt word optimization device provided by the present invention; Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0019] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.

[0020] To address the aforementioned issues, this invention provides a method for optimizing prompt words across different task scenarios. Figure 1 This is a flowchart illustrating the prompt word optimization method provided by the present invention, as follows: Figure 1 As shown, the method includes: Step 110: Extract the case feature vector of the current failed task.

[0021] Here, the currently failed task refers to a task in which the agent, guided by the current task prompt, fails to achieve the expected goal or outputs abnormally due to inference bias, constraint conflict, or abnormal decision-making. The case feature vector is a vectorized representation obtained by structuring and quantifying the input data, model output, complete inference trajectory, and external feedback information during the execution of the currently failed task. It is used to represent the overall picture of this failed task in a multi-dimensional feature space.

[0022] Specifically, this can be achieved by collecting and recording work segments in real time during task execution, such as intermediate inference chains, local abnormal states, and related contextual information. When it is detected that the task fails to output the correct result or receives external error feedback after execution, the original input, error output, and work segments of the task can be extracted, and the above information can be transformed into case feature vectors that can be processed efficiently through a preset encoding model or semantic feature extraction algorithm.

[0023] Step 120: Retrieve historical scenario data that matches the feature vector of the case from the scenario memory bank.

[0024] Here, the contextual memory bank refers to a pre-constructed hierarchical memory map used to record the complete task execution trajectory. Similar to a mistake notebook, it can be used to record the input, output, reasoning chain, and error analysis feedback of historical tasks. Furthermore, the historical contextual data here refers to past task records and related experience data stored in the contextual memory bank that have a high degree of similarity or correlation with the current failed task in terms of feature dimensions.

[0025] Specifically, the extracted case feature vectors can be used to perform vector similarity matching or semantic alignment retrieval in the context memory. For example, by setting a similarity threshold or selecting top-ranked search results, historical error cases similar to the current task context, frequently occurring error patterns, and previously successfully corrected transferable strategies can be recalled. Understandably, this recalled comprehensive data constitutes historical context data, providing rich experience to support subsequent reflection and strategy adjustments.

[0026] Step 130: Based on the historical scenario data, a semantic pseudo-gradient signal is mapped to obtain the signal.

[0027] Here, the semantic pseudo-gradient signal refers to a control instruction generated through natural language processing and structured mapping, which indicates the direction and magnitude of cue word updates. It should be noted that the semantic pseudo-gradient signal is similar to the backpropagation gradient in neural network training, but it operates at the discrete linguistic and semantic levels, guiding targeted modifications to the textual cue words.

[0028] Specifically, firstly, reflective structural information about the current failed task can be generated by aligning, comparing, and summarizing historical contextual data. Then, the critical reasoning capabilities of a large language model can be used to self-criticize and cross-validate this reflective structural information to pinpoint the key reasons for the current failure, such as specific structural flaws in the cue words or strategy selection biases. Finally, a linguistic feedback result containing error localization and optimization suggestions can be output.

[0029] Furthermore, the natural language feedback can be parsed and mapped using a semantic parser, converting it into an executable semantic pseudo-gradient signal. This semantic pseudo-gradient signal can specifically represent an indication of the adjustment amount of the prompt module weights, or a rule for modifying the constraints of the prompt words.

[0030] It should be noted that the fuzzy reflections and criticisms at the language level based on historical contextual data are mapped into calculable and executable semantic pseudo-gradient signals, realizing semantic-level optimization capabilities similar to backpropagation in neural networks, so as to achieve the evolution of prompt words without parameter adjustment.

[0031] Step 140: The semantic pseudo-gradient signal and the general task strategy generated based on the context memory are fused to obtain the fused pseudo-gradient signal.

[0032] Here, the general task strategy refers to the prompt word optimization rules or template rules that are universally applicable and reusable, summarized after high-level semantic processing and pattern extraction of a large number of cross-task historical cases in the context memory bank. Here, the fusion of pseudo-gradient signals is a comprehensive prompt word update basis formed by combining specific correction instructions for the current failed task with macro-general rules across tasks.

[0033] Specifically, multiple historical units in the context memory bank can be clustered and policy factors extracted to refine a general task policy that can be reused across tasks, which can be considered as policy memory. Subsequently, according to preset fusion weights or logical aggregation rules, the currently generated semantic pseudo-gradient signal that is only for this failure can be superimposed or logically fused with the above-mentioned general task policy to obtain a fused pseudo-gradient signal.

[0034] It should be noted that guiding gradient fusion through historical strategy memory effectively avoids getting stuck in local optima or causing excessive expansion of prompt instructions when optimizing prompt words, significantly improving the stability and generalization of strategy updates. In other words, it retains the ability to correct local errors while introducing general guidance from a global perspective.

[0035] Step 150: Based on the fused pseudo-gradient signal, optimize the current task prompt word of the current failed task to obtain the optimized prompt word.

[0036] Here, "optimized prompt words" refers to a new generation of prompt word templates generated based on the current task prompt words, after incorporating adjustment instructions from the fused pseudo-gradient signal. These prompt words correct existing logical flaws or missing constraints and are used in the next round of task execution.

[0037] Specifically, the fused pseudo-gradient signal and the current task prompt can be added to the prompt template used for optimization. The added prompt is then input into a large language model, which performs structured updates to the current task prompt based on the specific indications of the fused pseudo-gradient signal. For example, it can dynamically enable or disable certain inference modules, adjust instruction weights and execution order, or rearrange the constraint structure in the context, based on the adjustment step size and direction in the pseudo-gradient signal. This ultimately generates optimized prompts with a more rigorous structure and more complete logic.

[0038] It should be noted that the current task prompt word can be obtained by retrieving the current prompt word template and historical similar cases with semantically similar meanings to the current failed task. The historical similar cases and the currently failed task to be executed are then added to the current prompt word template to obtain the current task prompt word used to execute the current failed task. In essence, the task to be executed is completed based on the current prompt word template and the retrieved historical similar cases, thus achieving initial optimization of the current prompt word template.

[0039] The method provided in this invention extracts the case feature vector of the current failed task and retrieves matching historical scenario data. It then fuses the semantic pseudo-gradient signal obtained from analyzing the historical scenario data with a general task strategy generated based on a scenario memory bank, and uses this to optimize the prompt words for the current task. This achieves automated and directional evolution of prompt words based on memory retrieval and semantic backpropagation mechanisms. While ensuring accurate repair for specific failed tasks, it also takes into account the guidance of general rules, significantly improving the targeting, stability, and cross-task generalization ability of prompt word optimization.

[0040] Based on any of the above embodiments, historical scenario data includes historical similar cases, high-frequency error patterns, and transferable strategies.

[0041] Here, historical context data specifically includes historical similar cases, high-frequency error patterns, and transferable strategies. Historical similar cases refer to past task records that have a high degree of similarity to the current failed task in terms of task objectives, semantic context, or input features. High-frequency error patterns refer to common patterns and pitfalls that repeatedly occur in multiple historical tasks, leading to model inference bias or output errors. Furthermore, transferable strategies refer to cue word adjustment rules extracted from past successful tasks or optimization experience that can transcend specific task boundaries and have universal applicability.

[0042] Figure 2 This is a schematic diagram of the method for obtaining semantic pseudo-gradient signals through mapping provided by the present invention, as shown below. Figure 2 As shown, the method includes: Step 210: Align the execution trajectory of the currently failed task with the historical similar cases to obtain local anomaly decision points.

[0043] Here, the execution trajectory refers to the complete flow of the currently failed task from input to final output, encompassing information such as intermediate inference chains, candidate inference branches, and local states. Here, reflective structural information refers to a structured and organized error analysis report data formed after multi-dimensional comparison and systematic summarization.

[0044] Specifically, the complete execution trajectory of the current failed task can be aligned and compared with the retrieved historical similar cases one by one in terms of input data, inference nodes, and output results to obtain the current local anomaly decision point.

[0045] Step 220: Based on the high-frequency error pattern, the local abnormal decision point is subjected to error attribution verification, and the local abnormal decision point is located for cue word structure defects by referring to the transferable strategy, and reflective structure information is generated.

[0046] Specifically, based on multidimensional alignment, high-frequency error patterns can be combined to verify the attribution of errors at current local anomaly decision points, allowing for in-depth analysis of whether the failure is caused by a jump in factual knowledge or a break in the logical chain. Simultaneously, a transferable strategy can be used to systematically review the current task prompts, locating structural defects in the prompts and identifying which contextual constraints were not effectively activated or caused mutual interference. Finally, the obtained local anomaly decision points, along with the attribution verification results and the prompt structural defect location results, are summarized to generate a reflective structural information document containing key reasons for task failure and the structural features of prompts that lead to reasoning biases.

[0047] Understandably, fault attribution verification refers to the process of confirming whether the core reason for the failure of this task matches known common error patterns. Here, fault code structural defect localization refers to identifying structural weaknesses in the current task fault codes, such as logical gaps, constraint conflicts, or improper weighting.

[0048] It should be noted that through multi-dimensional alignment, attribution verification, and prompt word defect localization, the root causes of the current task failure can be deeply explored, and the generated reflection structure information provides a comprehensive and rigorous structured factual basis for the subsequent accurate feedback generation.

[0049] Step 230: Perform semantic analysis on the reflection structure information and output the language feedback results.

[0050] Here, language feedback results refer to text content presented in natural language that includes self-criticism, error identification, and specific optimization suggestions.

[0051] Specifically, the generated reflective structural information can be input into a large language model as context. Leveraging the powerful critical reasoning capabilities of the large language model, this reflective structural information can undergo linguistic self-criticism and semantic analysis. It should be noted that the large language model can be used to deeply interpret the constraint conflicts identified in the report, deduce their impact on the final result, and output a natural language paragraph containing detailed attributions of decision biases and specific optimization suggestions. This natural language paragraph constitutes the language feedback result.

[0052] It should be noted here that semantic analysis of reflective structural information based on the large language model fully leverages the deep logical reasoning and critical capabilities of the large language model, transforming rigid structured error features into highly interpretable and instructive language feedback results, thus building a smooth semantic bridge for the quantitative mapping of subsequent instructions.

[0053] Step 240: Perform semantic parameter mapping processing on the language feedback result to generate the semantic pseudo-gradient signal.

[0054] The semantic pseudo-gradient signal includes numerical adjustment amounts and / or logical rule instructions.

[0055] Here, the numerical adjustment amount refers to the specific increase or decrease coefficient for the weight of a specific module or instruction in the prompt. Here, the logical rule instruction refers to the control command for structured operations such as rearranging the order of instructions in the prompt, enabling or disabling specific inference modules.

[0056] Specifically, after obtaining language feedback results at the natural language level, these feedback texts can be parsed using a built-in semantic parser to extract key optimization actions and perform semantic parameter mapping processing. It should be noted that this process can be considered as forcibly converting optimization suggestions in natural language form into semantic pseudo-gradient signals that can be executed by the algorithm. Specifically, if the language feedback result indicates "the need to strengthen constraints on specific industry terms," ​​after mapping, the pseudo-gradient signal can be concretized into a numerical adjustment amount, such as instructing to increase the activation weight of the domain knowledge constraint module by a preset step size coefficient; if the feedback indicates "the inference steps are reversed, leading to an error," the pseudo-gradient signal can be concretized into a logical rule instruction, instructing to reverse the hierarchical order of the context constraints. It is understood that the semantic pseudo-gradient signal includes at least one of numerical adjustment amounts and logical rule instructions, which can be determined based on the actual language feedback result.

[0057] It should also be noted that by performing semantic parameter mapping on the language feedback results, a semantic pseudo-gradient signal is generated, achieving a key leap from natural language feedback to executable control instructions. This enables the originally vague semantic optimization suggestions to be accurately expressed in numerical or rule-based form, ensuring the computability and controllability of modifying the prompt word template.

[0058] The method provided in this invention aligns the execution trajectory of the current failed task with similar historical cases to obtain local anomaly decision points. It then analyzes these local anomaly decision points using high-frequency error patterns and transferable strategies to generate reflective structural information. Semantic analysis of this reflective structural information is then performed to output language feedback results. Finally, semantic parameter mapping is used to generate a semantic pseudo-gradient signal containing numerical adjustment amounts and / or logical rule instructions. This method accurately transforms complex, multi-dimensional task failure attribution and natural language reflection into executable and quantifiable prompt word update instructions. It effectively overcomes the limitations of reflection from a single task perspective, significantly reduces invalid prompt word trial and error, and significantly improves the accuracy, objectivity, and practical guiding significance of semantic pseudo-gradient signal generation for prompt word optimization.

[0059] Based on any of the above embodiments, the case feature vector includes the current task vector, the intermediate inference vector, and the execution result vector.

[0060] Here, the current task vector refers to the vector representation obtained by semantically encoding the original input text, system preset instructions, and task intent of the currently failed task, used to represent the initial state and core objective of the task. The intermediate inference vector refers to the vector representation obtained by encoding the thought processes, candidate decision branches, and local temporary states generated by the agent during task execution, used to represent the dynamic deduction process of the task. The execution result vector refers to the vector representation obtained by encoding the final output text, external feedback evaluation, and the specific error types marked, used to represent the final appearance and conclusion of the task failure.

[0061] Step 120 includes: Retrieve historical similar cases that match the current task vector from the context memory database; Based on the current task vector and the execution result vector, the high-frequency error pattern is retrieved from the context memory. Based on the current task vector and the intermediate inference vector, the transferable strategy is retrieved from the context memory.

[0062] It should be noted that the execution order of obtaining historical similar cases, high-frequency error patterns, and transferable strategies can be either parallel or sequential.

[0063] Specifically, for historical similar cases, the current task vector, representing the initial input state of the task, can be used as the core search term to perform semantic alignment and vector similarity calculation in the context memory. Then, historical cases with similarity greater than a preset threshold can be used as historical similar cases for the current failed task. This filters out past records that are highly semantically similar to the current task in terms of task objectives, domain background, and original input information. For example, if the current task is "extracting breach of contract clauses from medical contracts," then historical similar cases from previous processing of other medical texts or legal contracts will be recalled.

[0064] To identify high-frequency error patterns, the current task vector representing the task objective and the execution result vector representing the failed conclusion can be combined to form a two-dimensional joint query condition. This allows for the retrieval of historical trajectories from the context memory that produced similar erroneous results under similar task backgrounds. Furthermore, common defect labels summarized by the system from these trajectories can be extracted and recalled, thus identifying the high-frequency error pattern. For example, if multiple out-of-bounds errors occur in a mathematical reasoning task, the corresponding high-frequency error pattern can be recalled.

[0065] To determine transferable strategies, the current task vector representing the task objective can be combined with the intermediate reasoning vector representing the micro-deduction process. Similar reasoning paths and decision nodes can be deeply searched in the context memory bank. When it is found that a historical task successfully escaped a similar logical branch or a similar reasoning dilemma by calling certain specific prompt correction rules, these methods that have been verified as effective will be recalled as transferable strategies for the current failed task.

[0066] The method provided in this invention refines the case feature vector into a current task vector, an intermediate inference vector, and an execution result vector. It then uses the current task vector to match historical similar cases, combines the execution result vector to retrieve high-frequency error patterns, and combines the intermediate inference vector to retrieve transferable strategies. This enables multi-dimensional targeted retrieval from macro-level task intent, micro-level reasoning process to final execution appearance. It effectively avoids the problems of fuzzy experience matching or missing key clues caused by single coarse-grained vector retrieval, and significantly improves the richness, accuracy, and relevance of historical experience data retrieval in the context memory bank.

[0067] Based on any of the above embodiments, the steps for generating a general task strategy include: Extract multiple historical scenario cases from the aforementioned scenario memory bank; Semantic clustering was performed on the multiple historical scenario cases to obtain the case clustering results; Extract the cross-task general patterns from the clustering results of the cases, and generate the general task strategy.

[0068] Specifically, firstly, multiple historical scenario cases within a preset time period or reaching a certain threshold can be retrieved in batches from the scenario memory bank. Here, multiple historical scenario cases refer to the collection of historical execution records accumulated in the scenario memory bank, spanning different times and different task types. These typically include scenario units that are integrated and encapsulated, such as input data, model output, complete inference trajectories, and external feedback information for each task.

[0069] It should be noted that these multiple historical scenario cases can span different application fields, such as code generation, text summarization, or logical reasoning. They are collectively extracted as the original material library for subsequent extraction of macro-level patterns, providing rich and diverse underlying data support for subsequent strategy refinement, and ensuring that the pattern extraction process is not limited to the limitations of a single task perspective.

[0070] Then, semantic clustering is performed on multiple historical scenario cases to obtain case clustering results. Here, case clustering results refer to several case clusters with highly similar internal characteristics formed after the clustering operation. Specifically, the extracted historical scenario cases can first be converted into high-dimensional semantic feature vectors, and then clustering algorithms are applied to process these vectors and merge them with similar cases to obtain case clustering results. This allows cases with similar error types or common execution characteristics that were originally scattered across different tasks to be aggregated together, forming clear case clustering results. For example, failure cases caused by conflicting prompt word constraints under different business backgrounds can be automatically clustered into the same cluster.

[0071] Next, the cross-task general rules of the case clustering results are extracted to generate a general task strategy. Here, the cross-task general rules refer to the underlying prompt word construction principles or strategy factors abstracted from specific clusters and stripped of specific business scenario attributes. Here, the general task strategy is a standardized prompt word optimization template or correction rule transformed from these cross-task general rules, which can be reused in multiple scenarios and can be called strategy memory.

[0072] Specifically, feature summarization and strategy factor extraction can be performed on the data within each case cluster result. For example, batch reflective analysis using a large language model can identify common missing prompt structures or applicable correction paths among cases within a cluster. Subsequently, these patterns are abstracted and refined into cross-task general rules, and then encapsulated to generate general task strategies. For instance, the rule that tasks involving multi-step complex decision-making require supplementing thought chain verification instructions in prompts can be extracted and solidified into a general optimization strategy to guide the generation of prompts for various subsequent new tasks.

[0073] It should be noted that by extracting the cross-task general rules from the case clustering results, a general task strategy is generated, which realizes the sublimation from individual fragmented experience to global generalization, enabling the acquisition of underlying optimization logic that transcends the boundaries of specific tasks, and endowing it with the ability to generalize across tasks and continuously improve itself.

[0074] The method provided in this invention extracts multiple historical scenario cases from a contextual memory bank and performs semantic clustering to obtain case clustering results. Then, it extracts the cross-task general rules of the case clustering results to generate general task strategies. This achieves the automatic extraction of global prompt word optimization principles from massive and scattered historical execution trajectories, effectively breaking down the experience barriers between different tasks, establishing a strategy memory system that can be reused across tasks, and significantly improving the strategy generalization ability and self-evolution efficiency when facing cross-domain tasks.

[0075] Based on any of the above embodiments, step 150 includes: Based on the large language model and following the indication of the fused pseudo-gradient signal, an optimization operation is performed on the current task prompt word to obtain the optimized prompt word; The optimization operations include at least one of the following: increasing or decreasing the activation weight of any instruction by a preset step size coefficient, rearranging the order of constraints in the context, and inserting a task label for the current error type.

[0076] Specifically, the current task prompt, the fused pseudo-gradient signal, and the optimized instruction template can be input into a large language model. The large language model first parses the semantic indications in the fused pseudo-gradient signal to identify the implicit correction direction, such as whether it is necessary to strengthen the constraints of a certain logic module or adjust the output format of the instruction. Subsequently, guided by these signals, the large language model rewrites or adjusts the original text, logical structure, or parameter configuration of the current task prompt, and finally outputs the optimized prompt.

[0077] It should be noted that in this step, the large language model is not only the executor of the task, but also acts as a meta-optimizer of the prompt words. By leveraging its powerful instruction-following and text generation capabilities, it transforms the abstract gradient signals into specific text modification actions, realizing an automated closed loop for prompt word optimization and significantly improving the intelligence level of the optimization process.

[0078] Additionally, the optimization operations during this step include at least one of the following: increasing or decreasing the activation weights of arbitrary instructions by a preset step size, rearranging the order of constraints in the context, and inserting task labels for the current error type. In specific implementation, the activation weights of arbitrary instructions can be increased or decreased by a preset step size based on the quantization indication of the fused pseudo-gradient signal. For example, weights can be increased by adding strong prompts such as "extremely important" or "priority focus" before the instruction, or decreased by softening the tone. Simultaneously, considering the sensitivity of large language models to the order of prompts, the order of constraints in the context can be rearranged, moving previously ignored key constraints to more prominent positions. Furthermore, task labels for the current error type can be inserted, such as marking this failure as a logical illusion or a formatting error, and writing these labels into the task definition part of the prompt words to trigger specific reflection mechanisms in the model.

[0079] The preset step size coefficient refers to the quantitative adjustment unit set to ensure the stability of the optimization process. It is used to control the magnitude of each weight change and prevent drastic oscillations in the prompt strategy. The instruction activation weight refers to changing the degree of attention the large language model pays to specific instruction parts in the prompt words through linguistic embellishment or explicit emphasis. The order of constraints refers to the physical position of each restrictive requirement in the prompt words; large language models are usually more sensitive to the beginning and end positions in the context. Additionally, the task label refers to the meta-information that annotates the error category to which the current task belongs.

[0080] It should be noted that by providing multi-dimensional optimization methods from numerical weights and logical structures to classification labels, the optimization of prompt words is no longer limited to simple text repair, but delves into the underlying allocation rules of attention and logical weights in large language models, greatly improving the accuracy of prompt words in driving the behavior of large language models.

[0081] The method provided in this invention performs optimization operations on the current task prompt word based on a large language model and according to the indication of the fused pseudo-gradient signal. These operations include increasing or decreasing the activation weight of the instruction block by a preset step size coefficient, rearranging the order of constraints, and inserting erroneous task labels. This results in optimized prompt words, which realizes the transformation of semantic reflection suggestions into quantifiable and operable structured prompt word update actions. While ensuring the accuracy of the prompt word evolution direction, it overcomes the shortcomings of traditional prompt engineering, such as the single optimization method and difficulty in dealing with complex reasoning biases, through multi-dimensional fine-tuning methods. This significantly enhances the adaptability of prompt words to complex tasks.

[0082] Based on any of the above embodiments, after step 150, the following is included: Obtain the optimization feedback results after executing the currently failed task using the optimization suggestion words; Based on the optimization feedback results, the current optimization strategy is adjusted to obtain the next optimization strategy; The current optimization strategy includes current optimization parameters and current meta-hints; the current optimization parameters are used to control the running parameters of each execution stage during the hint word optimization process; The current meta-hint refers to the hint word used to generate the optimized hint word.

[0083] It should be noted that after obtaining the current round of optimization suggestions, in order to ensure continuous self-evolution, the process of optimizing the suggestions itself needs to be evaluated and further optimized. Specifically, firstly, the optimization feedback results after using the optimized suggestions to execute the currently failed task can be obtained. Here, the optimization feedback results refer to the actual performance evaluation data obtained after re-executing the previously failed target task using the newly generated optimized suggestions. This optimization feedback result can include whether the task was successfully completed, the improvement in accuracy, the stability index of the model output, and the final score given by the user or external environment.

[0084] In one embodiment, the agent can be driven to load the currently generated optimized prompt words and re-infer and execute the original input of the currently failed task. After execution, the output result can be evaluated by the adaptive meta-optimizer inside the agent, and the actual effect can be compared with the expected goal. The optimization feedback result is quantified, providing objective factual basis for measuring whether the current prompt word update based on the fused pseudo-gradient signal is truly effective. It can also promptly detect prompt word inflation or policy oscillation problems caused by over-optimization.

[0085] Then, based on the optimization feedback results, the current optimization strategy is adjusted to obtain the next optimization strategy. The current optimization strategy includes the current optimization parameters and the current meta-hints; the current optimization parameters are used to control the running parameters of each execution stage during the hint optimization process; the current meta-hints refer to the hint words used to generate the optimized hint words.

[0086] Here, the current optimization strategy refers to the control logic currently guiding the entire prompt optimization process. The current optimization parameters are the hyperparameters relied upon in each stage, such as retrieval, pseudo-gradient generation, and fusion, including prompt update step size, reflective retrieval scope, strategy memory acceptance weights, and pseudo-gradient generation rules. The current meta-prompt refers to the highest-level instruction text received by the large language model when acting as the optimizer, such as "prompt words for optimizing prompt words." The next optimization strategy, after evaluation and dynamic correction, is the next generation of control logic used to regulate the operation of the overall process in the next round.

[0087] In its implementation, secondary reflection can be performed based on the collected optimization feedback. That is, if the feedback indicates that the current optimization has led to a local optimum or is ineffective, the current optimization parameters will be automatically adjusted. For example, the update step size may be reduced to mitigate the adjustment, or the reflection retrieval scope may be expanded to incorporate more historical scenario data. Simultaneously, the current meta-hints themselves can be dynamically modified, such as by altering the guidance logic within the meta-hints regarding "how to analyze structural defects." Thus, through the comprehensive adjustment of these hyperparameters and meta-instructions, the next optimization strategy, which will guide future optimization tasks, is ultimately generated.

[0088] Understandably, by dynamically adjusting the optimization strategy itself, a full-link self-learning process is achieved, from local prompt word correction to the evolution of the top-level meta-strategy, thus avoiding being trapped in a fixed optimization paradigm for a long time.

[0089] The method provided in this invention obtains the optimization feedback result after executing the current failed task using the optimized prompt words, and adjusts the current optimization strategy containing the current optimization parameters and the current meta-prompt based on the optimization feedback result to obtain the next optimization strategy. This achieves adaptive evolution, which can not only optimize the underlying prompt words of specific tasks, but also dynamically correct the operation mechanism of the optimization process itself by evaluating the actual effect. This significantly improves the continuous evolution capability and long-term stability of the entire prompt word optimization method when facing complex and ever-changing tasks.

[0090] Based on any of the above embodiments, the present invention also provides a prompt word optimization method based on memory and backpropagation, the method comprising: First, perform the target task and simultaneously collect working memory fragments.

[0091] Specifically, guided by the current prompt word template and retrieved historical similar cases, the current target task is executed. During task execution, intermediate reasoning chains, candidate reasoning tree branches, local abnormal decision points, abnormal decision behaviors, temporary states, and reasoning contexts are collected and recorded in real time to form structured working memory fragments, which serve as the raw input for subsequent reflection and analysis.

[0092] Then, the task execution trajectory is encapsulated as a contextual memory unit.

[0093] Specifically, if the execution result of the current target task is abnormal, the current target task is marked as a failed task. After the current target task is completed, the input data, model output, complete inference trajectory, and external feedback information are integrated and encapsulated into a context memory unit. This context memory unit is stored in the context memory bank, and cases containing failures or deviations are specially marked and written into an error notebook to support subsequent cross-case reflection and pattern recognition.

[0094] Next, multi-case structured reflection is performed based on memory retrieval.

[0095] Specifically, the reflection-retrieval enhancement generation module can be invoked to retrieve historical similar cases, high-frequency error patterns, and transferable success strategies that are semantically similar to the current failed task from the context memory database, thus obtaining historical context data. Then, multiple related cases are aligned, compared, and summarized to generate a structured reflection report, i.e., generating reflection structure information. Here, the structured reflection report includes cross-task common error patterns, key reasons for task failure, and cue word structural features most likely to lead to reasoning bias.

[0096] Furthermore, a semantic pseudo-gradient is generated to guide the adjustment of cue words.

[0097] Specifically, a large language model can be used to perform linguistic self-criticism or cross-validation on the structured reflection report, outputting natural language feedback that includes error localization, constraint conflict analysis, decision bias attribution, and executable optimization suggestions—that is, outputting the language feedback results. Subsequently, a semantic parser transforms the natural language feedback into semantic pseudo-gradient signals. Here, the semantic pseudo-gradient signals are expressed in numerical or rule-based form, specifically including: the adjustment amount of the prompt module weights, the direction of correction of the instruction order and hierarchy, the degree of enhancement or weakening of domain knowledge constraints, and the instructions for enabling or disabling new policy modules. It can be understood that by mapping to obtain semantic pseudo-gradient signals, policy evolution can be driven through language feedback without parameter adjustment.

[0098] Next, we extract and integrate cross-task strategy memories.

[0099] Specifically, high-level semantic processing can be performed on multiple contextual memory units, including semantic clustering, similar case merging, and strategy factor extraction, to extract cross-task reusable prompt optimization rules, i.e., cross-task general rules. Then, a general task strategy, i.e., strategy memory, is generated through these cross-task reusable prompt optimization rules. Here, contextual memory units can refer to historical contextual cases. Furthermore, the strategy memory can be fused with the currently generated semantic pseudo-gradient signal to jointly constitute the comprehensive basis for the next round of prompt updates, i.e., the fused pseudo-gradient signal. It should be noted that using strategy memory to achieve the transfer and reuse of prompt updates significantly improves generalization.

[0100] Then, perform a structured update of the prompt word template.

[0101] Specifically, based on the fused pseudo-gradient signal, the current prompt word template of the current task prompt word is structurally updated. The specific operations include: applying pseudo-gradient adjustment according to a preset step size coefficient, dynamically starting and stopping specific inference modules, adjusting instruction weights and execution order, inserting task-specific labels, and rearranging the context constraint structure. Finally, a new generation of prompt word templates is generated, that is, optimized prompt words are generated for the next round of task execution.

[0102] It should be noted that during the execution of the cue word optimization method based on memory and backpropagation, a hierarchical memory map consisting of three types of memory can be constructed: working memory, used to store short-term information such as intermediate inference chains and local states of the agent during task execution; contextual memory, which records the complete task trajectory in the form of a mistake notebook, including input, output, inference chain, error analysis feedback, etc., i.e., used to store historical context cases; and policy memory, used to extract cross-task universal cue templates, policy correction rules, and historical optimization experience, i.e., used to store general task policies. It should be noted that gradient fusion is guided by historical policy memory to avoid getting trapped in local optima or cue word inflation.

[0103] This allows for coordinated lifecycle management of working memory, episodic memory, and strategic memory. Specifically, this includes: promoting high-value episodic memories to strategic memories; downgrading outdated or inefficient strategic memories back to episodic memory levels; eliminating redundant, conflicting, or low-contribution memory entries; and automatically merging semantically similar memory units to maintain the simplicity, consistency, and scalability of the memory bank. The lifecycle management of memory access, fusion, promotion, and elimination can be assessed using novelty, consistency, and utility indicators. It should be noted that this involves constructing a unified and structured memory system to overcome the paradigmatic disconnect between traditional experience playback, external memory, or semantic feedback.

[0104] In addition, after obtaining optimized prompts, adaptive evolution of the driving meta-policy can be executed.

[0105] Specifically, the adaptive meta-optimizer can evaluate the actual effect of the current round of optimization prompts and automatically adjust the hyperparameters and strategies in the optimization process based on the actual effect, including the prompt update step size, the reflective retrieval range, the strategy memory acceptance weight, and the pseudo gradient generation rules; and generate new prompts for optimization prompts, i.e. meta-prompts, to regulate the operation of the next round of the overall process, thereby achieving system-level self-evolution capability.

[0106] It should be noted that the entire optimization process consists of three stages. Stage one is execution and immediate correction, where the agent completes the task based on the current prompt word and retrieved memory content, and immediately writes failed cases into the contextual memory. Stage two is batch reflection and strategy refinement, where aggregate analysis is performed on multiple task trajectories, and batch optimization instructions for the prompt words are generated through semantic backpropagation. Stage three is meta-optimization and system evolution, where the large language model performs secondary reflection, further optimizing the optimization strategy itself, dynamically correcting the meta-strategy of how to optimize the prompt words, and achieving self-evolution.

[0107] The method provided in this invention parameterizes the semantic feedback of the language model into a computable, superimposed, and combinable pseudo-gradient signal, and combines it with a hierarchical memory system and a meta-optimization mechanism to achieve controllable, efficient, and continuous self-evolution of prompt word templates. This is significantly better than traditional prompt engineering methods that rely on manual trial and error or loose text repair.

[0108] Based on any of the above embodiments Figure 3 This is a schematic diagram of the prompt word optimization device provided by the present invention, as shown below. Figure 3 As shown, the device includes: Extraction unit 310 extracts the case feature vector of the current failed task; Matching unit 320 retrieves historical scenario data that matches the case feature vector from the scenario memory database; Mapping unit 330 maps semantic pseudo-gradient signals based on the historical context data; The fusion unit 340 fuses the semantic pseudo-gradient signal and the general task strategy generated based on the context memory bank to obtain a fused pseudo-gradient signal. The optimization unit 350 optimizes the current task prompt word of the current failed task based on the fused pseudo gradient signal to obtain the optimized prompt word.

[0109] The apparatus provided in this invention extracts the case feature vector of the current failed task and retrieves matching historical scenario data. It then fuses the semantic pseudo-gradient signal obtained from analyzing the historical scenario data with a general task strategy generated based on a scenario memory bank, and uses this to optimize the prompt words for the current task. This achieves automated and directional evolution of prompt words based on memory retrieval and semantic backpropagation mechanisms. While ensuring accurate repair for specific failed tasks, it also takes into account the guidance of general rules, significantly improving the targeting, stability, and cross-task generalization ability of prompt word optimization.

[0110] Based on any of the above embodiments, the historical scenario data includes historical similar cases, high-frequency error patterns, and transferable strategies; The mapping unit is specifically used for: Align the execution trajectory of the currently failed task with the historical similar cases to obtain local anomaly decision points; Based on the high-frequency error pattern, the error attribution verification is performed on the local abnormal decision points, and the structural defects of the prompt words are located by referring to the transferable strategy, and reflective structural information is generated. Perform semantic analysis on the aforementioned reflective structural information and output linguistic feedback results; The language feedback result is subjected to semantic parameter mapping processing to generate the semantic pseudo-gradient signal; the semantic pseudo-gradient signal includes numerical adjustment amount and / or logical rule instruction.

[0111] Based on any of the above embodiments, the case feature vector includes the current task vector, the intermediate inference vector, and the execution result vector; The matching unit is specifically used for: Retrieve historical similar cases that match the current task vector from the context memory database; Based on the current task vector and the execution result vector, the high-frequency error pattern is retrieved from the context memory. Based on the current task vector and the intermediate inference vector, the transferable strategy is retrieved from the context memory.

[0112] Based on any of the above embodiments, the fusion unit is specifically used for: Extract multiple historical scenario cases from the aforementioned scenario memory bank; Semantic clustering was performed on the multiple historical scenario cases to obtain the case clustering results; Extract the cross-task general patterns from the clustering results of the cases, and generate the general task strategy.

[0113] Based on any of the above embodiments, the optimization unit is specifically used for: Based on the large language model and following the indication of the fused pseudo-gradient signal, an optimization operation is performed on the current task prompt word to obtain the optimized prompt word; The optimization operations include at least one of the following: increasing or decreasing the activation weight of any instruction by a preset step size coefficient, rearranging the order of constraints in the context, and inserting a task label for the current error type.

[0114] Based on any of the above embodiments, the optimization unit further includes a meta-optimization unit, which is specifically used for: Obtain the optimization feedback results after executing the currently failed task using the optimization suggestion words; Based on the optimization feedback results, the current optimization strategy is adjusted to obtain the next optimization strategy; The current optimization strategy includes current optimization parameters and current meta-hints; the current optimization parameters are used to control the running parameters of each execution stage during the hint word optimization process; The current meta-hint refers to the hint word used to generate the optimized hint word.

[0115] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4As shown, the electronic device may include a processor 410, a communication interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a prompt word optimization method. This method includes: extracting case feature vectors of the currently failed task; retrieving historical context data matching the case feature vectors from a context memory; mapping a semantic pseudo-gradient signal based on the historical context data; fusing the semantic pseudo-gradient signal with a general task strategy generated based on the context memory to obtain a fused pseudo-gradient signal; and optimizing the current task prompt word of the currently failed task based on the fused pseudo-gradient signal to obtain an optimized prompt word.

[0116] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0117] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the prompt word optimization method provided by the above methods. The method includes: extracting case feature vectors of the current failed task; retrieving historical context data matching the case feature vectors from a context memory; mapping a semantic pseudo-gradient signal based on the historical context data; fusing the semantic pseudo-gradient signal and a general task strategy generated based on the context memory to obtain a fused pseudo-gradient signal; and optimizing the current task prompt word of the current failed task based on the fused pseudo-gradient signal to obtain an optimized prompt word.

[0118] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the prompt word optimization method provided by the above methods. The method includes: extracting case feature vectors of a currently failed task; retrieving historical context data matching the case feature vectors from a context memory; mapping a semantic pseudo-gradient signal based on the historical context data; fusing the semantic pseudo-gradient signal with a general task strategy generated based on the context memory to obtain a fused pseudo-gradient signal; and optimizing the current task prompt word of the currently failed task based on the fused pseudo-gradient signal to obtain an optimized prompt word.

[0119] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0120] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0121] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for optimizing prompt words, characterized in that, include: Extract the case feature vector of the currently failed task; Historical scenario data matching the feature vector of the case are retrieved from the scenario memory database; Based on the historical context data, a semantic pseudo-gradient signal is obtained through mapping. The semantic pseudo-gradient signal and the general task strategy generated based on the context memory are fused to obtain the fused pseudo-gradient signal. Based on the fused pseudo-gradient signal, the current task prompt word of the current failed task is optimized to obtain the optimized prompt word.

2. The prompt word optimization method according to claim 1, characterized in that, The historical scenario data includes similar historical cases, high-frequency error patterns, and transferable strategies. The process of mapping semantic pseudo-gradient signals based on the historical context data includes: Align the execution trajectory of the currently failed task with the historical similar cases to obtain local anomaly decision points; Based on the high-frequency error pattern, the error attribution verification is performed on the local abnormal decision points, and the structural defects of the prompt words are located by referring to the transferable strategy, and reflective structural information is generated. Perform semantic analysis on the aforementioned reflective structural information and output linguistic feedback results; The language feedback result is subjected to semantic parameter mapping processing to generate the semantic pseudo-gradient signal; the semantic pseudo-gradient signal includes numerical adjustment amount and / or logical rule instruction.

3. The prompt word optimization method according to claim 2, characterized in that, The case feature vector includes the current task vector, intermediate inference vector, and execution result vector; The process of retrieving historical context data that matches the case feature vector from the context memory database includes: Retrieve historical similar cases that match the current task vector from the context memory database; Based on the current task vector and the execution result vector, the high-frequency error pattern is retrieved from the context memory. Based on the current task vector and the intermediate inference vector, the transferable strategy is retrieved from the context memory.

4. The prompt word optimization method according to any one of claims 1 to 3, characterized in that, The steps for generating the general task strategy include: Extract multiple historical scenario cases from the aforementioned scenario memory bank; Semantic clustering was performed on the multiple historical scenario cases to obtain the case clustering results; Extract the cross-task general patterns from the clustering results of the cases, and generate the general task strategy.

5. The prompt word optimization method according to any one of claims 1 to 3, characterized in that, The optimization of the current task prompt word for the currently failed task based on the fused pseudo-gradient signal to obtain the optimized prompt word includes: Based on the large language model and following the indication of the fused pseudo-gradient signal, an optimization operation is performed on the current task prompt word to obtain the optimized prompt word; The optimization operations include at least one of the following: increasing or decreasing the activation weight of any instruction by a preset step size coefficient, rearranging the order of constraints in the context, and inserting a task label for the current error type.

6. The prompt word optimization method according to any one of claims 1 to 3, characterized in that, The process of optimizing the current task prompt word for the currently failed task based on the fused pseudo-gradient signal to obtain an optimized prompt word includes: Obtain the optimization feedback results after executing the currently failed task using the optimization suggestion words; Based on the optimization feedback results, the current optimization strategy is adjusted to obtain the next optimization strategy; The current optimization strategy includes current optimization parameters and current meta-hints; the current optimization parameters are used to control the running parameters of each execution stage during the hint word optimization process; The current meta-hint refers to the hint word used to generate the optimized hint word.

7. A prompt word optimization device, characterized in that, include: Extraction unit: Extracts the feature vector of the current failed task. The matching unit retrieves historical scenario data that matches the feature vector of the case from the scenario memory database; The mapping unit maps the historical scenario data to obtain a semantic pseudo-gradient signal. The fusion unit fuses the semantic pseudo-gradient signal and the general task strategy generated based on the context memory bank to obtain a fused pseudo-gradient signal. The optimization unit optimizes the current task prompt word of the currently failed task based on the fused pseudo gradient signal to obtain the optimized prompt word.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the prompt word optimization method as described in any one of claims 1 to 6.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the prompt word optimization method as described in any one of claims 1 to 6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the prompt word optimization method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Reasoning optimization method and device for large model and medium

    CN119168067A

  • Large model cue word design method, system and equipment in industrial scene and medium

    CN120235125A

  • Large language model cue word automatic optimization method

    CN120542583A

  • Bayesian automatic cue word optimization method based on meta cue word

    CN120832540A

  • Semantic prompt automatic labeling method in building construction scene

    CN121053655A