Learned Optimizers

Can we generate suitable instructions or agent configurations for a new problem without testing many candidates every time? Here, the learned component is not the target model solving problems, but the generator of prompts or execution structures supplied to it. Even with a fixed large language model (LLM), the generator’s weights can be trained. This distinction makes harness optimization and model training compatible rather than mutually exclusive.

Training a generator does not, however, mean learning the entire optimizer, including search, evaluation, and acceptance. Checking generated code for executability, deciding which candidates to retain, and restarting search after failure often remain separate fixed procedures. This chapter first compares discrete-prompt policies with preference learning, then turns to question-specific multi-agent system generation. Its central studies are RLPrompt at EMNLP 2022, MePO at EACL 2026, MAS-GPT at ICML 2025, and MAS-Architect at ICML 2026. FlowReasoner, a workshop paper, and Harness-R1, a preprint, supplement them by illustrating differences in learning targets and evaluation.

From Searching for Candidates to Learning to Generate Them

For a mathematics problem, possible configurations include solving alone, having another agent check the result, or combining several solutions. In outer-loop search with a fixed LLM proposer, candidates are executed and their results returned to the history to inform the next proposal. The history and candidate collection change, but the proposing model’s weights do not. A trained generator instead changes the probability of its next configuration using past problem–configuration pairs or rewards from executing configurations.

Let \(q\) be a problem, \(h\) the generated instruction, configuration, or code, \(G_\theta(h\mid q)\) the generator, and \(T_\phi\) the fixed target model. With execution reward \(R\), reinforcement learning (RL) of the generator conceptually takes the following form.

\[ \max_\theta\;\mathbb{E}_{q\sim D,\,h\sim G_\theta(\cdot\mid q)} \left[R\bigl(\operatorname{Exec}(T_\phi,h,q)\bigr)\right], \qquad \phi\text{ is fixed}. \]

This equation does not equate the papers’ individual losses. Supervised learning imitates token sequences for good configurations. Preference learning adjusts the relative probabilities of preferred and dispreferred rewrites. RL updates generation probabilities from execution rewards. None necessarily requires numerical gradients through the target. Even when outputs are discrete code or strings, gradients can be computed for the weights of the policy generating them.

Learning a prompt shared by all problems also differs from generating a configuration per question. The former can distribute a string once learned. The latter requires a generator call for every question, and the execution costs of the resulting agents remain. Table 1 compares these output units and supervision signals.

Table 1: Learning targets and supervision signals in the central studies: RLPrompt (Deng et al. 2022), MePO (Zhu et al. 2026), MAS-GPT (Ye et al. 2025), and MAS-Architect (Huang et al. 2026). This is not a performance ranking across different benchmarks.
Method Learned Component and Output Training Data and Objective Work Remaining on New Problems
RLPrompt Discrete tokens generated through a small policy module Soft Q-learning with rewards from few-shot labels or style evaluation Classification uses a learned shared prompt. Generation tasks also include input-conditioned generation
MePO A 7B prompt-rewriting model Direct preference optimization on preference pairs derived from Alpaca and BPO Rewrite the question and pass it to a fixed answering model
MAS-GPT A 32B question-conditioned system generator Supervised learning on question–code pairs constructed through execution evaluation and consistent mappings Execute the system obtained in one generation
MAS-Architect A model generating declarative structures and node implementations Initialization on correct teacher code, followed by RL using validity, cheating checks, and correctness rewards Generate and execute a question-specific structure and implementation

Learning Discrete Prompts from Rewards or Preferences

Instead of directly replacing individual prompt words, we can train a policy that selects the next word. RLPrompt treats previously generated prompt tokens as the state, the next token as the action, and the target LLM’s result with the completed prompt as the reward. The target model is fixed, as is the body of a small pretrained generator model. Only a small multilayer perceptron (MLP) transforming its internal representations is trained, and the original vocabulary output layer produces the next-token distribution. The paper uses on-policy soft Q-learning. (Deng et al. 2022, secs. 2.2–2.3)

