Large Language Models (LLMs) have demonstrated strong capabilities in complex reasoning tasks, while recent prompting strategies such as Chain-of-Thought (CoT) have further elevated their performance in handling complex logical problems. Despite these advances, high-quality reasoning remains heavily reliant on manual static prompts and is sensitive to decoding configurations and task distributions, leading to performance fluctuations and limited transferability. Existing automatic prompt optimization methods typically adopt single-agent local search, failing to simultaneously optimize prompts and decoding hyperparameters within a unified framework to achieve stable global improvements. To address this limitation, we propose Agent-GWO, a dynamic prompt optimization framework for complex reasoning. Specifically, we unify prompt templates and decoding hyperparameters as inheritable agent configurations. By leveraging the leader-follower mechanism of the Grey Wolf Optimizer (GWO), we automatically select three leader agents (α, β, and δ) to guide the collaborative updates of the remaining agents, enabling iterative convergence toward robust optimal reasoning configurations that can be seamlessly integrated for inference. Extensive experiments on multiple mathematical and hybrid reasoning benchmarks across diverse LLM backbones show that Agent-GWO consistently improves accuracy and stability over existing prompt optimization methods. The code will be released publicly.
Figures & tables
Figure 1: GWO abstracts each LLM agent as a “wolf” which is characterized by hyperparameters & reasoning prompt. These two guide the behavior of the LLMs during the optimization process.
Figure 2: The overall Agent-GWO framework operates by having each agent process a dataset, Prompt, and parameters to produce outputs, which are then scored. Only the top-3 agents ( α , β , and δ ) are differentiated, while the rest (i.e., ω ) are updated using the prompt and parameters from the previous round. This iterative ranking and update process continues until termination, after which the final agent is set as the top-ranked α from the last iteration. Note: The left-bottom subfigure illustrates the learning process of each agent at each iteration and the right-bottom subfigure illustrates the optimization process.
Model
Math Reasoning Tasks
Hybrid Reasoning Tasks
Avg
GSM8K
MATH
SVAMP
MultiArith
ASDiv
AQUA
MMLU
BBH
Date
CLUTRR
MATH_MIX
GPT-4o-mini
CoT
85.4%
74.8%
84.7%
89.5%
92.3%
65.3%
63.4%
66.6%
52.1%
66.2%
80.1%
74.6%
CoT-SC/n=5
89.9%
76.3%
85.8%
89.7%
93.3%
70.7%
67.1%
69.0%
54.7%
72.2%
81.6%
77.3%
Self-Refine
88.9%
75.1%
85.0%
89.9%
92.2%
67.8%
64.8%
67.5%
53.0%
68.4%
83.8%
76.0%
AFlow
93.5%
78.9%
88.7%
91.9%
93.4%
72.0%
69.5%
68.0%
66.0%
72.8%
85.3%
80.0%
Table 1: Performance comparison of Agent-GWO against baselines across math and hybrid reasoning tasks. Bold indicates the best result, and underlined indicates the second-best result.
Model / Method
Math Reasoning Tasks
Hybrid Reasoning Tasks
Avg. Increase
GSM8K
MATH
SVAMP
MultiArith
ASDiv
AQUA
MMLU
BBH
Date
CLUTRR
MATH_MIX
GPT-4o-mini
CoT
85.4%
74.8%
84.7%
89.5%
92.3%
65.3%
63.4%
66.6%
52.1%
66.2%
80.1%
-
CoT+GWO/n=5
95.1%
79.9%
92.4%
99.5%
93.8%
76.1%
73.7%
71.3%
77.1%
74.9%
85.0%
↑ 8.9%
CoT+GWO/n=6
96.5%
81.5%
92.9%
99.8%
94.5%
76.8%
74.9%
72.2%
78.3%
75.8%
95.1%
↑ 10.7%
GPT-4.1-mini
Table 2: Combined evaluation of adaptability of GWO to CoT on math and hybrid reasoning tasks.
Figure 5
Parameter
Sampling Rule
Perf.(%)
Cost ($)
tj
(0.2, 0.1)
↓ 1.0–1.5%
↓ 3–5%
(0.4, 0.1)
↓ 0.3–0.6%
↓ 1–2%
(0.6, 0.1)
baseline
baseline
(0.8, 0.1)
↓ 0.5–1.0%
↑ 4–7%
pj
(0.2, 0.1)
↓ 0.8–1.3%
↓ 2–4%
(0.4, 0.1)
↓ 0.2–0.5%
↓ 1–2%
Table 3: Sensitivity analysis of agent-level decoding hyperparameters. Entries report relative performance and cost changes compared to the baseline configuration used in our framework.
Elite Size
Elite
GSM8K
MATH
MMLU
m=1
α
92.4
76.8
72.0
m=2
α,β
94.8
79.1
74.2
m=3
α,β,δ
95.9
80.2
75.3
m=4
α,β,δ,ω1
95.0
79.4
74.6
m=5
α,β,δ,ω1,ω2
94.1
78.5
73.8
Table 4: Ablation on Elite Set Size. Results under different elite set sizes m . α , β , and δ denote the top three leaders in standard GWO, while ω1 and ω2 denote the 4th- and 5th-ranked agents by fitness, respectively.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 5: Illustration of GWO algorithm.
Method
Model
GSM8K
CoMAT Leang et al. (2025)
GPT-4
93.7
CoT Wei et al. (2022)
GPT-4
94.5
FCoT Lyu et al. (2023)
GPT-4
95.0
MathPrompter Imani et al. (2023)
GPT-4
95.6
QuaSAR Radford et al. (2018)
GPT-4
96.5
MathDivide Srivastava and Gandhi (2024)
GPT-4
96.8
Appendix
Table 5: Accuracy on GSM8K comparing GPT-4 and GPT-4o-mini.
Method
Base
GSM8K
MATH
OMI2 Li et al. (2025b)
Qwen2.5
84.1
72.3
CODEI/O++ Li et al. (2025b)
Qwen2.5
85.7
72.1
PyEdu Li et al. (2025b)
Qwen2.5
85.8
71.4
CODEI/O Li et al. (2025b)
Qwen2.5
86.4
71.9
OC-SFT-1 Li et al. (2025b)
Qwen2.5
86.7
70.9
WI Li et al. (2025b)
Qwen2.5
87.0
71.4
Appendix
Table 6: Accuracy (%) on GSM8K and MATH using Qwen2.5-Coder-7B.