Research Article

Cost-Aware Adaptive Prompt Selection for Large Language Models Using UCB and Thompson Sampling

Junbo Zhang*
Capital University of Economics and Business

* Corresponding author: [email protected]

Abstract

This paper investigates cost-aware adaptive prompt selection for large language models by modeling four prompt strategies as arms in a multi-armed bandit. Standard UCB and Thompson Sampling are compared with contextual extensions, LinUCB and Linear Thompson Sampling (LinTS), on GSM8K. The study evaluates accuracy, cumulative reward, cumulative regret, average token usage, tokens per correct answer, and budget satisfaction. On the held-out evaluation set, the Global Best prompt achieved 96.8% accuracy with a cumulative regret of 3.00, while the Oracle upper bound reached 97.4%. LinUCB achieved 95.47% accuracy with an average of 200.18 tokens per question, reducing token use by approximately 9.9% relative to the Global Best prompt (222.14 tokens). Under the medium normalized token budget B = 0.2893, cost-constrained LinUCB maintained 95.47%-95.49% accuracy and 93% budget satisfaction, compared with 30%-35% for LinTS. In addition, 92% of evaluation questions produced identical binary rewards across all four prompts, indicating limited prompt-specific heterogeneity. The results suggest that contextual prompt selection may provide greater value for resource control than for accuracy improvement in homogeneous, high-accuracy reasoning settings.

Keywords: Large language model; Prompt optimization; Multi-armed bandit; UCB; Thompson Sampling; Contextual bandit
Published: November 17, 2026
DOI: 10.54254/2755-2721/2026.39115
Volume: ACE Vol.282
pp. 1-10
Download PDF

References

  1. Brown, T. B., et al. (2020). Language models are few-shot learners.Advances in Neural Information Processing Systems, 33, 1877-1901.
  2. Liu, P., Yuan, W., Fu, J., Jiang, Z., Hayashi, H., & Neubig, G. (2023). Pre-train, prompt, and predict: A systematic survey of prompting methods in natural language processing.ACM Computing Surveys, 55(9), 1-35. https://doi.org/10.1145/3560815
  3. Wei, J., et al. (2022). Chain-of-thought prompting elicits reasoning in large language models.Advances in Neural Information Processing Systems, 35, 24824-24837.
  4. Shin, T., Razeghi, Y., Logan IV, R. L., Wallace, E., & Singh, S. (2020). AutoPrompt: Eliciting knowledge from language models with automatically generated prompts.Proceedings of EMNLP, 4222-4235. https://doi.org/10.18653/v1/2020.emnlp-main.346 https://aclanthology.org/2020.emnlp-main.346/
  5. Zhou, Y., Muresanu, A. I., Han, Z., Paster, K., Pitis, S., Chan, H., & Ba, J. (2023). Large language models are human-level prompt engineers.International Conference on Learning Representations (ICLR).
  6. Lester, B., Al-Rfou, R., & Constant, N. (2021). The power of scale for parameter-efficient prompt tuning.Proceedings of EMNLP, 3045-3059. https://aclanthology.org/2021.emnlp-main.243/
  7. Deng, M., Wang, J., Hsieh, C.-P., Wang, Y., Guo, H., Shu, T., Song, M., Xing, E., & Hu, Z. (2022). RLPrompt: Optimizing discrete text prompts with reinforcement learning.Proceedings of EMNLP, 3369-3391. https://doi.org/10.18653/v1/2022.emnlp-main.222 https://aclanthology.org/2022.emnlp-main.222/
  8. Auer, P., Cesa-Bianchi, N., & Fischer, P. (2002). Finite-time analysis of the multiarmed bandit problem.Machine Learning, 47, 235-256. https://doi.org/10.1023/A:1013689704352
  9. Russo, D., & Van Roy, B. (2016). An information-theoretic analysis of Thompson sampling.Journal of Machine Learning Research, 17(68), 1-30.
  10. Li, L., Chu, W., Langford, J., & Schapire, R. E. (2010). A contextual-bandit approach to personalized news article recommendation.Proceedings of the 19th International Conference on World Wide Web, 661-670. https://doi.org/10.1145/1772690.1772758
  11. Agrawal, S., & Goyal, N. (2013). Thompson sampling for contextual bandits with linear payoffs.Proceedings of the 30th International Conference on Machine Learning, PMLR 28(3), 127-135. https://proceedings.mlr.press/v28/agrawal13.html
  12. Agrawal, S., & Devanur, N. R. (2016). Linear contextual bandits with knapsacks.Advances in Neural Information Processing Systems, 29. https://proceedings.neurips.cc/paper_files/paper/2016/hash/f3144cefe89a60d6a1afaf7859c5076b-Abstract.html
  13. Cobbe, K., Kosaraju, V., Bavarian, M., Chen, M., Jun, H., Kaiser, L., Plappert, M., Tworek, J., Hilton, J., Nakano, R., Hesse, C., & Schulman, J. (2021). Training verifiers to solve math word problems. arXiv:2110.14168. https://arxiv.org/abs/2110.14168
  14. Agrawal, S., & Goyal, N. (2012). Analysis of Thompson sampling for the multi-armed bandit problem.Proceedings of the 25th Annual Conference on Learning Theory, 23, 39.1-39.26.
  15. Sutton, R. S., & Barto, A. G. (2018).Reinforcement learning: An introduction(2nd ed.). MIT Press.