cd /news/artificial-intelligence/spear-code-augmented-agentic-prompt-… · home topics artificial-intelligence article
[ARTICLE · art-14917] src=arxiv.org pub= topic=artificial-intelligence verified=true sentiment=↑ positive

SPEAR: Code-Augmented Agentic Prompt Optimization

Researchers introduced SPEAR (Sandboxed Prompt Engineer with Active Roll-back), a code-augmented agentic optimizer that autonomously rewrites prompts using a Python sandbox for structural error analysis, outperforming existing methods across three industrial LLM-as-judge suites, seven BBH tasks, and GSM8K. The system achieved a kappa of 0.857 versus 0.359 on tool-selection tasks and 0.938 accuracy on BBH-7 compared to GEPA's 0.628. Ablations confirmed the Python tool as the largest performance driver, enabling class-pair confusion aggregation that long-context LLMs cannot reliably extract from raw evaluation data.

read1 min publishedMay 27, 2026

arXiv:2605.26275v1 Announce Type: new Abstract: 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, set_prompt, 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 \approx +0.79\kappa$ on the 5-class tool-selection judge, $\Delta \approx +0.35\kappa$ 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.

── more in #artificial-intelligence 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/spear-code-augmented…] indexed:0 read:1min 2026-05-27 ·