A hint generation method based on a double-layer particle swarm algorithm
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SICHUAN TUOTUO DI SCI & TECH CO LTD
- Filing Date
- 2026-05-06
- Publication Date
- 2026-08-07
AI Technical Summary
[0003]现有的人工调整提示词方法高度依赖开发者的直觉与习惯,本质上是一种低效的经验主义,难以处理多变量的非线性协同效应,且存在严重的主观偏好与不可复现性
本发明提供的基于双层粒子群算法的提示生成方法,在实际应用中带来了显著的技术收益与工程价值:全局协同优化与稳定性提升:通过将指令、示例与任务描述参数化编码并进行群体演化,解决了离散空间下多维要素的非线性耦合寻优难题,显著降低了提示词对模型微小扰动的敏感性,增强了LLM在高精度业务场景下的输出鲁棒性;高效的信息积累与演化机制:利用主粒子作为“精英信息中心”动态积累优质基因分量,配合归一化概率采样与概率阈值过滤机制,算法能够快速锁定高质量搜索空间并过滤随机噪声,有效避免了传统搜索易陷入局部最优的问题;工程标准化与成本降低:实现了提示工程从人工试错向标准化自动流水线范式的转变,大幅降低了模型版本迭代或任务微调时的迁移与人工维护成本,确保在金融、医疗等复杂场景下能够持续获得最优指令支撑。
Smart Images