The white model components in Figure 1 remain fixed, while only the small red policy module is updated from rewards. The two target models shown are a masked model and a left-to-right generative model, illustrating how the same token-generation mechanism connects to different targets.

The original RLPrompt diagram places a small trainable MLP within a fixed language model and returns rewards from running the target with its generated prompt to that MLP.
Figure 1: RLPrompt’s fixed models and learned policy. The red MLP generates discrete prompts and is updated from target-model rewards. Reward values in the diagram are explanatory examples from the paper, not aggregate benchmark results (original Figure 1). Source: (Deng et al. 2022)

For classification, a piecewise reward uses the gap between the correct label’s probability and the strongest incorrect label’s probability, placing greater weight on correct classifications. Maximizing only the correct-label probability could reward prompts that ignore the input and assign high probability to one class. For style transfer, rewards assess content preservation and target-style strength. Rewards for several prompts on the same input are normalized by their mean and standard deviation to distinguish input difficulty from prompt quality. (Deng et al. 2022, sec. 2.4)

After training, classification can use a greedily generated discrete string without rerunning the generator each time. Input-conditioned style transfer, by contrast, includes prompt generation per input. The strings need not be natural instructions and may contain ungrammatical word sequences. Discrete representation does not imply clear human-readable meaning.

Experiments likewise require separating a fixed target model from inexpensive inference. On Yelp sentiment style transfer with GPT-2-xl, a five-token RLPrompt scores 61.4 on the main metric \(J\), combining content, style, and fluency, versus 53.4 for a handwritten prompt. Both conditions, however, generate 32 output candidates and select the one with the highest reward. This supports prompt learning under that setup, not equivalent performance from a single output. (Deng et al. 2022, Table 3, §3.2)

Another approach collects preference pairs of good rewrites in advance rather than repeatedly executing the target for rewards. MePO specifies four properties: clarity, precision, concise reasoning instructions, and preservation of the original information. A lightweight model revises prompts accordingly. Starting from Alpaca and BPO, it retains pairs where DeepSeek-R1 rates the revised answer above the original and the pair meets specified quality thresholds. The dataset contains 40,151 examples, including deliberately degraded inputs simulating imperfect user instructions. (Zhu et al. 2026, secs. 2–3, Table 1)

Figure 2 shows three stages: discovering properties, constructing revision data, and training the rewriter. The left-hand bars show property frequencies, not accuracy or the effect of removing each property. The learned component on the right generates rewritten input instructions, not answers themselves.

MePO's three-stage diagram shows property-frequency analysis on the left, revision using four properties in the middle, and preference-based rewriter training and deployment on the right.
Figure 2: MePO’s progression from property analysis to rewriter training. Instructions revised along four properties become preference-learning data (original Figure 4). Source: (Zhu et al. 2026)

Training starts from Qwen2.5-7B-Instruct and uses direct preference optimization (DPO) to make revised prompts more likely than their originals. Answers provide evidence for selecting data. The answering model itself is not trained with DPO. At evaluation, only the test-question portion is rewritten, while demonstrations and other material remain fixed. Unlike RLPrompt’s continual rewards from a particular target, this design learns offline to rewrite diverse questions.

The design allows a local rewriter without an external optimization API at deployment. Data filtering and property discovery still use large evaluation models. Local operation therefore does not imply development without external models. Nor are the four properties universal optimality conditions for every task.

MePO’s Table 4 also compares a training-free condition where static property instructions ask the answering model itself to rewrite the question. Averaged over five task families, Qwen3-8B scores 76.28 without training and 76.88 with MePO. LLaMA2-7B-chat scores 37.13 and 39.66, respectively. Training consistently adds value in these comparisons, but its magnitude depends on the target. Table 5’s property ablations use the training-free template setting. They do not remove individual properties from DPO training data. (Zhu et al. 2026, secs. 4.4–4.5)

Separating Reusable Procedure Generation from Execution-Policy Learning

