MASPO: Joint Prompt Optimization for LLM-based Multi-Agent Systems
Zhexuan Wang 1 Xuebo Liu 1 # Li Wang Zifei Shan Yutong Wang 1 Zhenxi Song 1 Min Zhang 1
arXiv:2605.06623v1 [cs.AI] 7 May 2026
Abstract
paradigm for solving multi-stage problems. By orchestrating heterogeneous agents (Liang et al., 2024; Wang et al., 2025a; Du et al., 2024; Zhuge et al., 2024) to communicate and collaborate, MAS often surpass the capabilities of single-agent counterparts. Within such systems, the design of agent-specific prompts is critical, as they not only define the distinct roles of each agent but also govern their interaction dynamics and reasoning trajectories. However, despite their critical importance, the joint optimization of these prompts remains a non-trivial challenge. Unlike singleagent scenarios, MAS optimization involves a combinatorial search space where the optimality of one agent’s prompt depends intrinsically on the behaviors of others.
Large language model (LLM)-based Multi-agent systems (MAS) have shown promise in tackling complex collaborative tasks, where agents are typically orchestrated via role-specific prompts. While the quality of these prompts is pivotal, jointly optimizing them across interacting agents remains a non-trivial challenge, primarily due to the misalignment between local agent objectives and holistic system goals. To address this, we introduce MASPO, a novel framework designed to automatically and iteratively refine prompts across the entire system. A core innovation of MASPO is its joint evaluation mechanism, which assesses prompts not merely by their local validity, but by their capacity to facilitate downstream success for successor agents. This effectively bridges the gap between local interactions and global outcomes without relying on ground-truth labels. Furthermore, MASPO employs a data-driven evolutionary beam search to efficiently navigate the high-dimensional prompt space. Extensive empirical evaluations across 6 diverse tasks demonstrate that MASPO consistently outperforms state-of-the-art prompt optimization methods, achieving an average accuracy improvement of 2.9. We release our code at https: //github.com/wangzx1219/MASPO.
Typically, MAS operate through the collaboration of specialized agents. While existing prompt optimization methods typically rely on labeled data to evaluate prompt quality, this paradigm is ill-suited for MAS (Fernando et al., 2024a; Yuksekgonul et al., 2024). In collaborative settings, specific agents may be tasked with intermediate steps, such as reasoning, reflection, or summarization rather than generating the final output. This leads to a severe credit assignment problem. A critical failure mode in MAS is Local-Global Misalignment, where an intermediate agent satisfies its local instructions perfectly but generates outputs that mislead downstream peers, causing system-wide failure. Although recent self-supervised strategies (Xiang et al., 2025) leverage comparative feedback to assess reasoning quality, they remain confined to an isolated scope, failing to capture how local variations propagate to influence global system outcomes. In the context of MAS, recent works (Opsahl-Ong et al., 2024; Zhou et al., 2025) have introduced Bayesian search strategies utilizing Tree-structured Parzen Estimators (TPE). However, these methods are restricted to selecting prompts from a fixed, discrete candidate pool, thereby limiting their capacity for open-ended optimization and finegrained adjustment. Consequently, there is an urgent need for a robust framework capable of automating prompt generation in dynamic multi-agent environments.
1. Introduction Recent advancements in LLMs (Achiam et al., 2023; Team et al., 2024) have exhibited exceptional capabilities in context understanding, instruction following, and complex reasoning, demonstrating strong performance across various tasks and scenarios. Building upon these foundations, Multi-Agent Systems (MAS) have emerged as a powerful
To address these challenges, we propose MASPO, a joint prompt optimization framework tailored for multi-agent environments. MASPO introduces three key innovations. First, to resolve the credit assignment dilemma, we design a multi-granularity joint evaluation mechanism that integrates Local Validity, Lookahead Potential, and Global Alignment,
1
Institute of Computing and Intelligence, Harbin Institute of Technology, Shenzhen, China. Correspondence to: Xuebo Liu <[email protected]>. Proceedings of the 43 rd International Conference on Machine Learning, Seoul, South Korea. PMLR 306, 2026. Copyright 2026 by the author(s).
1
MASPO: Joint Prompt Optimization for LLM-based Multi-Agent Systems
where Nin (vi ) denotes the set of predecessors of vi . Here, ⊕ denotes the concatenation operation applied in a fixed topological order, and Ci represents the aggregated context. oi is the resulting output conditioned on the role-specific agent’s prompt pi .
assessing an agent’s utility through its contribution to the entire causal chain rather than isolated outputs. Second, we introduce Misalignment-Aware Sampling, a targeted technique that explicitly mines and injects historical traces where coordination failed despite local success, guiding the optimizer to diagnose and rectify specific interaction breakdowns. Third, regarding the co-adaptation protocol, we implement a coordinate ascent-style strategy augmented with a Beam Refresh mechanism, which ensures stability by realigning the search tree of each agent in real-time to mitigate the non-stationarity caused by peer agents.
2.2. Prompt Optimization Prompt optimization aims to automate the discovery of optimal instructions that maximize the performance of LLMs on downstream tasks. In the context of our defined MAS, this objective extends from optimizing a single string to jointly optimizing the set of role-specific prompts P. Let |D| D = {(qk , yk∗ )}k=1 be a dataset consisting of input queries and their corresponding ground-truth labels (or reference answers). The execution of the multi-agent system G on a query q, governed by the prompt configuration P, produces a final system response oglob . We abstract this complex interaction process as a composite function Φ:
Extensive experiments conducted across diverse domains demonstrate that MASPO consistently delivers significant performance gains over existing baselines. Our primary contributions are summarized as follows: • Multi-Granularity Joint Evaluation: We introduce a composite evaluation metric that resolves the credit assignment dilemma in MAS. By synergizing Local Validity, Lookahead Potential, and Global Alignment, our approach captures the full causal impact of an agent within the collaborative chain.
oglob = Φ(G, P, q).
(2)
Here, oglob represents the final output from multiple agents, derived through the topological propagation defined in Eq. (1). The goal of MAS prompt optimization is to identify the optimal configuration P ∗ that maximizes the expected performance over the data distribution:
• Misalignment-Driven Generative Search: We design a beam search strategy explicitly guided by Misalignment Cases—scenarios where agents fulfill local roles but induce system-wide failure. • Adaptive Optimization Dynamics: We propose a coordinate ascent-based scheduling protocol augmented with a Beam Refresh mechanism. These techniques effectively mitigate the non-stationarity inherent in multiagent interactions, ensuring that each agent adapts to the evolving behaviors of its peers.
P ∗ = argmax E(q,o∗glob )∼D R Φ(G, P, q), o∗glob , (3) P∈S N
where S denotes the discrete space of natural language strings (prompts), N is the number of agents, and R(·, ·) is a scalar scoring function measuring the alignment between the prediction of the system and the ground truth. However, directly optimizing this objective is non-trivial. Since agents fulfill different intermediate roles, the final ground truth o∗glob provides only sparse supervision and does not effectively assign credit to individual steps. To address this, we employ a self-supervised evaluation mechanism as a proxy, which is detailed in Section 3.
2. Preliminary 2.1. LLM-Based Multi-Agent Systems Adopting the graph-theoretic perspective from the recent literature (Chan et al., 2024; Jiang et al., 2023; Wu et al., 2023), we formalize the MAS as a directed communication graph G = (V, E). Here, V = {vi }N i=1 represents the set of N agents, and the edge set E ⊆ V × V defines the communication topology. A directed edge (vj , vi ) ∈ E signifies that the output of agent vj serves as input context for agent vi . We equip each agent vi with an LLM-based inference function fi ∈ F and, crucially, a specific system prompt pi . We denote the set of all prompts as P = {pi }N i=1 , which constitutes the primary learnable parameters in our optimization framework. Given a global task query q, the generation process for a specific agent vi is formulated as: M oi = fi (pi , q, Ci ) , with Ci = oj , (1)
This optimization problem presents unique challenges compared to single-agent settings. First, the search space S N is combinatorial and high-dimensional. Second, the objective function is non-differentiable with respect to P due to the discrete nature of language tokens, precluding standard gradient-based updates. Crucially, the agents are functionally coupled: modifying the prompt pj of an upstream agent vj alters the input context Ci for downstream agent vi . This induces a covariate shift in the input distribution that vi faces, creating a non-stationary optimization landscape that necessitates a joint optimization strategy rather than the independent tuning of individual agents.
vj ∈Nin (vi )
2
MASPO: Joint Prompt Optimization for LLM-based Multi-Agent Systems
LLM Evaluator
Generating
Local-level
Prompt Prompt Optimizer Query
Lookahead-level
Output
Samples
Global-level
Context
…
Prompt Trace-Guided Beam Search
Misalignment Case
0.6
0.5
Eq.(6)
0.1
0.6
0.6
0.4
0.8
Joint Reward Model
TopK 0.8
Eq.(5)
Construct Search Tree
0.3
0.5+0.6+0.8=1.9
0.7
0.2
…
0.6+0.8+0.7=2.1
Figure 1. Overview of the MASPO Framework. The optimization proceeds sequentially following the topological order of the agent graph (Top-Right). (Top) For a specific target agent, the Prompt Optimizer analyzes execution traces (context C and output o) from sampled batches Biter ∪ Bmis to generate candidate prompts Pcand . These candidates are rigorously assessed by the LLM Evaluator across three distinct dimensions: local adherence, lookahead potential, and global alignment. (Bottom-Left) To resolve credit assignment, we synthesize these evaluations into a Joint Reward Model. Crucially, we identify and mine Misalignment Cases to explicitly guide the optimizer towards repairing coordination breakdowns. (Bottom-Right) Navigating the high-dimensional search space, the framework employs a Trace-Guided Beam Search. This mechanism maintains a beam of Top-K candidates, accumulating joint reward scores along the path to iteratively evolve and select the optimal prompt.
3. Multi-Agent System Prompt Optimization
Trace-Guided Generation With the target agent fixed, we employ a data-driven generation strategy to explore the prompt space. Unlike blind mutation, our approach grounds offspring generation in actual execution traces. For a parent prompt p, we sample a batch Biter to collect traces Tparent = {(qk , Ck , ok )}k∈Biter . Here, Ck captures the specific incoming context, explicitly modeling the dependency on inter-agent communication. We partition these traces into mini-batches and treat them as few-shot contexts for the Optimizer Model Mopt . Mopt is instructed to analyze the mapping from input context (q, C) to output o, and propose a variation p′ that enhances the reasoning logic:
We present MASPO, a framework designed to navigate the non-stationary and combinatorial landscape of multi-agent prompt optimization. As illustrated in Figure 1, our workflow follows a systematic loop: it orchestrates agents via a topological protocol, generates candidates through trace analysis, evaluates them using a multi-granularity reward, and evolves the population via an adaptive beam search. 3.1. Topological Context and Trace-Guided Proposal Topological Scheduling Strategy Optimizing the entire MAS simultaneously is intractable due to the functional coupling between agents. To manage this, we adopt a coordinate ascent-style strategy that respects the causal dependencies of the MAS. We iterate through the agents {v1 , . . . , vN } following the topological order of the communication graph G. Unlike standard sequential optimization that fully converges one agent before moving to the next, we employ an interleaved evolution protocol. In each topological turn, we optimize the target agent for a limited number of generations, denoted as the step size T , before freezing it and moving to the successor. This process is repeated for D rounds. This interleaved scheduling prevents upstream agents from overfitting to the initial, suboptimal behaviors of downstream peers, thereby stabilizing the co-adaptation process.
Pcand =
K[ sub
{p′ | p′ ∼ Mopt (pparent , τm )} ,
(4)
m=1
where τm is a subset of traces. Crucially, to address coordination failures, we employ Misalignment Sampling. We maintain a memory buffer Bmis of “Misalignment Cases” (defined in Sec. 3.2), the scenarios where local validity coexists with ineffective downstream adaptation. During generation, we prioritize injecting Kmis samples from Bmis . By exposing Mopt to these hard negatives, we force the generation of offspring that specifically bridge the gap between local instructions and global system goals. The detailed prompt of Mopt is provided in Appendix A. 3
MASPO: Joint Prompt Optimization for LLM-based Multi-Agent Systems
3.2. Joint Reward Modeling and Misalignment Mining
Trace-Guided Beam Search. For each optimization step, we maintain a beam of top-K candidates. Each candidate p′ ∈ Pcand is evaluated on Biter , and we calculate the cumulative performance gain by adding the joint reward scores to the parent score:
Once candidate prompts are generated, evaluating their quality presents a severe credit assignment challenge. The output oi of an upstream agent acts as the input context for downstream agents; thus, relying solely on local validity or final outcome alignment creates an evaluation gap.
J(p′ ) = R(p′ , pparent ; Biter ) + J(pparent ).
This accumulation mitigates the noise of individual samples and enriches the candidate diversity, thereby expanding the search space and allowing us to retain the most robust prompts for the next iteration.
Multi-Granularity Joint Reward To bridge this gap, we employ a composite scoring function R(pcand , pref ; B) that evaluates the candidate prompt against a reference. The resulting score is a weighted combination of three improvement indicators: " 1 X α · I (o′i ≻ oi ) +θ · I o′glob ≻ oglob R= | {z } |B| {z } | k∈B Local Validity
Beam Refresh Mechanism A pivotal challenge in MAS optimization is score staleness. Prompts retained in the beam of Agent vi were evaluated based on contexts generated by obsolete versions of upstream agents. As peer agents evolve during the topological traversal, the input distribution for vi shifts (covariate shift), rendering historical scores unreliable. To explicitly address this, we discard the stale cumulative scores when an agent is re-visited in a new epoch. We re-anchor the beam by evaluating the relative advantage of each candidate against the current global best prompt pbest (serving as a baseline). We define the refreshed score as the centered win-rate:
Global Alignment
X 1 +β · I o′j ≻ oj |Nout (vi )| vj ∈Nout (vi ) {z } |
(5)
#(k)
(7)
,
Lookahead Potential
where Local Validity measures whether the candidate’s output o′i satisfies role-specific constraints better than the baseline. Lookahead Potential is a topology-aware metric that quantifies the “ripple effect” by evaluating whether downstream agents {vj } produce better outputs o′j when fed with the new context generated by vi , thereby ensuring the prompt produces context useful for immediate successors. Global Alignment measures the impact on the final system response oglob , capturing long-range dependencies across the entire agent chain. Nout (vi ) denotes the set of immediate successor agents, and ≻ represents a preference judgment derived from the Evaluator Model Meval , whose detailed prompt can be found in Appendix B.
Jnew (p) = R(p, pbest ; Biter ) − 0.5,
(8)
where subtraction of 0.5 centers the metric around zero, ensuring that prompts performing worse than the baseline receive negative rewards. By resetting the history, this recalibration ensures the beam search resumes from a valid, up-to-date performance manifold. A detailed description of the algorithm can be found in Appendix C. 3.4. Discussion
Mining Misalignment Cases This joint evaluation mechanism allows us to explicitly identify Local-Global Misalignment. A sample k is identified as a misalignment case if the agent satisfies its local objective but fails to support the system:
Recent literature (Wang et al., 2025b; Schmidgall et al., 2025; Xiang et al., 2025) has established that the relative efficacy of prompts can be determined solely by comparing the quality of LLM inference outputs, largely independent of ground-truth labels. Building on this insight, our approach utilizes a small set of unlabeled samples for iterative prompt evolution and evaluation, thereby significantly enhancing practical applicability. In our experiments, we restrict the sample pool to only a few dozen instances. During each optimization iteration, we randomly sample a mini-batch of size |B| = 10 from the pool for trace collection and joint evaluation. This design effectively minimize both the computational overhead and data annotation requirements.
I(o′i ≻ oi )(k) = 1 AND I(Lookahead)(k) = 0 ∨ I(o′glob ≻ oglob )(k) = 0 . (6) (k)
where I(Lookahead) equals 1 if the Lookahead Potential (defined in Eq. 5) is 1. These identified cases are stored in Bmis and fed back into the proposal stage (Sec. 3.1) to guide the optimizer in repairing specific interaction breakdowns.
4. Experiments
3.3. Evolutionary Beam Search with Adaptive Dynamics
4.1. Experimental Setup
To navigate the high-dimensional prompt space efficiently, we integrate the components above into an evolutionary beam search augmented with a dynamic refresh mechanism.
Models and Benchmarks We conduct experiments using Qwen3-8B (Yang et al., 2025) as the backbone model 4
MASPO: Joint Prompt Optimization for LLM-based Multi-Agent Systems Table 1. Performance comparison of MASPO against baselines and other optimization methods. Prompt Opt. denotes optimizing prompts for individual agents, while Joint Opt. indicates the joint optimization of agents within the MAS. Method Vanilla CoT SC (CoT) Self-Refine AgentDropout Sequential MAS + TPE + SPO + MASPO Hierarchical MAS + TPE + SPO + MASPO
Prompt Opt.
Joint Opt.
% % % % % % " " " % " " "
% % % % % % % % " % % % "
MATH-500 74.80 75.40 75.50 76.20 76.80 75.10 75.80 77.20 77.80 77.60 77.60 77.80 78.40
AGIEval-MATH 55.86 54.69 56.64 56.52 59.77 59.38 58.73 60.13 61.98 59.38 60.68 63.41 64.45
AQuA 79.53 81.89 82.17 82.28 86.23 83.47 84.92 81.10 85.56 87.01 86.45 86.61 87.01
GPQA 45.96 46.72 47.52 47.73 47.98 47.73 48.04 49.52 58.08 50.63 49.49 51.01 54.04
MBPP 63.47 64.17 64.49 64.17 58.09 57.26 61.30 63.47 65.11 63.93 64.32 61.83 65.34
HumanEval-ET 71.95 72.26 72.56 70.73 72.44 68.90 70.12 67.94 73.78 71.34 71.73 73.39 76.83
Avg. 65.27 65.86 66.48 66.27 66.89 65.31 66.49 66.56 70.39 68.32 68.47 69.01 71.05
of MAS, both configured in standard inference mode to exclude intrinsic reasoning enhancements. To comprehensively assess system performance, we employ a diverse suite of benchmarks across three domains: (1) Mathematical Proficiency: MATH-500 (Hendrycks et al., 2021), AQuA (Patel et al., 2021), and the Level-5 subset of AGIEval-MATH (Zhong et al., 2024); (2) Complex Reasoning: the challenging GPQA-Diamond dataset (Rein et al., 2024); and (3) Code Generation: MBPP (Austin et al., 2021) and HumanEval-ET (Dong et al., 2025). Furthermore, we utilize Gemini-2.5-pro (Comanici et al., 2025) as the engine for both the optimizer and evaluator modules.
beam, we generate Ksub = 2 candidate variations. We balance the components of the joint reward model by setting α = 0.4, β = 0.4, θ = 0.2. Furthermore, to prioritize error correction while maintaining batch diversity, we set the maximum capacity for retrieved misalignment cases to Kmis = 3. Regarding the scheduling dynamics, we set the step size for each topological round to T = 3, and also set the number of rounds D = 3 to ensure that the agent can adapt to the constantly changing cues from its peers. Detailed specifications regarding the initial agent roles, prompt templates, and the architectural configurations for the MAS baselines are provided in Appendix D.
Baselines In single-agent scenarios, we compare with the direct reasoning method, known as Vanilla, Chainof-Thought (CoT, Wei et al., 2022) approach, CoT with self-consistency (SC (CoT), Wang et al., 2023) and SelfRefine (Madaan et al., 2023). For multi-agent collaboration tasks, we establish baselines using two distinct architectures: a Sequential MAS and a Hierarchical MAS (Zou et al., 2025). To ensure a rigorous comparison, we further apply the Tree-structured Parzen Estimator (TPE) used in MIPRO (Opsahl-Ong et al., 2024) and MASS (Zhou et al., 2025) to optimize these MAS configurations. Furthermore, we incorporate SPO as an optimization baseline; despite being a single-agent prompt optimizer, its unsupervised optimization mechanism allows it to be adapted to MAS.
4.2. Main Result MASPO outperforms other baselines on multiple benchmarks We observe that MASPO-optimized MAS significantly surpass standard single-agent inference strategies, such as CoT and Vanilla prompting. More importantly, MASPO outperforms heuristic-based collaborative paradigms, including Self-Consistency, Self-Refine, and topological optimization methods like AgentDropout (Wang et al., 2025e). Unlike these static approaches, which rely on fixed role and prompts, MASPO dynamically tailors the interaction logic via prompt evolution, enabling agents to handle intricate dependencies that heuristic methods often overlook. When compared against state-of-the-art prompt optimization techniques, MASPO demonstrates a substantial advantage. While TPE and single-agent adapters SPO provide marginal gains, they often struggle with the nonstationary nature of multi-agent environments. By leveraging joint reward modeling and misalignment-aware sampling, MASPO achieves an average accuracy improvement of 2.90 over the best-performing optimization baselines. This result highlights the efficacy of our method in resolving the credit assignment problem.
Implementation Details For the inference of backbone model of agents, we set the sampling temperature to 0. Regarding the optimization framework, we configure the Optimizer Model Mopt with a temperature of 0.7 to encourage diverse prompt exploration, while the Evaluator Model Meval operates at a temperature of 0. All models are deployed in non-thinking inference mode. During the iterative optimization phase, we maintain a sample pool of size |D| = 50. The evolutionary search is governed by a beam width of K = 2, and for each parent prompt in the
MASPO demonstrates stability across different topologies We applied MASPO to both Sequential and Hierarchi5
MASPO: Joint Prompt Optimization for LLM-based Multi-Agent Systems Table 2. Comprehensive analysis of MASPO through extensive ablation studies and sensitivity analyses. We examine the framework across eight dimensions, organized into three groups: core mechanism contributions (I–IV), covering the search strategy, scheduling strategy, joint evaluation, and misalignment-aware sampling (with sensitivity to Kmis ); design-choice sensitivities (V–VI), including the lookahead depth and computational budget; and external robustness validations (VII–VIII), assessing the impact of a weaker optimizer/evaluator backbone (Qwen3-8B) and sub-optimal prompt initialization. Method
MATH-500 AGIEval-MATH AQuA GPQA MBPP HumanEval-ET Reference: Proposed Framework MASPO (Full) 77.80 61.98 85.56 58.08 65.11 73.78 I. Effectiveness of Search & Scheduling Strategies Serial Search 77.20 58.95 87.01 50.83 65.11 69.51 Single Cycle 75.50 59.77 85.24 50.51 65.58 72.56 Single Agent + SPO 75.60 61.67 81.89 47.59 61.87 72.51 + Our Proposed Beam Search 76.00 62.11 86.59 51.02 64.40 73.10 II. Contribution of Core Components w/o Beam Refresh 76.50 59.77 85.24 52.51 64.58 72.56 w/o Joint Evaluate 76.20 60.13 84.85 51.01 63.70 70.73 w/o Misalignment Sampling 77.60 62.89 86.61 52.53 65.28 73.17 III. Sensitivity to Misalignment Cases (Default Kmis = 3) w/ Success-Case Sampling 77.20 61.63 86.52 51.51 65.11 73.78 w/ 2 Misalignment Cases 77.40 64.45 87.01 53.03 64.17 72.56 w/ 4 Misalignment Cases 77.60 60.13 85.83 55.41 64.64 74.73 w/ 5 Misalignment Cases 78.80 60.55 86.61 51.01 67.03 75.00 IV. Robustness to Prompt Initialization w/ Minimal Initialization 77.20 62.23 86.61 56.06 64.64 72.95 w/ Wrong-Domain Initialization 77.00 61.62 85.86 55.56 65.11 73.17 V. Impact of Lookahead Depth (Default 1-step) w/ 2-step Lookahead 78.00 62.33 85.86 57.58 64.04 74.73 w/ 3-step Lookahead 77.80 62.65 84.85 57.07 65.11 75.00 VI. Impact of Computational Budget SPO + Same Search Budget 76.80 61.33 84.85 50.51 63.70 69.52 SPO + Same Gemini Budget 77.60 60.67 85.04 51.01 63.93 68.90 VII. Impact of Optimizer and Evaluator Backbone (Self-Optimized via Qwen3-8B) Self-Optimized 77.00 58.92 84.58 48.48 64.64 72.56
cal MAS structures to assess the architectural adaptability of our framework. Empirical results indicate that our approach is topology-agnostic, yielding performance gains in both settings.Specifically, compared to the respective baselines, MASPO improves the average task accuracy of Sequential MAS by 5.06 and Hierarchical MAS by 2.73. A case study of the optimized prompt is provided in Appendix E.
Avg. 70.39 68.10 68.19 66.86 68.87 68.53 67.77 69.68 69.29 69.77 69.72 69.83 69.95 69.72 70.42 70.41 67.79 67.86 67.70