Large Language Models (LLMs) are increasingly used in reasoning, summarization, classification, structured generation, and decision-support tasks. However, their output quality is highly sensitive to prompt wording, structure, examples, and constraints. Manual prompt engineering is brittle, time-consuming, difficult to reproduce, and rarely integrated with systematic benchmarking, governance, versioning, or auditability. This paper presents a self-improving agentic framework for LLM prompt optimization and benchmarking. The proposed system treats prompts as optimizable artifacts and integrates prompt generation, prompt refinement, benchmark-driven evaluation, multi-objective scoring, reinforcement learning, evolutionary search, multi-armed bandit selection, governance checks, Human-in-the-Loop (HITL) review, versioning, audit logging, and report export. A Flask-based implementation using SQLite, Bootstrap, Chart.js, and Gemini API support is developed and evaluated through a local experimental dashboard. Demonstration results show that the system manages three prompts, five benchmark tasks, prompt lifecycle states, governance review, audit traces, and CSV reports. The Reasoning Tutor prompt achieved a task score of 0.94, safety score of 1.0, latency of 0.3 seconds, and an estimated cost of $0.000100 in the evaluated case. The proposed work demonstrates how prompt engineering can be transformed from an ad hoc manual process into a structured, benchmark-driven, governed, and auditable LLMOps workflow.
Introduction
The text presents a Self-Improving Agent for LLM Prompt Optimization and Benchmarking, an intelligent system designed to automatically generate, evaluate, optimize, and improve prompts used with Large Language Models (LLMs).
1. Introduction
Large Language Models are widely used for text generation, summarization, classification, reasoning, and decision-making. However, their performance depends heavily on prompt design. Even small changes in instructions, wording, or output format can affect the quality of generated responses.
Traditional prompt engineering is mostly manual, time-consuming, and difficult to scale. Developers repeatedly write, test, and modify prompts to achieve better results.
To overcome these limitations, the research proposes an automated agent-based framework that continuously generates, evaluates, refines, and manages prompts to improve LLM performance.
2. Related Work
The paper discusses four major research areas:
Prompt Engineering and Evaluation: Designing instructions, examples, roles, and constraints to improve LLM responses.
LLM-Based Autonomous Agents: Using planning, memory, feedback, and external tools to perform complex tasks.
Prompt Optimization: Applying evolutionary algorithms, reinforcement learning, and optimization techniques to improve prompts automatically.
Safety, Governance, and Auditability: Ensuring that optimized prompts remain safe, fair, reliable, and cost-effective.
3. Proposed System Architecture
The proposed framework consists of seven major layers:
User Dashboard
Orchestration Layer
Agent Layer
Optimization Layer
Benchmarking and Evaluation Layer
LLM Abstraction Layer
Governance and Audit Layer
It includes seven specialized agents:
Prompt Generation Agent: Creates different prompt candidates.
Prompt Refinement Agent: Improves prompts by adding constraints, examples, formatting instructions, and safety rules.
Evaluation Agent: Tests prompts using an LLM.
Benchmarking Agent: Manages benchmark tasks and expected outputs.
Feedback Learning Agent: Learns from previous evaluation results.
Governance Agent: Checks safety, privacy, bias, response time, and cost.
Orchestration Agent: Coordinates all agents and manages the optimization process.
4. Methodology
The system follows an automated prompt optimization process.
A. Prompt Representation
Prompts are divided into smaller instruction blocks, such as:
Role
Task
Context
Constraints
Output format
Safety rules
Evaluation criteria
This modular structure makes prompts easier to modify, compare, and manage.
B. Benchmark-Driven Evaluation
Generated prompts are tested against predefined benchmark tasks to measure their performance.
The evaluation considers task quality, safety, robustness, fairness, response latency, and computational cost.
C. Multi-Objective Optimization
The system calculates an overall utility score using weighted evaluation metrics.
Prompts that violate safety, latency, or cost requirements are rejected or sent for human review.
D. Optimization Strategies
The framework supports three main optimization techniques:
Multi-Armed Bandit (UCB): Selects refinement strategies based on their previous performance.
Evolutionary Search: Improves prompts through selection, crossover, and mutation.
Reinforcement Learning (Q-Learning): Learns which prompt modification actions produce better results.
The system also supports a hybrid optimization mode combining these techniques.
5. Implementation Technologies
The project is developed as a Flask-based web application.
Technology
Purpose
Python
Main programming language
Flask
Web application and backend
SQLite
Database storage
SQLAlchemy
Database management
Bootstrap 5
User interface
Chart.js
Dashboard visualizations
Gemini API
LLM integration
The application includes prompt management, benchmark management, evaluation results, optimization history, human feedback, governance reviews, audit logs, and report generation.
It also supports demo mode when the Gemini API key is unavailable.
6. Experimental Results
The implemented system was tested locally through its Flask web interface.
The demonstration database contained:
3 prompts
5 benchmark tasks
The benchmark tasks covered:
Safety refusal
Structured JSON output
Sentiment classification
Policy summarization
Temporal reasoning
The system uses these tasks to demonstrate how different prompts can be evaluated and optimized across multiple performance dimensions.
Conclusion
This paper presented a self-improving agentic system for LLM prompt optimization and benchmarking. The system treats prompts as optimizable artifacts and integrates prompt generation, benchmark evaluation, multi-objective scoring, bandit selection, evolutionary search, reinforcement learning, governance checks, HITL review, versioning, audit logging, and report export. A working Flask-based implementation with Gemini API support was developed and evaluated using screenshots and demonstration metrics. The results demonstrate that prompt engineering can be transformed from a manual and brittle process into a structured, measurable, governed, and auditable workflow. Future work will extend the system with larger benchmark suites, multi-model testing, advanced safety classifiers, retrieval-augmented generation, richer human feedback learning, and scalable LLMOps deployment.
References
[1] L. Wang, C. Ma, X. Feng, Z. Zhang, H. Yang, J. Zhang, Z. Chen, J. Tang, X. Chen, Y. Lin, W. X. Zhao, Z. Wei, and J.-R. Wen, “A survey on large language model based autonomous agents,” Frontiers of Computer Science, vol. 18, no. 6, 2024.
[2] S. S. Chowa, R. Alvi, S. M. A. U. Rahman, M. A. Rahman, M. A. K. Raiaan, M. R. Islam, M. Hussain, and S. Azam, “From language to action: A review of large language models as autonomous agents and tool users,” Artificial Intelligence Review, vol. 59, no. 2, 2026.
[3] M. Mizrahi, G. Kaplan, D. Malkin, R. Dror, D. Shahaf, and G. Stanovsky, “State of what art? A call for multi-prompt LLM evaluation,” Transactions of the Association for Computational Linguistics, vol. 12, pp. 933–949, 2024.
[4] Y. Chang, X. Wang, J. Wang, Y. Wu, L. Yang, K. Zhu, H. Chen, X. Yi, C. Wang, Y. Wang, W. Ye, Y. Zhang, Y. Chang, P. S. Yu, Q. Yang, and X. Xie, “A survey on evaluation of large language models,” ACM Transactions on Intelligent Systems and Technology, vol. 15, no. 3, pp. 1–45, 2024.
[5] M. S. Torkestani, A. Alameer, P. Shivakumara, and T. Mansouri, “Inclusive prompt engineering for large language models: A modular framework for ethical, structured, and adaptive AI,” Artificial Intelligence Review, vol. 58, no. 11, 2025.
[6] M. Abou Ali, F. Dornaika, and J. Charafeddine, “Agentic AI: A comprehensive survey of architectures, applications, and future directions,” Artificial Intelligence Review, vol. 59, no. 1, 2025.
[7] S. Du, J. Zhao, J. Shi, Z. Xie, X. Jiang, Y. Bai, and L. He, “A survey on the optimization of large language model-based agents,” ACM Computing Surveys, vol. 58, no. 9, pp. 1–37, 2026.
[8] B. Li, Z. Wei, J. Wu, S. Yu, T. Zhang, C. Zhu, D. Zheng, W. Guo, C. Zhao, and J. Zhang, “Machine learning-enabled globally guaranteed evolutionary computation,” Nature Machine Intelligence, vol. 5, no. 4, pp. 457–467, 2023.
[9] S. Chaudhari, P. Aggarwal, V. Murahari, T. Rajpurohit, A. Kalyan, K. Narasimhan, A. Deshpande, and B. Castro da Silva, “RLHF deciphered: A critical analysis of reinforcement learning from human feedback for LLMs,” ACM Computing Surveys, vol. 58, no. 2, pp. 1–37, 2025.
[10] J. Lee, D. Jo, S. J. Yun, and S. Kim, “SGPO: Self-generated preference optimization based on self-improver,” ACM Transactions on Intelligent Systems and Technology, 2026.
[11] Y. Dong, R. Mu, Y. Zhang, S. Sun, T. Zhang, C. Wu, G. Jin, Y. Qi, J. Hu, J. Meng, S. Bensalem, and X. Huang, “Safeguarding large language models: A survey,” Artificial Intelligence Review, vol. 58, no. 12, 2025.
[12] X. Huang, W. Ruan, W. Huang, G. Jin, Y. Dong, C. Wu, S. Bensalem, R. Mu, Q. Yi, X. Zhao, K. Cai, Y. Zhang, S. Wu, P. Xu, D. Wu, A. Freitas, and M. Mustafa, “A survey of safety and trustworthiness of large language models through the lens of verification and validation,” Artificial Intelligence Review, vol. 57, no. 7, 2024.