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.
Figures & tables
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.
Figure 2: Conceptual comparison between myopic control and AegisFlow. (a) Myopic Control : A greedy controller driven purely by local target attraction and rigid boundary constraints. It gets trapped sliding jaggedly along the edge of the Unsafe Set and fails to reach the target state. (b) AegisFlow : By explicitly modeling the global cost field, the proposed trajectory is smooth and globally optimal. It proactively avoids the obstacle with an anticipated safety margin and successfully converges to the target. (c) Barrier Cost Landscape : The cost functional used by AegisFlow combines a barrier function to enforce constraints and a reward of the target, balancing constraint satisfaction and target guidance.
Figure 3: Visualization of text-guided image manipulation on CelebA-HQ. The row "+ MNC" shows the results when MNC is applied on OC-Flow.
Method
CLIP ↑
LPIPS ↓
ID ↑
CG + RF [ 13 ]
0.292
0.346
0.643
CG + LDM [ 13 ]
0.298
0.383
0.513
DiffusionCLIP [ 30 ]
0.285
0.398
0.659
StyleCLIP + e4e [ 42 ]
0.267
0.359
0.704
FlowGrad + RF [ 36 ]
0.299
0.302
0.737
OC-Flow [ 56 ]
0.302
0.207
0.732
Table 1: Comparison of AegisFlow with state-of-the-art methods on CelebA-HQ. The best results are in bold . We also include the results of directly applying MNC for reference.
Figure 4: Quantitative Analysis on CelebA-HQ. a. The value of the function h(x,t) at each timestep. The solid lines represent the mean value for the three methods and the shallow bands represent the range of variation. The x-axis is emphasized by a dash line since the forward invariance of Ct requires h(x,t)≥0 for all t . b. AegisFlow achieves a more favorable balance between text alignment (CLIP) and structure preservation (LPIPS). Connected markers represents different hyperparameter settings (See Appendix D.2 ).
Figure 5: Visualization of path generation process in Maze2D. Red circles represent the obstacles. AegisFlow behaves more proactively to maintain a large margin from the boundary of the safe set in the early stages of generation.
Method
BS1 ↑
BS2 ↑
Score ↑
κ↓
a↓
Diffuser [ 27 ]
-0.825
-0.784
1.572 ± 0.288
77.04 ± 4.30
86.68 ± 3.81
FlowMatcher
-0.324
-0.904
1.632 ± 0.003
73.51 ± 1.02
88.45 ± 0.60
ROS-SafeDiffuser [ 57 ]
0.010
0.010
1.435 ± 0.502
75.15 ± 6.67
422.87 ± 86.70
RES-SafeDiffuser [ 57 ]
0.010
0.010
1.442 ± 0.451
80.30 ± 13.06
398.17 ± 1060.86
TVS-SafeDiffuser [ 57 ]
-0.003
-0.003
1.506 ± 0.405
78.72 ± 7.80
124.51 ± 34.22
SafeFlowMatcher [ 58 ]
0.020
0.041
1.632 ± 0.003
51.97 ± 2.55
65.71 ± 2.45
Table 2: Comparison of AegisFlow with state-of-the-art methods on Maze2D. The best results are in bold . BS1 and BS2 being positive ( ≥0 ) indicates the trajectory is safe with respect to the corresponding constraint. a±b means a is the mean and b is the standard deviation over 100 trials.
Figure 6: Qualitative Results for Robotic Manipulation. a. Visualization of the robotic manipulation task. The object is to reach the green line while avoiding collision with the red obstacles. b. Generated trajectories by Flowmatcher. c. Generated trajectories by AegisFlow. The novel test-time constraints are that the robot should not enter the blue regions.
Method
Timesteps ↓
Goal ↑
Safe ↑
Violation ↓
Diffuser [ 27 ]
76.7 ± 12.7
1.00
0.07
17.8 ± 12.1
Flowmatcher
64.2 ± 9.4
1.00
0.22
14.8 ± 11.5
DOM [ 22 ]
79.1 ± 13.9
1.00
0.96
0.1 ± 0.5
Model-free [ 46 ]
76.1 ± 12.1
0.99
0.07
18.0 ± 12.0
DPCC-C [ 47 ]
69.0 ± 12.9
1.00
0.98
0.0 ± 0.3
AegisFlow (Ours)
62.6 ± 2.0
1.00
0.98
0.1 ± 0.5
Table 3: Comparison of AegisFlow with state-of-the-art methods on Avoiding. The best results are in bold . a±b means a is the mean and b is the standard deviation over 100 trials.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
U-Net channels
(1,4,8)×32
Loss type
L2
Training steps
1M
Steps per epoch
5K
Batch size
64
Learning rate
2e-4
EMA decay
0.995
Appendix
Table 4: Training strategy for the flow matching model in maze navigation.
Dataset
Method
Computation Time (s)
CelebA-HQ
OC-Flow
421.02 ± 25.56
OC-Flow + MNC
518.26 ± 25.54
AegisFlow
433.81 ± 25.57
Maze2D
SafeDiffuser
4.78 ± 0.42
SafeFlowmatcher
4.21 ± 0.39
AegisFlow
44.15 ± 1.96
Appendix
Table 5: Computational efficiency comparisons. a±b means a is the mean and b is the standard deviation over 1000 trials (CelebA-HQ) or 100 trials (Maze2D).
Method
Hyperparameters
CLIP ↑
LPIPS ↓
ID ↑
FlowGrad
+ RF
0.299
0.302
0.737
+ LDM
0.294
0.298
0.743
OC-Flow
α=0.6
0.295
0.119
0.822
α=0.7
0.302
0.207
0.732
α=0.8
0.306
0.192
0.722
α=0.9
0.310
0.244
0.662
Appendix
Table 6: Detailed metrics comparisons for text-guided image manipulation on CelebA-HQ.
Inference-time guided sampling steers state-of-the-art diffusion and flow models without fine-tuning by interpreting the generation process as a controllable trajectory. This provides a simple and flexible way to inject external constraints (e.g., cost functions or pre-trained verifiers) for controlled generation. However, existing methods often fail when composing multiple constraints simultaneously, which leads to deviations from the true data manifold. In this work, we identify root causes of this off-manifold drift and find that the approximation error scales severely with gradient misalignment. Building on these findings, we propose Conflict-Aware Additive Guidance (gcar), a lightweight and learnable method, which actively rectifies off-manifold drift by dynamically detecting and resolving gradient conflicts. We validate gcar across diverse domains, ranging from synthetic datasets and image editing to generative decision-making for planning and control. Our results demonstrate that gcar effectively rectifies off-manifold drift, surpassing baselines in generation fidelity while using light compute. Code is available at https://github.com/yuxuehui/CAR-guidance.
Xuehui Yu, Fucheng Cai, Meiyi Wang +2
Smart Systems Institute, National University of Singapore, Singapore · Faculty of Computing, Harbin Institute of Technology, Harbin, China · School of Computing, National University of Singapore, Singapore
In recent years Flow Matching has become a prominent method for generative modeling robot motion generation. In its generic form Flow Matching is an ODE-based neural sampler that is trained by regressing empirical flow fields associated with motion samples as data. However, in robot motion generation we often have additional constraints that might not be present in the collected data. The majority of current approaches train the flow on the available data and use inference-time guidance to enforce task-specific constraints. To address this mismatch, we propose ConFlow, a constraint-guided flow matching framework that incorporates constraint information directly into the training objective via differentiable barrier or cost functions. To address design specifications such as smoothness and boundary conditions, we propose replacing the standard Gaussian source distribution used in flow matching training with a conditional Gaussian Process. Our approach also uses infeasible demonstrations as negative supervision, improving constraint satisfaction without requiring additional expert data. Experiments on a two-robot navigation task demonstrate that ConFlow achieves lower collision rates and higher trajectory quality than standard flow matching baselines, with or without inference-time guidance. These results validate training-time constraint integration as an effective approach to closing the training--inference gap in generative motion models.
Nutan Chen, Jianxiang Feng, Marvin Alles +1
LS Wiiri Robot Innovation Center · Independent Researcher · Technical University of Munich +1
While flow-based generative models have demonstrated strong performance across a wide range of domains, deploying them in safety-critical physical systems remains challenging due to strict constraint requirements. Existing approaches typically enforce safety through post-hoc corrections, which incur substantial computational overhead and may distort the learned distribution. We propose PolyFlow, a polytope-constrained flow matching framework that embeds constraints directly into the model and flow dynamics. PolyFlow introduces a discrete-time flow formulation and a projection-free architecture, which eliminate the discretization error and guarantee strict satisfaction of arbitrary polyhedral constraints, without the need for expensive iterative solvers. Experimental results show that PolyFlow achieves zero constraint violation while maintaining high distributional fidelity across a range of planning and control tasks. Compared to state-of-the-art constrained generation baselines, PolyFlow significantly reduces inference latency and demonstrates a favorable trade-off between safety, efficiency, and generative quality. Code is available on https://github.com/MJianM/PolyFlow.
Jianming Ma, Qiyue Yang, Yang Zhang +4
Shanghai Jiao Tong University, Shanghai, China · Shanghai Innovation Institute, Shanghai, China