arXiv:2610.24823cs.LGOct 2026

Manuscript Offprint

arXiv:2610.24823

Pair-Aware Optimization: Coordinating Exploration and Refinement for Jailbreaking LLM Agents

Juanyang Xu, Zheng Wang, Xingyu Zhao, Siddartha Khastgir, Andi Zhang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large Language Model (LLM) agents are vulnerable to adversarial inputs that induce attacker-specified malicious behaviors, commonly referred to as jailbreaking. Existing optimization-based jailbreak attacks primarily employ first-order (FO) methods that leverage gradient information or zeroth-order (ZO) methods that rely on function-value feedback. However, their complementarity and optimization ordering remain underexplored. We systematically investigate four strategies: pure ZO, pure FO, ZO→FO, and FO→ZO, and develop a ZO-FO framework that explores adversarial prefixes through ZO optimization and refines their corresponding suffixes through FO optimization. To coordinate the two processes, we introduce Pair-aware optimization, which retains multiple prefix candidates, conditionally refines their suffixes and selects among the resulting prefix-suffix pairs. We further investigate agent jailbreaking from a more general stochastic-generation perspective, where the same adversarial input can induce diverse reasoning trajectories and actions that a single greedy output cannot capture. Accordingly, we adopt consistent stochastic decoding during both optimization and evaluation. Experiments across malicious-instruction and malicious-environment benchmarks demonstrate that hybrid optimization improves attack effectiveness over single-optimizer methods, while optimization order substantially influences performance. Code is available at https://github.com/Haxlon/pair-aware.git.

1 Introduction

Optimization-based jailbreak attacks search for adversarial inputs that induce attacker-specified responses or behaviours. While many existing attacks are developed around a single greedy generation, stochastic decoding allows the same input to induce diverse reasoning trajectories, tool calls, and final actions (Beyer et al., 2026; Zhang et al., 2025a). We therefore study the more general stochastic setting, using the same decoding distribution during optimization and evaluation (Chao et al., 2024; Andriushchenko et al., 2025; Zhan et al., 2024). This setting poses a practical challenge: adversarial inputs are discrete, while their quality must be estimated from sampled behaviours, raising the question of how to efficiently optimize the attack space under a distributional objective.

Existing optimization-based attacks mainly follow gradient-based and gradient-free paradigms. Gradient-based methods refine adversarial inputs using token-level gradients, with later work improving candidate evaluation, coordinate updates, objectives, and positional optimization (Zou et al., 2023; Zhao et al., 2024; Jia et al., 2024; Li et al., 2025a; Wang et al., 2024b; Jeong et al., 2026; Geisler et al., 2025). Gradient-free methods instead explore discrete prompt spaces through evolutionary search, beam search, sampling, or model-guided strategies (Liu et al., 2024c; Chao et al., 2025; Mehrotra et al., 2024; Sadasivan et al., 2024; Liu et al., 2024b, 2025). Recent hybrid approaches further combine search-based exploration with gradient-based adaptation (Paulus et al., 2024; Sun et al., 2025; Basani and Zhang, 2026). These developments suggest that gradient-free exploration and gradient-based refinement can be complementary, yet how the two optimization paradigms should be organized directly over adversarial inputs remains comparatively underexplored.

We therefore study how they are ordered. As illustrated in Figure 1, we consider four optimization modes: pure zeroth-order (ZO), pure first-order (FO), ZO→FO, and FO→ZO. Since the first stage determines the intermediate solution on which the second operates, different orders can induce substantially different optimization trajectories, even under the same stochastic objective. Rather than assuming an ordering a priori, we systematically

∗^{*}Corresponding Author.

(a) Pure ZO

Figure

(b) Pure FO

Figure

(c) ZO → FO

Figure

(d) FO → ZO

Figure

Figure 1: Four optimization organizations for prefix-suffix adversarial strings. (a) Pure ZO uses CEM to optimize both segments. Candidates are scored by target cross-entropy; per-position token frequencies from selected low-loss candidates guide cross-entropy fitting and smoothing of the sampling distribution, without model gradients. (b) Pure FO selects non-overlapping target locations, generates top-k token substitutions using target-loss gradients, and retains the candidate with the lowest screening loss. (c, d) apply ZO-to-FO and FO-to-ZO, respectively, updating prefix before suffix while fixing the other segment. Blue/orange denote prefix/suffix.

compare these alternatives and use the resulting empirical evidence to motivate ZO exploration followed by FO refinement as our basic framework.

Building on this ZO→FO structure, a further challenge is coordinating exploration with downstream refinement. A naive procedure selects a single ZO candidate before applying FO optimization, although the strongest candidate before refinement may not remain the best afterward. We therefore introduce Pair-aware optimization, illustrated in Figure 2. Instead of committing early, Pair-aware retains multiple promising ZO candidates, conditionally refines each with FO optimization, and selects according to their post-refinement prefix–suffix quality. This allows the exploration stage to account explicitly for the outcome of subsequent gradient-based refinement.

Our contributions are summarized as follows:

• A structured ZO-FO framework for agent jailbreaking. We systematically study how zeroth-order and first-order optimization should be organized, and establish a ZO→FO framework that separates candidate exploration from gradient-based refinement.

• Pair-aware optimization: an effective realization of the framework. Building on this formulation, we propose Pair-aware optimization, which retains multiple ZO candidates and evaluates them after conditional FO refinement to better coordinate the two optimization stages.

• Higher ASR under stochastic generation. We evaluate our method on multiple LLM agent benchmarks under stochastic decoding and show that the proposed framework achieves consistently higher targeted attack success rates than existing optimization-based baselines.

References (16)