arXiv:2610.39825cs.AIOct 2026

Manuscript Offprint

arXiv:2610.39825

AegisFlow: Training-Free Non-Myopic Path-Safe Guided Flow Matching

Kunpeng Liu, Boshi Zhang, Keyou You

Kunpeng Liu

Department of Automation and BNRist

Tsinghua University

Beijing, China

liukp22@mails.tsinghua.edu.cn

Boshi Zhang

Department of Automation and BNRist

Tsinghua University

Beijing, China

zbs22@mails.tsinghua.edu.cn

Keyou You ∗^{*}

Department of Automation and BNRist

Tsinghua University

Beijing, China

youky@tsinghua.edu.cn

Abstract

Pretrained generative models, such as diffusion and flow matching models, have demonstrated exceptional capabilities in synthesizing high-quality data. However, steering their generative trajectories to satisfy strict constraints—such as identity preservation in image editing or obstacle avoidance in robotics—remains fundamentally challenging. While recent training-free guidance methods enforce path-safety, they rely heavily on min-norm controllers that only account for immediate constraint satisfaction. These myopic approaches often yield suboptimal trajectories that hover dangerously close to the boundary, severely restricting the model's ability to optimize toward its target. In this paper, we propose AegisFlow, a training-free, non-myopic path-safe guidance framework that recasts guided generation as a safety-critical optimal control problem with global scope. By integrating a time-varying barrier function directly into the global cost functional, AegisFlow naturally enforces constraints along the entire generative path. To compute the global optimal control, we derive a tractable, mathematically grounded approximation of the Hamilton-Jacobi-Bellman (HJB) equation. Comprehensive experiments demonstrate that AegisFlow outperforms state-of-the-art methods across text-guided image manipulation and robotic planning, establishing a significantly better trade-off between target alignment and constraint satisfaction. Code is available at https://github.com/LiuKunpeng03/AegisFlow.

1 Introduction

Generative models such as diffusion [25, 53] and flow matching [34] have exhibited remarkable capabilities in synthesizing high-quality data across various domains, including images [45, 16] and planning [8, 14]. Guided generation, e.g., image editing [38, 24], takes advantage of the expressiveness of pretrained generative models and steers the generative trajectory towards a target. Reward-guided methods [52, 36, 56], which leverage a predefined reward function to optimize the trajectory at inference time, have attracted significant attention due to their training-free nature and flexibility in handling various objectives.

∗^{*}Corresponding author

Preprint.

Figure

Figure 1: Toy Example. Vanilla represents the original flow which is trained to fit into the contour of a cat. Guidance stands for the case where the flow is guided towards two eyes of the cat. Although the guidance successfully steers the trajectory, many trajectories collide with the red yarn ball which serves as the obstacle. Correction means min-norm controller is applied to the former case. While all trajectories are safe, the quality is significantly degraded. Aegis successfully guides most of the trajectories towards the target while maintaining a safe distance from the obstacle.

Besides objective guidance, constraint satisfaction is increasingly accounted for in guided generation. For example, fake or harmful content should be strictly prohibited from generation [51, 33], and generated trajectories for robotics should obey physical law and avoid obstacles [27, 8]. Previous methods deal with constraints by either soft guidance [60, 9] or projection [10, 54, 61]. The former admits no hard guarantees on constraint satisfaction, while the latter might hinder the generation quality. Recent works [57, 58, 20] extend the desired constraint on the output to the entire generative trajectory, and enforce path-safety by imposing control to the pretrained flow model. These methods are able to achieve better constraint satisfaction while maintaining generation quality. However, they apply a myopic min-norm controller, which only considers the immediate effect of the control input without accounting for the long-term effect on the trajectory. As a result, these methods often find suboptimal solutions that hover dangerously close to safety boundaries, severely limiting the aggressiveness with which a model can optimize toward its target. See Figure 1 for an illustration.

To overcome the fundamental limitations of myopic controllers, we propose AegisFlow, a training-free, non-myopic path-safe guidance method for flow matching models. AegisFlow recasts guided generation as a safety-critical optimal control problem with a global scope. Instead of relying on per-step corrections, we integrate a time-varying barrier function directly into the global cost functional. This formulation penalizes the trajectory for approaching the boundary of the safe set, ensuring the entire generated path remains within a safe tube. AegisFlow seeks to find the global optimal control via estimating the solution to the Hamilton-Jacobi-Bellman (HJB) equation associated with the cost functional, which inherently accounts for the long-term effects of control inputs on both target alignment and safety constraints. Since the barrier function drives the cost to infinity near safety boundaries, any finite-cost solution natively guarantees constraint satisfaction, allowing us to bypass the ad-hoc projections or per-step barrier functions required by prior methods.

We extensively evaluate AegisFlow across diverse and challenging domains, spanning from high-dimensional text-guided image manipulation (CelebA-HQ) to physical planning (Maze2D and D3IL robotic manipulation). In image editing, AegisFlow proactively maintains a larger safety margin for identity preservation, enabling stronger textual alignment (higher CLIP scores) and better identity retention than myopic baselines. In continuous control tasks, AegisFlow achieves higher success rates, smoother trajectories, and fewer safety violations compared to current state-of-the-art safe diffusion methods.

In summary, our main contributions are as follows:

• Overcoming of Myopic Limitations: We identify the suboptimality of min-norm controllers in guided flow matching and propose AegisFlow, a globally aware, training-free optimal control framework.

• Tractable HJB Approximation: We formulate a barrier-inclusive cost functional and derive a tractable, mathematically grounded approximation for the optimal safe control using the Hamilton-Jacobi-Bellman (HJB) equation.

• Comprehensive Empirical Validations: We demonstrate superior performance across both high-dimensional image manipulation and safety-critical continuous control tasks, establishing a significantly better trade-off between target alignment and constraint satisfaction.

References (61)