Learned generators need not create only new question-specific systems. MetaFlowLLM takes two existing tasks and their procedures and generates a higher-level procedure that retains common parts as static operations while delegating differing parts to dynamic agents. MetaFlowGen is initialized with teacher examples whose merged procedure passes tests for every source task. It then uses GRPO with a reward combining the fraction of source tasks solved correctly and the fraction of static operations retained. The latter is relative to the smaller static-operation count of the two input procedures. It is not direct minimization of LLM call counts. (Fan et al. 2025, sec. 3.2, Eqs. 3-5)

Here, training generator weights coexists with updating an experience tree that merges and retrieves generated procedures. Adding nodes to the tree is not itself weight training. Experience Reuse covers the memory unit and retrieval and execution details.

Research training a model to plan during execution should also remain in the comparison. AgentFlow connects a planner, tool executor, verifier, and answer generator through shared memory. The planner selects subgoals and tools. Flow-GRPO distributes final-answer correctness to individual turns and updates the planner from actual multi-turn executions. It generates actions executed immediately, not a configuration later applied to another fixed target. It therefore learns the target-side execution policy’s weights rather than a harness generator for a fixed target. (Li et al. 2026, secs. 3.1–3.2) The trained/frozen distinction in Figure 6 locates learning in the planner rather than in an outer generator of reusable system code.

AgentFlow coordinates a trained planner with frozen execution and verification modules through shared memory; the right panel expands one turn of the rollout.
Figure 6: AgentFlow coordinates a trained planner with frozen execution and verification modules through shared memory; the right panel expands one turn of the rollout. (original Figure 2). Source: (Li et al. 2026)

CoMAS likewise does not learn an outer code generator. Agents exchange answers, critiques, and scores, with complementary rewards assigned to answers and critiques from the scores. A highly rated answer rewards its author, while discovering a fatal error rewards the critic. Invalid scoring formats are penalized, and REINFORCE++ updates the participating agents’ own weights. Interaction provides learning signals without requiring external correct answers every time, but internal scoring may still diverge from actual correctness. Even under the common aim of improving agents, we must specify whose weights change. (Xue et al. 2026, secs. 3.1–3.3) The transition from discussion to reward formulation in Figure 7 shows why the scoring interaction itself becomes part of the learning signal.

CoMAS samples solutions, evaluations, and scores through multi-agent discussion, then converts the scores into rewards for policy optimization.
Figure 7: CoMAS samples solutions, evaluations, and scores through multi-agent discussion, then converts the scores into rewards for policy optimization. (original Figure 2). Source: (Xue et al. 2026)

Evaluating Learned Runtime Patches

Extending outputs from system configurations to runtime patches makes the gap between plausible and effective changes more consequential. Harness-R1, a preprint, trains a specialized model to generate code intervening at episode start, before decisions, before actions, and after feedback, using failure records from a fixed target. Patches supplement input context, normalize or reject actions, and recover from stalled states without changing target-model weights. (Shao et al. 2026, sec. 3)

Initialization uses supervised learning on valid teacher patches that do not worsen performance. During RL, eight candidates are generated from one failure summary. Each is independently installed and the fixed target rerun. The reward is the difference in mean reward over the same complete batch, including originally successful cases as well as failures. Invalid candidates, candidates with no substantive change, and incomplete evaluations receive 0. Measuring changes that break previously successful tasks is important.

This training reward measures improvement on the same batch, not generalization to unseen tasks itself. A separate experiment generates one patch from only 10 failures per environment and applies it to tasks absent from that evidence. Figure 8 shows this evaluation of patch reuse.

Figure 8: Author-reported application of patches derived from 10 failures per benchmark to 1,270 tasks not used as evidence. Success-rate changes are +8.9 percentage points for Harness-R1, −4.3 for Qwen3.5-397B, and −0.4 for DeepSeek-V4-Pro. Whiskers are sample standard deviations across three paired seeds, not confidence intervals (original Figure 4a). Source: (Shao et al. 2026)

This pools the remaining 1,270 tasks across WebShop, ALFWorld, and DBBench. It differs from a separate aggregate that weights environments equally. The changes are +8.9 ± 1.5, −4.3 ± 2.5, and −0.4 ± 3.6 percentage points, respectively. With matched targets and failure evidence, this illustrates a difference between a trained patcher and large fixed patchers. It does not establish independent replication under the same conditions or a general standard evaluation. (Shao et al. 2026, sec. 4.4, Table F.1)

