Particle Swarm Optimization Meets Large Language Models
Xiaoyan Yu · 2025
Large Language Models (LLMs) have shown remarkable capabilities across many Natural Language Processing (NLP) tasks, but their performance hinges on well-designed prompts. Recent studies have explored discrete prompt optimization using Evolutionary Algorithms (EAs), e.g., the EVOPROMPT framework for black-box automatic prompt tuning. In this paper, we introduce a new approach, Swarm-Prompt, which leverages Particle Swarm Optimization (PSO) for discrete prompt optimization in LLMs. We show how LLMs can be used to perform swarm-based position and velocity updates in discrete prompt space, generating new prompt variants that balance exploration and exploitation without access to model gradients. Swarm-Prompt follows the experimental setup of EVOPROMPT on diverse language understanding, generation, and reasoning tasks. Our experiments on instruction-following models demonstrate that PSO-driven prompt optimization yields competitive or superior results, compared to previous studies. In particular, Swarm-Prompt outperforms human-crafted prompts and prior automatic prompt generation methods, and it significantly improves over Genetic Algorithm (GA) and Differential Evolution (DE) variants on several benchmarks (e.g. 4.2% average gain on challenging reasoning tasks). To the best of our knowledge, this work is the first to connect LLMs with swarm intelligence for prompt optimization, illustrating a novel synergy between LLMs and conventional algorithms.