CDCP: Conditional Diffusion Model with Contextual Prompts for Multi-task Offline Safe Reinforcement Learning

Jiayi Guan, Tianle Zhang, Li Shen, Ruiqi Zhang, Ao Zhou, Lusong Li, Guai Chen, Mengjie Li, Alois Knoll, Xiaodong He, Changjun JiangarXiv 2026

TL;DR

Deploying reinforcement learning in high-risk, real-world scenarios requires agents that can perform multiple tasks safely using only pre-collected offline data. This paper introduces CDCP, a conditional diffusion framework that sidesteps error-prone Q-value estimation by treating multi-task offline safe RL as a conditional sequence generation problem. By combining textual and trajectory prompts with an adaptive gradient synchronization strategy, CDCP achieves superior rewards while strictly satisfying safety constraints—even generalizing to entirely unseen tasks at test time.

What Problem Does This Paper Address?

Offline Safe Reinforcement Learning (RL) is highly desirable for real-world applications like autonomous driving and robotics because it allows policies to be learned from static, pre-recorded datasets without risking dangerous real-world exploration. However, scaling this to multi-task settings introduces a "triple whammy" of challenges: multi-task gradient interference, strict safety constraints, and out-of-distribution (OOD) actions.

Traditional offline RL algorithms rely on temporal-difference (TD) learning to estimate reward and cost Q-values. In offline settings, evaluating actions outside the dataset causes massive extrapolation errors. When scaled to multiple tasks, these errors compound rapidly across multiple cost Q-functions. As a result, existing methods either fail to stay safe or suffer from severely degraded rewards.

Fig. 1: The mean reward and cost for the multi-task offline RL algorithm MTDiff across nine driving tasks, each with varying traffic scenarios or densities. The curves represent the test results from 3 random seeds during training, with the solid line indicating the mean of the three random seeds and the shaded area representing the standard deviation.

Methods

To overcome the limitations of TD-learning, the authors propose CDCP (Conditional Diffusion model with Contextual Prompts), which reframes policy optimization as a conditional generation problem:

  1. Generative Framework via Diffusion: Instead of predicting Q-values, CDCP trains a conditional diffusion model via supervised learning to directly generate safe action sequences, completely avoiding value-estimation extrapolation errors.
  2. Classifier-Free Guided Cost Constraints: During the denoising process, classifier-free guidance uses target rewards and remaining trajectory costs to steer the generated actions. This allows users to dynamically adjust safety thresholds at test time without retraining the model.
  3. Contextual Prompts: To help the model differentiate between tasks and generalize to new ones, CDCP introduces a dual-prompting mechanism. It combines high-level semantic task descriptions (encoded via a pre-trained LLM) with low-level trajectory prompts (short snippets of expert state-action pairs).
  4. Gradient Loss Synchronization: Multi-task training often suffers from gradient interference where simpler or high-loss tasks dominate. CDCP adaptively weights each task's loss based on its gradient norm and decay rate, ensuring stable, balanced training across all tasks.

Datasets

The authors evaluated CDCP using the MetaDrive simulator, leveraging datasets from the DSRL (Datasets and Benchmarks for Offline Safe Reinforcement Learning) benchmark. They selected nine distinct driving tasks that span three levels of scenario complexity (Easy, Medium, Hard) and three traffic densities (Sparse, Mean, Dense). These tasks require navigating complex road layouts like curves, intersections, T-junctions, and roundabouts while avoiding collisions.

Key Insights and Ideas

  • Ditching Q-values for Diffusion: The core "aha!" moment is that diffusion models completely sidestep the brittle nature of offline Q-value estimation. By framing control as sequence generation, the model learns the safe data distribution directly, neutralizing OOD action risks.
  • Test-Time Safety Tuning: Because safety is injected as a conditioning variable (remaining cost) during classifier-free guidance, you can change the safety threshold on the fly during deployment. Setting the cost condition to zero seamlessly transforms the model from satisfying cumulative cost constraints to satisfying strict, state-wise safety constraints.
  • Text + Trajectory = Few-Shot Generalization: Text provides high-level semantic context (e.g., "dense traffic roundabout"), while trajectory prompts capture low-level environmental dynamics. Together, they allow the model to adapt to entirely unseen tasks using only a few expert demonstrations.

Key Results

CDCP significantly outperformed both multi-task offline RL baselines and single-task safe RL methods extended to multi-task settings.

  • Performance vs. Safety: While unconstrained multi-task models (like MTDiff) achieved high rewards but failed safety limits, and traditional safe RL baselines (like MTCPQ) over-conservatively tanked their rewards, CDCP struck an optimal balance. On the MetaDrive benchmark, CDCP achieved a top-tier mean reward of 270.45 while maintaining a mean cost of 23.06 (well below the strict cost limit of 25).
  • Robustness to Thresholds: CDCP successfully adhered to various cost thresholds (0, 20, 25, 30) adjusted purely at test time without any model retraining.
  • Few-Shot Generalization: In zero/few-shot experiments on unseen driving tasks, CDCP successfully maintained safety boundaries where other models failed.

Limitations and Future Work

While CDCP demonstrates impressive capabilities, the authors note a couple of areas for improvement:

  • Domain Diversity: The evaluation is heavily focused on autonomous driving scenarios. Testing CDCP on other complex domains, such as high-DoF robotic manipulation or industrial process control, would further validate its universality.
  • Inference Speed: Diffusion models require iterative denoising steps, which can be computationally slow. For real-time, safety-critical deployments like autonomous driving, integrating acceleration techniques (such as Consistency Models or DDIM sampling) is a necessary next step.

Summary updated

BibTeX
@misc{guan2026cdcp,
  author = {Jiayi Guan and Tianle Zhang and Li Shen and Ruiqi Zhang and Ao Zhou and Lusong Li and Guai Chen and Mengjie Li and Alois Knoll and Xiaodong He and Changjun Jiang},
  title = {{CDCP: Conditional Diffusion Model with Contextual Prompts for Multi-task Offline Safe Reinforcement Learning}},
  year = {2026},
  eprint = {2607.03903},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.03903},
}
Figure