Shifting Costs and Generalization Requirements Through Training

Training a generator shifts search on each new problem into training-time data collection and execution evaluation. Even when generation becomes one-shot, as in MAS-GPT, teacher question–configuration combinations must first be executed. RL requires target execution per candidate, while offline methods such as MePO still incur preference-data and evaluation-model costs. Whether training costs can be amortized across many uses depends not only on usage volume, but also on the stability of target models and tool specifications.

Generalization has two levels. First, do generated instructions or configurations help on new tasks? Second, can the learned generator produce effective configurations for new target models, tools, and failure types? RLPrompt directly uses rewards from a particular target, MePO uses general rewriting pairs, and MAS-GPT and MAS-Architect learn executable structures. Their data and evaluators bear different generalization requirements. A single transfer score obscures these distinctions.

The remaining scientific question is when a trained generator outperforms outer-loop search with a fixed LLM under matched targets, usage counts, data, and total budgets including training and search. Current results demonstrate learnability and effectiveness in specific settings, not that training the optimizer always improves outcomes.

Figure Credits

References

Deng, Mingkai, Jianyu Wang, Cheng-Ping Hsieh, et al. 2022. “RLPrompt: Optimizing Discrete Text Prompts with Reinforcement Learning.” Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing. https://aclanthology.org/2022.emnlp-main.222/.
Fan, Shengda, Xin Cong, Zhong Zhang, et al. 2025. “Generalizing Experience for Language Agents with Hierarchical MetaFlows.” Advances in Neural Information Processing Systems 38, Main Conference: 64103–32. https://doi.org/10.52202/085713-2149.
Gao, Hongcheng, Yue Liu, Yufei He, et al. 2025. “FlowReasoner: Reinforcing Query-Level Meta-Agents.” ICML 2025 Workshop on Multi-Agent Systems in the Era of Foundation Models: Opportunities, Challenges and Futures. https://icml.cc/virtual/2025/49324.
Huang, Jing, Lidong Zhang, Mutian Bao, et al. 2026. “MAS-Architect: Declarative Multi-Agent System Design via Separation of Concerns.” Proceedings of the 43rd International Conference on Machine Learning, Proceedings of machine learning research, vol. 306: 48248–73. https://proceedings.mlr.press/v306/huang26by.html.
Li, Zhuofeng, Haoxiang Zhang, Seungju Han, et al. 2026. “In-the-Flow Agentic System Optimization for Effective Planning and Tool Use.” International Conference on Learning Representations 2026: 50524–70. https://proceedings.iclr.cc/paper_files/paper/2026/hash/52c4a736cd63b3c7bf52011a1f66f3f6-Abstract-Conference.html.
Shao, Shuai, Kangning Zhang, Qingyao Li, et al. 2026. Harness-R1: Learning to Edit Executable Runtime Harnesses from Agent Failure Trajectories. https://arxiv.org/abs/2608.02276.
Xue, Xiangyuan, Yifan Zhou, Guibin Zhang, et al. 2026. “CoMAS: Co-Evolving Multi-Agent Systems via Interaction Rewards.” International Conference on Learning Representations 2026: 32373–94. https://proceedings.iclr.cc/paper_files/paper/2026/hash/372593bd318ad8b34b3a8da77e20272b-Abstract-Conference.html.
Ye, Rui, Shuo Tang, Rui Ge, et al. 2025. “MAS-GPT: Training LLMs to Build LLM-based Multi-Agent Systems.” Proceedings of the 42nd International Conference on Machine Learning, Proceedings of machine learning research, vol. 267: 72063–90. https://proceedings.mlr.press/v267/ye25g.html.
Zhu, Zixiao, Hanzhang Zhou, Zijian Feng, et al. 2026. “Rethinking Prompt Optimizers: From Prompt Merits to Optimization.” Proceedings of the 19th Conference of the European Chapter of the Association for Computational Linguistics (Volume 1: Long Papers) (Rabat, Morocco), 864–92. https://doi.org/10.18653/v1/2026.eacl-long.38.