Figure CN122528889A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large language model prompting technology, specifically to a prompting generation method based on a two-layer particle swarm optimization algorithm. Background Technology
[0002] As the parameter scale of Large Language Models (LLMs) reaches the trillion-level threshold, their performance exhibits extremely high context sensitivity. Experiments show that even minor perturbations in prompts—such as the addition or deletion of a punctuation mark, subtle changes in the tone of the instruction, or the order of few-shot examples—often lead to drastic fluctuations in model output quality. This phenomenon is particularly pronounced when handling high-precision tasks such as logical reasoning and financial data analysis, making "prompt engineering" a key variable determining the model's effectiveness. However, current prompt optimization faces several severe challenges. First, the search space exhibits discreteness and combinatorial explosion characteristics. A mature prompt scheme typically consists of a coupling of "task instructions," "retrieved few-shot examples," and "thought chain guidance." If combinations are selected from dozens or hundreds of candidate examples, the space of permutations and combinations grows exponentially. Traditional manual trial and error is not only inefficient but also prone to getting trapped in local optima. Second, many closed-source models provide services via APIs, with their internal weights and gradient information completely closed to developers. This means that traditional gradient-based optimization algorithms fail for users, suggesting that optimization has completely evolved into a high-dimensional, nonlinear, and discrete optimization problem.
[0003] Existing methods for manually adjusting prompts rely heavily on developers' intuition and habits, which is essentially an inefficient form of empiricism. These methods struggle to handle the nonlinear synergistic effects of multiple variables and suffer from significant subjective bias and non-reproducibility. Methods that allow large models to generate prompts themselves are prone to falling into the trap of overly rapid semantic convergence and self-circulation. Their optimization paths are limited by the original training corpus, lacking the ability to achieve global breakthroughs beyond the existing logical framework.
[0004] Therefore, it is imperative to introduce heuristic search methods to seek the optimal combination of various elements of the project. Summary of the Invention
[0005] To overcome the aforementioned technical problems in existing technologies, this invention provides a prompt generation method based on a two-layer particle swarm optimization algorithm. By mapping discrete prompt elements to particle position vectors in a high-dimensional space, and utilizing the collective intelligence and collaborative evolution characteristics of the particle swarm, a global heuristic search is performed within an exponentially growing combination space. This overcomes the limitations of human experience and automatically mines the optimal prompt combination that produces high accuracy and good results, solving the problem of global collaborative optimization of multi-dimensional prompt elements in discrete space. Furthermore, in specific high-precision business scenarios (such as contract element extraction and financial analysis), by parameterizing and encoding three heterogeneous elements—"task description, few-sample examples, and thought chain logic"—the weight allocation of each element is dynamically adjusted during the evolution of the particle swarm. This enables the prompt engineering to move towards a standardized, automated pipeline paradigm, reducing the migration and maintenance costs for users between different models.
[0006] To achieve the above objectives, this invention provides a prompt generation method based on a two-layer particle swarm optimization algorithm, comprising the following steps: Step S1: Initialize algorithm parameters, including the maximum number of iterations, particle swarm size, inner layer update probability threshold, and outer layer reset probability threshold, and initialize a historical best fitness list and a historical best particle population list; Step S2: Construct a master particle, which includes a prompt word pool, a reference example pool, and a task description pool; Step S3: Generate a particle swarm from the master particle by random sampling, wherein each particle in the particle swarm includes a prompt word, a subset of reference examples, and a subset of task descriptions selected from the master particle; Step S4: For each particle, concatenate its three components into a complete prompt word, call a large language model on a validation dataset to obtain the model output, and determine the semantic consistency between the model output and the standard answer. Step S5: Calculate the fitness of each particle; Step S6: Determine the particle with the highest fitness in the current particle swarm as the optimal particle, generate a first random number, if the first random number is less than the inner layer update probability threshold, then store the fitness of the optimal particle in the historical optimal fitness list, store the optimal particle itself in the historical optimal particle population list, and incrementally add the hint words, reference example subset, and task description subset carried by the optimal particle to the corresponding pool of the main particle; Step S7: Generate a second random number, if the second random number is less than the outer layer reset probability threshold, then jump to step S2 to reconstruct the main particle; Step S8: Update the iteration count, if the maximum iteration count has not been reached, then jump to step S9, otherwise output the particle with the highest fitness from the historical optimal particle population list as the global optimal solution.
[0007] Preferably, the method for calculating particle fitness in step S4 is as follows: ,in, To verify the size of the dataset, For particles The corresponding model output, As the standard answer, This is a semantic consistency determination function. It returns 1 if the two are semantically consistent, and 0 otherwise.
[0008] Preferably, the inner layer update probability threshold in step S5 Dynamic adjustment using an exponential decay adaptive method: ,in, This represents the current iteration number. This represents the maximum number of iterations.
[0009] Preferably, the outer layer reset probability threshold in step S6 Dynamic adjustment using an exponential decay adaptive method: ,in, This represents the current iteration number. This represents the maximum number of iterations.
[0010] Preferably, the specific method for constructing the main particle in step S2 is as follows: the prompt word pool generates multiple different prompt words for the same task by adjusting the inference hyperparameters of the large language model; the reference example pool obtains multiple sets of input-output pairs by performing non-reset random sampling from the training dataset; the task description pool guides the large language model to observe and compare multiple samples in the training dataset, and the model autonomously summarizes and outputs multiple task deep feature descriptions.
[0011] Preferably, in step S3, the reference example subset and task description subset for each particle are selected from the corresponding pool of the main particle using random sampling without replacement, and the sampling between different particles is independent of each other.
[0012] Preferably, the semantic consistency determination function The implementation method is as follows: using a preset judgment prompt template, ask the large language model the question "Judging from the semantic level". "Is it consistent?" If the model returns "consistent", output 1; otherwise, output 0.
[0013] Preferably, in step S5, when the first random number is less than the inner layer update probability threshold, if the prompt word, reference example, or task description in the optimal particle is duplicated with an existing element in the main particle pool, then it is added repeatedly. Preferably, the particle swarm size, the number of reference examples per particle, and the number of task descriptions per particle are all preset hyperparameters and remain unchanged during algorithm operation.
[0014] The present invention has at least the following technical effects through the technical solution provided by the present invention: The suggestion generation method based on a two-layer particle swarm optimization algorithm provided by this invention brings significant technical benefits and engineering value in practical applications: Global collaborative optimization and improved stability: By parameterizing and encoding instructions, examples, and task descriptions and performing swarm evolution, the nonlinear coupling optimization problem of multi-dimensional elements in discrete space is solved, significantly reducing the sensitivity of suggestion words to small perturbations in the model and enhancing the output robustness of LLM in high-precision business scenarios; Efficient information accumulation and evolution mechanism: By using the master particle as an "elite information center" to dynamically accumulate high-quality gene components, combined with normalized probability sampling and probability threshold filtering mechanisms, the algorithm can quickly lock the high-quality search space and filter random noise, effectively avoiding the problem of traditional search easily getting trapped in local optima; Engineering standardization and cost reduction: It realizes the transformation of suggestion engineering from manual trial and error to a standardized automatic pipeline paradigm, greatly reducing the migration and manual maintenance costs during model version iteration or task fine-tuning, and ensuring that optimal instruction support can be continuously obtained in complex scenarios such as finance and healthcare. Attached Figure Description
[0015] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a prompt generation method based on a two-layer particle swarm optimization algorithm provided in an embodiment of the present invention. Detailed Implementation
[0016] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.
[0017] In this invention, the terms "system" and "network" are used interchangeably. "Multiple" refers to two or more; therefore, in this invention, "multiple" can also be understood as "at least two." "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / ", unless otherwise specified, generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, it should be understood that in the description of this invention, terms such as "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or order.
[0018] Please see Figure 1 This invention provides a prompt generation method based on a two-layer particle swarm optimization algorithm, comprising the following steps: Step S1: Initialize algorithm parameters, including maximum number of iterations, particle swarm size, inner layer update probability threshold and outer layer reset probability threshold, and initialize the historical best fitness list and the historical best particle swarm list; Step S2: Construct the main particle, which includes a prompt word pool, a reference example pool, and a task description pool; Step S3: Generate a particle swarm from the main particle by random sampling. Each particle in the particle swarm contains a cue word, a subset of reference examples, and a subset of task descriptions selected from the main particle. Step S4: For each particle, concatenate its three components into a complete prompt word, call the large language model on the validation dataset to obtain the model output, and calculate the fitness of each particle based on the semantic consistency between the model output and the standard answer; Step S5: Determine the particle with the highest fitness in the current particle swarm as the optimal particle, generate a first random number, if the first random number is less than the inner layer update probability threshold, then store the fitness of the optimal particle in the historical optimal fitness list, store the optimal particle itself in the historical optimal particle population list, and incrementally add the hint words, reference example subset and task description subset carried by the optimal particle to the corresponding pool of the main particle; Step S6: Generate a second random number. If the second random number is less than the outer layer reset probability threshold, then proceed to step S2 to reconstruct the main particle. Step S7: Update the iteration count. If the maximum iteration count has not been reached, proceed to step S3. Otherwise, output the particle with the highest fitness from the list of historical best particle populations as the global optimal solution.
[0019] In this embodiment of the invention, step S1 mainly involves initializing algorithm parameters, specifically including: the maximum number of iterations. Particle swarm size M, inner layer update probability threshold outer layer reset probability threshold Initialize the historical best fitness list and the list of historical best particle populations Set the current iteration number. Next, proceed to step S2.
[0020] In this embodiment of the invention, step S2 involves constructing the master particle (ancestor particle), specifically: constructing the master particle. The main particle contains a pool of cue words. Reference Example Pool and task description pool Specifically, it is expressed as follows: Among them, the prompt word pool By adjusting the inference hyperparameters of the large language model (such as increasing the temperature coefficient to enhance creativity, or limiting the generation length to obtain concise instructions), N different prompt words can be generated for the same task; refer to the example pool. From the training dataset Perform non-reset random sampling to obtain Z sets of input-output pairs; task description pool By guiding the large language model to actively observe and compare with the training dataset From multiple samples, the model autonomously summarizes and outputs X deep feature descriptions about the task; then step S3 is executed.
[0021] In this embodiment of the invention, step S3 involves generating a particle swarm from the master particle (ancestor particle), specifically: from the master particle... Particle swarm generation is achieved through random sampling. Where M is the number of particles in the swarm, and each particle... The construction method is as follows: Among them, prompts That is, each particle's cue word is randomly selected uniformly from the cue word pool of the main particle (ancestor particle); see example. Reference example subset Randomly draw z input-output pairs without replacement from the reference example pool of the main particle; Task Description Task description subset Randomly select x description fragments without replacement from the task description pool of the main particle; repeat the above process M times to generate a complete particle swarm. Next, proceed to step S4.
[0022] In this embodiment of the invention, step S4 calculates the particle fitness, specifically by: for each particle... The three components it carries (hint) Reference Examples Task Description By piecing together elements according to a preset template or structure, a complete prompt message can be generated that can be executed by a large model (LLM). The generated prompt words and validation dataset Each input in the model is concatenated to obtain a complete input list, which is then fed into the larger model to produce an output list. abbreviated as Let the standard output be... ,contrast and , to obtain particles The fitness of a particle is determined by comparing the elements of two output lists one by one using LLM. The fitness of the particle is defined as follows: ,in The semantic consistency determination function is implemented by using a preset determination prompt template to ask the large language model, "Judging from a semantic level..." The function checks for consistency; if the model returns "consistent," it returns 1; otherwise, it returns 0. This process is repeated to obtain a list of fitness functions for the current particle swarm. Next, proceed to step S5.
[0023] In this embodiment of the invention, step S5 performs inner layer update (elite gene accumulation), specifically: determining the particle with the highest fitness in the current particle swarm as the optimal particle. To avoid getting stuck in local optima, a roulette wheel strategy is used to generate the first random number. , ,like Then update Update the optimal particle population: Expanding prompts Expand upon the examples: Task description expanded: Otherwise, no updates will be made. The specific formula is as follows: , The fitness of the best particle is stored in the historical best fitness list, the particle itself is stored in the historical best particle population list, and the hints, reference example subsets, and task description subsets carried by the particle are incrementally added to the corresponding pool of the main particle. If an element in the best particle is duplicated in the main particle pool, it is added again (the more excellent genes, the greater the probability of being selected in subsequent steps); if If no update is made, the search remains exploratory; then proceed to step S6.
[0024] In this embodiment of the invention, step S6 performs an outer layer reset (global exploration), specifically by generating a second random number. , ,like If the search range is too large, proceed to step S2 to reconstruct the main particle. Set a smaller value; otherwise, continue execution. This mechanism is used to prevent the algorithm from getting trapped in local optima; then proceed to step S7.
[0025] In this embodiment of the invention, step S7 performs iterative control and output, specifically by updating the iteration count. ,like If the result is positive, proceed to step S3 to continue the next round of evolution; otherwise, stop the iteration and output the particle with the highest fitness from the list of historical best particle populations as the global optimal solution. .
[0026] Furthermore, in the above method, the inner layer update probability threshold A fixed value can be used (generally set to 0.5, i.e., a 50% probability of acceptance), or an exponential decay adaptive method can be used to dynamically adjust the value. ,in, This represents the current iteration number. Set the initial number of iterations to the maximum number of iterations. , Outer layer reset probability threshold A fixed value can be used (generally set to 0.01 to prevent excessive search range), or it can be dynamically adjusted using an exponential decay adaptive method. Furthermore, the particle swarm size M, the number of reference examples z for each particle, and the number of task descriptions x are all preset hyperparameters that remain unchanged during the algorithm's operation.
[0027] In one implementation, taking the unstructured data parsing task of a financial private equity investment report as an example, the execution process of the present invention is described in detail as follows: First, system initialization is performed: a training dataset is constructed for the target task. and validation dataset For example, each sample in the training data contains input (I): a non-standard private equity investment report text (e.g., "This product was registered in October 2023, with a scale of approximately 120 million, investing in CTA strategies..."), and output (O): standard JSON format data (e.g., {"Registration Time":"2023-10", "Scale":"120,000,000", "Strategy Type":"CTA"}). Validation dataset. The structure is the same, but the data volume is smaller, used to adjust algorithm parameters. The system initializes the main particle. : By adjusting the hyperparameters of the Large LLM inference model, N candidate prompt words are generated, forming From the training dataset The reference example pool is formed by randomly sampling Z=50 input-output pairs without replacement. The LLM program is guided to observe multiple samples in the training set and autonomously summarize and output X=8 deep feature descriptions, forming a task description pool. At the same time, set the initial number of iterations. Maximum number of iterations Set the inner layer update probability threshold. Adaptive exponential decay method: Outer layer reset probability threshold Use fixed values .
[0028] Furthermore, particle swarm generation and evaluation are performed. In each iteration, the system generates a particle swarm of size M from the main particle resource pool using uniform distribution sampling. Each particle The instructions it carries Reference example subset and task description subset To create a complete prompt word scheme Then, validate the dataset. Run the large language model and obtain the model output list. Using LLM as the decision criterion, each one is compared individually. Compared with the standard answer semantic consistency (here) It is the result of the large model output, that is , (This is the standard answer), calculate the fitness score for each particle: , where m is the size of the validation set, and in this embodiment m=50.
[0029] Furthermore, by performing probability-driven gene evolution, the system identifies the index of the particle with the highest fitness in the current population. Generate a random number between 0 and 1. ,like Then the update mechanism is triggered: the fitness of the best particle is stored in... The individual information of the optimal particle is stored in the optimal population. The hints, subset of reference examples, and subset of task description carried by the optimal particle are incrementally incorporated into the main particle. The corresponding pool is used (duplicate elements are added repeatedly). If the threshold condition is not met, the main particle remains unchanged to maintain the exploratory nature of the search. Subsequently, a second random number is generated. ,like If the value is less than 0.01, then jump to step S2 to rebuild the main particle, realize a global reset, and prevent the algorithm from getting stuck in a local optimum.
[0030] Finally, the iteration terminates and the optimal solution is output. Then proceed to the next iteration, until the number of iterations reaches the preset maximum value. At this point, the algorithm stops evolving, and the system evolves from the elite population accumulated over generations. In the process, the particle with the highest historical fitness score is retrieved as the global optimal solution: The high-quality prompt word scheme integrated by this particle can be directly applied to high-precision automated financial data extraction tasks.
[0031] The key technical point of this invention lies in: an inner and outer layer optimization architecture based on dual random probability control: This invention protects a nested two-layer search mechanism. The inner loop iterates through a probability threshold. The incremental push of elite individuals to the main particle (ancestral particle) resource pool is controlled to achieve robust accumulation of local genes; the outer loop uses an independent probability threshold. Triggering a global reset logic, the system randomly jumps back to the main particle initialization or component regeneration stage. This dual random perturbation mechanism mathematically balances the exploration and development of the algorithm, effectively avoiding the local optimum trap in the discrete cue space. A lightweight discrete evolutionary model with demutation: Unlike traditional particle swarm optimization algorithms that rely on complex velocity and displacement formulas for mutation operations, this invention protects a lightweight evolutionary method based on a "main particle resource pool." The algorithm simplifies complex individual mutations to gene abundance updates within the main particle through the probabilistic absorption of the optimal components from previous generations by the main particle, significantly reducing computational overhead and logical complexity when handling large-scale cue word combinations, and reducing token waste during the optimization process. A large model cue generation method based on particle swarm optimization: This invention protects an automated generation method that deeply couples large model cue word elements with particle swarm evolution logic. This method maps non-differentiable, highly discrete cue word components (including task instructions, few-sample examples, and task feature descriptions) to heterogeneous components of particles and uses a large model as an intelligent evaluator for real-time fitness quantification. During the evolution process, the algorithm not only achieves global collaborative optimization of various cue elements in the combination space, but also enables the model to autonomously discover deep task features that surpass human experience through the probabilistic evolution mechanism of the master particle. This method transforms cue engineering from inefficient trial-and-error based on human experience into a standardized automated evolution pipeline, significantly improving the output accuracy and robustness of the agent in complex, high-precision business scenarios.
[0032] Furthermore, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the present invention.
[0033] The optional embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the embodiments of the present invention are not limited to the specific details in the above embodiments. Within the scope of the technical concept of the embodiments of the present invention, various simple modifications can be made to the technical solutions of the embodiments of the present invention, and these simple modifications all fall within the protection scope of the embodiments of the present invention.
[0034] It should also be noted that the various specific technical features described in the above embodiments can be combined in any suitable manner without contradiction. To avoid unnecessary repetition, the embodiments of the present invention will not describe the various possible combinations separately.
[0035] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a microcontroller, chip, or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0036] Furthermore, various different implementations of the present invention can be combined arbitrarily, as long as they do not violate the spirit of the present invention, they should also be regarded as the content disclosed in the present invention.
Claims
1. A hint generation method based on a two-layer particle swarm optimization algorithm, characterized in that, Includes the following steps: Step S1: Initialize algorithm parameters, including maximum number of iterations, particle swarm size, inner layer update probability threshold and outer layer reset probability threshold, and initialize the historical best fitness list and the historical best particle population list; Step S2: Construct the main particle, which includes a prompt word pool, a reference example pool, and a task description pool; Step S3: Generate a particle swarm from the main particle by random sampling. Each particle in the particle swarm contains a cue word, a subset of reference examples, and a subset of task descriptions selected from the main particle. Step S4: For each particle, concatenate its three components into a complete prompt word, call the large language model on the validation dataset to obtain the model output, and calculate the fitness of each particle based on the semantic consistency between the model output and the standard answer; Step S5: Determine the particle with the highest fitness in the current particle swarm as the optimal particle, generate a first random number, and if the first random number is less than the inner layer update probability threshold, store the fitness of the optimal particle in the historical optimal fitness list, store the optimal particle itself in the historical optimal particle population list, and incrementally add the hint words, reference example subset, and task description subset carried by the optimal particle to the corresponding pool of the main particle. Step S6: Generate a second random number. If the second random number is less than the outer layer reset probability threshold, then proceed to step S2 to reconstruct the main particle. Step S7: Update the iteration count. If the maximum iteration count has not been reached, proceed to step S3. Otherwise, output the particle with the highest fitness from the list of historical best particle populations as the global optimal solution.
2. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 1, characterized in that, The method for calculating particle fitness in step S4 is as follows: , in, To verify the size of the dataset, For particles The corresponding model output, As the standard answer, This is a semantic consistency determination function. It returns 1 if the two are semantically consistent, and 0 otherwise.
3. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 1, characterized in that, In step S5, the inner layer update probability threshold Dynamic adjustment using an exponential decay adaptive method: , in, This represents the current iteration number. This represents the maximum number of iterations.
4. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 1, characterized in that, In step S6, the outer layer reset probability threshold Dynamic adjustment using an exponential decay adaptive method: , in, This represents the current iteration number. This represents the maximum number of iterations.
5. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 1, characterized in that, The specific method for constructing the main particle in step S2 is as follows: The prompt word pool generates multiple different prompt words for the same task by adjusting the inference hyperparameters of the large language model; The reference example pool obtains multiple sets of input-output pairs by performing non-reset random sampling from the training dataset; The task description pool guides the large language model to observe and compare multiple samples in the training dataset, and the model autonomously summarizes and outputs multiple task-deep feature descriptions.
6. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 1, characterized in that, In step S3, the reference example subset and task description subset for each particle are selected from the corresponding pool of the main particle using random sampling without replacement, and the sampling between different particles is independent of each other.
7. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 2, characterized in that, The semantic consistency determination function The implementation method is as follows: using a preset judgment prompt template, ask the large language model "Judging from the semantic level". "Is it consistent?" If the model returns "consistent", output 1; otherwise, output 0.
8. The prompt generation method based on a two-layer particle swarm optimization algorithm according to claim 1, characterized in that, In step S5, if the first random number is less than the inner layer update probability threshold, and the prompt word, reference example, or task description in the optimal particle is the same as an existing element in the main particle pool, then the particle is added repeatedly.
9. The prompt generation method based on the two-layer particle swarm algorithm according to claim 1, wherein the particle swarm size, the number of reference examples for each particle, and the number of task descriptions for each particle are preset hyperparameters and remain unchanged during the algorithm operation.