Self-improving Artificial Intelligence (AI) agent evaluation loop architecture
Self-improving Artificial Intelligence (AI) agent evaluation loop architecture: DSPy and MIPRO for inner-loop prompt optimisation, adversarial outer-loop variation, and benchmark harness selection
- DSPy is the only surveyed automated prompt optimization framework that provides both inner-loop instruction search and outer-loop metric-based evaluation within a single codebase, making it the correct integration target for a Self-Improving Agent Evaluation Loop. (Confidence: high)
- APE automated instruction generation outperformed human-annotated prompts on 19 of 24 NLP tasks and matched on the remaining 5, establishing that systematic instruction search has materially higher ceiling than hand-tuning. (Confidence: high)
- OPRO's meta-prompt optimization outperforms human-designed prompts by up to 8% on GSM8K and up to 50% on Big-Bench Hard tasks, with gains attributable to accumulated optimization history in the meta-prompt rather than any single instruction change. (Confidence: high)
- TextGrad's text-backpropagation mechanism improved GPT-4o GPQA accuracy from 51% to 55% zero-shot, but its per-update LLM call overhead makes it a poor fit for repeated self-improvement cycles in API-cost-constrained environments. (Confidence: medium)
- DSPy MIPRO with default settings (~4 candidates, 4 demos, 10 trials, batch of 35) requires approximately 370 LLM API calls per optimization run, placing weekly automated runs within operational budget but ruling out per-commit CI integration. (Confidence: high)
- AgentBench is the only benchmark in the surveyed set with an explicit training split across 8 interactive environments, making it the best-suited source for DSPy inner-loop bootstrapping as opposed to evaluation-only use. (Confidence: high)
- Chambers and Partners Global Practice Guides are copyright-protected and their terms explicitly prohibit bulk extraction and redistribution for AI training purposes, requiring direct commercial negotiation for any Golden Set use — a path that is not self-serviceable. (Confidence: high)
- FinBen (36 datasets, 24 financial tasks, NeurIPS 2024) is open-source and directly applicable as a domain Golden Set for NZ financial services agents, though it requires NZ-specific regulatory supplementation because its tasks are US-centric. (Confidence: medium)
Research Question
What is the most principled architecture for a Self-Improving AI Agent Evaluation Loop — specifically, how should a nested inner/outer loop be designed so that a "Meta-Optimizer" rewrites system prompts based on failure analysis without causing instruction drift or overfitting to specific training questions?
Findings
Executive Summary
DSPy (Khattab et al., 2023) is the most principled foundation for a Self-Improving AI Agent Evaluation Loop because it is the only surveyed framework providing native support for both an inner loop (instruction and demonstration optimization) and an outer loop (evaluation against a held-out metric) within a single pip-installable Python package. The canonical architecture pairs MIPRO as the inner-loop optimizer — searching instruction-demo combinations via Bayesian optimization at ~370 LLM calls per run — with an LLM-prompted paraphrase engine as the outer-loop variation mechanism. Instruction drift is managed by incorporating a token-count Brevity Penalty into MIPRO's objective and applying LLMLingua compression before each update, grounded in empirical evidence that prompt length degrades recall accuracy through context rot and the lost-in-the-middle effect. The Chambers & Partners Golden Set path is blocked by copyright with no self-service licensing available; the open alternative stack is AgentBench (inner-loop bootstrap), GAIA (tool-use robustness), FinBen (finance), and LegalBench plus legislation.govt.nz statute text (NZ legal domain). The primary open architectural question — how to refresh the outer-loop test set before it itself overfits — is unresolved in any surveyed framework.
Key Findings
- DSPy is the only surveyed automated prompt optimization framework that provides both inner-loop instruction search and outer-loop metric-based evaluation within a single codebase, making it the correct integration target for a Self-Improving Agent Evaluation Loop. (Confidence: high)
- APE automated instruction generation outperformed human-annotated prompts on 19 of 24 NLP tasks and matched on the remaining 5, establishing that systematic instruction search has materially higher ceiling than hand-tuning. (Confidence: high)
- OPRO's meta-prompt optimization outperforms human-designed prompts by up to 8% on GSM8K and up to 50% on Big-Bench Hard tasks, with gains attributable to accumulated optimization history in the meta-prompt rather than any single instruction change. (Confidence: high)
- TextGrad's text-backpropagation mechanism improved GPT-4o GPQA accuracy from 51% to 55% zero-shot, but its per-update LLM call overhead makes it a poor fit for repeated self-improvement cycles in API-cost-constrained environments. (Confidence: medium)
- DSPy MIPRO with default settings (~4 candidates, 4 demos, 10 trials, batch of 35) requires approximately 370 LLM API calls per optimization run, placing weekly automated runs within operational budget but ruling out per-commit CI integration. (Confidence: high)
- AgentBench is the only benchmark in the surveyed set with an explicit training split across 8 interactive environments, making it the best-suited source for DSPy inner-loop bootstrapping as opposed to evaluation-only use. (Confidence: high)
- Chambers and Partners Global Practice Guides are copyright-protected and their terms explicitly prohibit bulk extraction and redistribution for AI training purposes, requiring direct commercial negotiation for any Golden Set use — a path that is not self-serviceable. (Confidence: high)
- FinBen (36 datasets, 24 financial tasks, NeurIPS 2024) is open-source and directly applicable as a domain Golden Set for NZ financial services agents, though it requires NZ-specific regulatory supplementation because its tasks are US-centric. (Confidence: medium)
- Prompt length degrades LLM recall accuracy non-uniformly through context rot and the lost-in-the-middle effect; every Meta-Optimizer instruction update must include a compression step — LLMLingua achieves up to 20× compression with negligible performance loss. (Confidence: high)
- LLM-prompted paraphrase generation is the lowest-cost outer-loop variation method, but answer-consistency validation is mandatory because paraphrase generation can silently alter the semantically correct answer. Adversarial paraphrasing (NeurIPS 2025) is more effective at surface coverage but requires additional quality gates. (Confidence: medium)
Assumptions
- Assumption: The Self-Improving Loop operates against LLM APIs only (no local GPU compute). Justification: Explicitly stated in scope constraints; all cost estimates derived accordingly.
- Assumption: A weekly optimization cadence is the appropriate operational schedule. Justification: Derived from cost calculation (~370 API calls × weekly frequency = manageable; daily frequency becomes expensive); not empirically validated for this specific repo.
- Assumption: NZ legislation.govt.nz text is freely usable for LLM training. Justification: New Zealand government publications are typically Crown copyright with open licensing for non-commercial use, but specific terms should be confirmed before building a Golden Set from this source.
- Assumption: Brevity Penalty and Prompt Pruning can be implemented as MIPRO objective modifications. Justification: DSPy's modular objective design supports custom metric functions; the specific implementation is untested in this context.
Analysis
The four frameworks (APE, OPRO, TextGrad, DSPy) form a progression from simple search (APE) to history-aware search (OPRO) to gradient-analogue feedback (TextGrad) to full pipeline programming (DSPy). The key discriminator for this repo's use case is not raw performance ceiling — all four show substantial gains over hand-tuning — but operational fit: weekly API-accessible runs, Python integration into src/, and explicit outer-loop support. DSPy wins on all three criteria.
The benchmark landscape divides cleanly into three tiers for an optimization loop: bootstrapping sources (AgentBench — has training splits), evaluation harnesses (GPQA, MMLU-Pro, HLE, GAIA — held-out test sets), and domain Golden Sets (FinBen, LegalBench, SWE-bench). The absence of a training split in most benchmarks is a deliberate design choice to prevent contamination; this means the inner loop can only bootstrap from actual agent interaction traces, not from benchmark training data for most benchmarks.
The Chambers & Partners assessment is a clear no-go for unilateral action. The structured Q&A format of the Guides is ideal for a Golden Set, but the copyright barrier is absolute without a negotiated license. The open-source alternative (LegalBench + NZ statute text) is less curated but immediately actionable.
Instruction drift is the central reliability risk of iterative prompt optimization. Every update that adds a new rule without removing redundant prior rules will lengthen the prompt and degrade performance through context rot. The mitigation architecture — Brevity Penalty in the objective + LLMLingua compression post-update — is grounded in empirical evidence but its specific implementation in DSPy is an engineering task, not a research question.
Risks, Gaps, and Uncertainties
- Outer-loop test set refresh policy is unresolved. No surveyed framework specifies when or how to replace the variation set to prevent the outer loop itself from overfitting. This is a first-order architectural gap.
- NZ-specific regulatory content is absent from all open benchmarks. FinBen is US-centric; LegalBench covers common law principles but not NZ statutes. A custom Golden Set is required for production NZ financial/legal agent evaluation.
- Brevity Penalty formulation is an inference, not a published technique. The concept is sound and grounded in compression literature, but no primary paper implements it as a DSPy objective term specifically. This requires prototyping.
- LLMLingua 20× compression claim is from vendor documentation. Independent third-party validation of the compression-without-loss claim is not confirmed in this review.
- Adversarial paraphrasing transfer to agent evaluation is an inference. NeurIPS 2025 work demonstrated effectiveness on AI detection tasks; whether the same approach generalises to research agent Q&A is not empirically established.
Open Questions
- What is the correct policy for rotating the outer-loop variation test set — by age, by accuracy saturation, or by explicit adversarial gap analysis? (Candidate backlog item)
- Can legislation.govt.nz content be used as LLM training data under NZ Crown copyright terms, and what is the procedure for establishing this? (Candidate backlog item)
- Is TextGrad's text-backpropagation approach viable for a multi-component agent pipeline where individual modules (retrieval, synthesis, citation) need independent optimization? (Future research item)
- What is the practical accuracy ceiling for GAIA level-3 tasks with a DSPy-optimized agent using only LLM API calls and web search? (Evaluation question)
sources
- [x] Khattab et al. (2023) — "DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines"
- [x] Yang et al. (2024) — "OPRO: Large Language Models as Optimizers"
- [x] Zhou et al. (2023) — "Large Language Models Are Human-Level Prompt Engineers (APE)"
- [x] Yuksekgonul et al. (2024) — "TextGrad: Automatic 'Differentiation' via Text"
- [x] Rein et al. (2023) — "GPQA: A Graduate-Level Google-Proof Q&A Benchmark"
- [x] Mialon et al. (2023) — "GAIA: A Benchmark for General AI Assistants"
- [x] Xie et al. (2024) — "FinBen: A Holistic Financial Benchmark for Large Language Models"
- [x] Guha et al. (2023) — "LegalBench: A Collaboratively Built Benchmark for Measuring Legal Reasoning in Large Language Models"
- [x] Jimenez et al. (2024) — "SWE-bench: Can Language Models Resolve Real-World GitHub Issues?"
- [x] Liu et al. (2023) — "AgentBench: Evaluating LLMs as Agents"
- [x] DSPy documentation
- [x] Chambers and Partners Global Practice Guides — (assess licensing and structured Q&A availability)
- [x] HLE (Humanity's Last Exam) — (assess data access and format)
- [x] MMLU-Pro