SPEAR: Code-Augmented Agentic Prompt Optimization
On the map: LLM agents and tool use → General LLM agent frameworks and benchmarks
Abstract (arXiv)
Automatic prompt engineering (APE) rewrites prompts to improve downstream task performance, but existing APE loops treat the optimizer itself as a fixed pipeline. We port the code-as-action paradigm of CodeAct (Wang et al., 2024a) to APE and propose SPEAR (Sandboxed Prompt Engineer with Active Roll-back), a free-form agentic optimizer with four tools -- evaluate, python, setprompt, finish -- that decides autonomously how and when to use them. The distinctive tool is the Python sandbox: the optimizer writes and executes arbitrary Python on the current evaluation DataFrame, performing structural error analysis (confusion matrices, error clustering, per group metrics) the agent itself authors. Two guardrails turn the long-horizon agent into a monotone-improving optimizer: auto-rollback on metric regression, and an optional guard metric floor. We evaluate on three industrial LLM-as-judge suites (13 judge tasks across recruiter-intake, conversational-memory, and query-refinement systems) plus seven BBH tasks and GSM8K. SPEAR wins every industrial task on the primary metric (kappa 0.857 vs 0.359 on tool-selection; F1-macro 0.815 vs 0.763 on filter-relevance; kappa 0.254 vs 0.218 on the hardest extraction dimension). On BBH-7 SPEAR averages 0.938 accuracy vs GEPA 0.628 and TextGrad 0.484. Ablations show the Python tool is the largest single lever on complex judge tasks (Delta ≈ +0.79kappa on the 5-class tool-selection judge, Delta ≈ +0.35kappa on the hardest extraction dimension when removed); its irreplaceable contribution is class-pair confusion aggregation that a long-context LLM cannot extract reliably from the raw eval DataFrame.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Placed in General LLM agent frameworks and benchmarks, one of 16 directions in LLM agents and tool use. Builds on 29 of its 72 references that are in the map. First posted on arXiv 25 May 2026.
Builds on
29 of 72 references.
Closest ancestors · 2
Same direction, newest first
- 2025MARS: Multi-Agent Adaptive Reasoning with Socratic Guidance for Automated Prompt Optimization21 Mar
- 2025Multi-Agent Design: Optimizing Agents with Better Prompts and Topologies4 Feb
Other references · 27
- 2021Training Verifiers to Solve Math Word Problemscited by 10,109
- 2022ReAct: Synergizing Reasoning and Acting in Language Modelscited by 8,695
- 2022Challenging BIG-Bench Tasks and Whether Chain-of-Thought Can Solve Themcited by 1,807
- 2023Automatic Prompt Optimization with "Gradient Descent" and Beam Searchcited by 653
- 2024Executable Code Actions Elicit Better LLM Agentscited by 564
- 2023Promptbreeder: Self-Referential Self-Improvement Via Prompt Evolutioncited by 551
- 2023LongLLMLingua: Accelerating and Enhancing LLMs in Long Context Scenarios via Prompt Compressioncited by 453
- 2020Efficient Intent Detection with Dual Sentence Encoderscited by 433
- 2024Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programscited by 291
- 2023PromptAgent: Strategic Planning with Language Models Enables Expert-level Prompt Optimizationcited by 233
- 2024Trace is the Next AutoDiff: Generative Optimization with Rich Feedback, Execution Traces, and LLMscited by 69
- 2026EvoX: Meta-Evolution for Automated Discoverycited by 60
15 more
- 2026SkillForge: Forging Domain-Specific, Self-Evolving Agent Skills in Cloud Technical Supportcited by 48
- 2024PromptWizard: Task-Aware Prompt Optimization Frameworkcited by 36
- 2025VISTA: A Test-Time Self-Improving Video Generation Agentcited by 31
- 2024Symbolic Prompt Program Search: A Structure-Aware Approach to Efficient Compile-Time Prompt Optimizationcited by 30
- 2024Fairer Preferences Elicit Improved Human-Aligned Large Language Model Judgmentscited by 25
- 2025No Loss, No Gain: Gated Refinement and Adaptive Compression for Prompt Optimizationcited by 7
- 2025ProCut: LLM Prompt Compression via Attribution Estimationcited by 6
- 2025HPSS: Heuristic Prompting Strategy Search for LLM Evaluatorscited by 5
- 2025Auto-Prompt Ensemble for LLM Judgecited by 5
- 2026Generalizable Self-Evolving Memory for Automatic Prompt Optimizationcited by 5
- 2025P3: Prompts Promote Promptingcited by 3
- 2026Reflection in the Dark: Exposing and Escaping the Black Box in Reflective Prompt Optimizationcited by 3
- 2026Build, Judge, Optimize: A Blueprint for Continuous Improvement of Multi-Agent Consumer Assistantscited by 1
- 2026REVERE: Reflective Evolving Research Engineercited by 1
- 2026ContraPrompt: Contrastive Prompt Optimization via Dyadic Reasoning Trace Analysiscited by 1
Built on by
Citing papers per year: 2026: 1.
1 paper.
Similar, not cited
Close in wording, no citation either way
- 2026Coding Agents are Strong Prompt Optimizers
- 2026SePO: Self-Evolving Prompt Agent for System Prompt Optimization
- 2024Minstrel: Structural Prompt Generation with Multi-Agents Coordination for Non-AI Experts
- 2026Environment-Grounded Automated Prompt Optimization for LLM Game Agents
- 2025AutoPDL: Automatic Prompt Optimization for LLM Agents
- 2024PRompt Optimization in Multi-Step Tasks (PROMST): Integrating Human Feedback and Heuristic-based Sampling
- 2026The Optimizer Is the Agent: Reasoning-Driven Search across Prompts, Programs, and ML Workflows
- 2026Prompt Codebooks: Discrete Compositional Optimization for Language Model Instruction Refinement