TL;DR
MemAPO shifts the automatic prompt optimization paradigm from a one-off, task-specific search to a continuous, self-evolving experience accumulation process. By maintaining a dual-memory mechanism of successful strategy templates and structured error patterns, it allows LLMs to reuse prompting knowledge across heterogeneous tasks, significantly outperforming traditional baselines while slashing optimization costs by over 55%.
What Problem Does This Paper Address?
Automatic Prompt Optimization (APO) has emerged as a powerful way to bypass the tedious, labor-intensive process of manual prompt engineering. However, most existing APO frameworks treat prompt optimization as a discrete search problem tailored to a single, fixed task distribution.
This traditional paradigm suffers from two major flaws:
- Instability: The prompt space is massive and highly stochastic; minor wording tweaks can cause erratic shifts in LLM behavior.
- Inability to Generalize: Treating tasks in isolation means the system cannot accumulate transferable knowledge. If you optimize a prompt for a math task, that optimization process typically starts completely from scratch when you move to a logic or history task.
The authors introduce MemAPO (Memory-driven Automatic Prompt Optimization) to address this gap, transforming prompt engineering from an externally supervised search into an internal, lifelong capability of experience accumulation.
Methods
MemAPO introduces a structured Dual-Memory Mechanism that mimics human cognitive schemas by separating positive guidance from negative constraints:
- Correct-Template Memory (CTM): Distills successful reasoning trajectories into abstract, reusable strategy templates. By decoupling the core reasoning strategy from the specific query instance, these templates can be transferred to semantically similar tasks.
- Error-Pattern Memory (EPM): Instead of storing raw incorrect answers, this component abstracts failures into high-level reflective rules that describe recurring failure modes and how to avoid them.
The framework operates in three distinct stages:
- Stage I: Memory Retrieval: Given a new query, MemAPO uses semantic embeddings to fetch the top-$k$ relevant strategy templates from the CTM and applies global error rules from the EPM to construct an augmented prompt.
- Stage II: Prompt Evaluation: The target LLM attempts the task. If it fails, an iterative self-reflection loop triggers, generating corrective feedback and retrying up to a set limit.
- Stage III: Memory Update: Based on the final outcome, the memory is updated. Successful runs can add, update, or merge templates in the CTM (following a verification step on sampled historical cases). Failed runs generate a new or refined error pattern in the EPM.
Crucially, during inference, the self-reflection loop is bypassed. The system performs a highly efficient, single-pass generation using the retrieved memories.
Datasets
The authors evaluated MemAPO across six diverse sub-tasks spanning three distinct domains:
- Logical Reasoning: Geometric Shapes from Big-Bench Hard (BBH) and Big-Bench Extra Hard (BBEH).
- Mathematical Calculation: AQuA-RAT and Gaokao-MathQA from the AGIEval benchmark.
- Knowledge-Intensive Reasoning: Gaokao-Geography and Gaokao-History from AGIEval.
Tasks from similar domains were merged into unified training sets to test the framework's ability to handle heterogeneous query distributions.
Key Insights and Ideas
- Success vs. Failure Synergy: An ablation study revealed that CTM and EPM are highly complementary. CTM provides positive directional guidance, while EPM sets boundaries to prevent repeating known mistakes. Combining both yielded the highest accuracy gains.
- The "Less is More" Template Sweet Spot: More memory isn't always better. The authors found that performance peaks when retrieving exactly the top-3 templates. Retrieving too many templates introduces context noise and increases the cognitive load on the LLM, leading to instability and higher token costs.
- Cross-Domain Robustness: Traditional APO methods often suffer severe performance drops when tasks from completely different domains (e.g., Math and History) are mixed together, because a single static prompt cannot reconcile conflicting reasoning demands. MemAPO avoids this by dynamically retrieving query-dependent memories.
Key Results
MemAPO was tested using both proprietary (GPT-4o-mini) and open-source (Qwen3-8B) backbones, consistently outperforming strong baselines like TextGrad, OPRO, and ProTeGi.
- Performance Boost: On GPT-4o-mini, MemAPO achieved an average accuracy of 70.7% across all tasks, outperforming the strongest baseline (TextGrad) by 7.1%. On Qwen3-8B, it achieved a leading 70.6% average accuracy.
- Cost Reduction: Because MemAPO amortizes optimization costs through experience reuse, it dramatically reduces token consumption and API calls. It cut optimization costs by 57.2% compared to TextGrad.
Limitations and Future Work
The current implementation of MemAPO focuses exclusively on textual reasoning tasks and language-based prompt optimization. The authors note that the framework does not explicitly model multimodal information (such as visual, audio, or structured environmental signals). Extending this self-evolving memory architecture to support multimodal experiences is highlighted as a promising direction for broader agentic environments.
Summary updated