Introduction
In traditional Safe Markov Decision Process (MDP) planning, safety is typically defined by a cost function that penalizes specific state-action pairs. However, real-world environments often exhibit "Negative Side Effects" (NSEs)—undesirable outcomes that are not explicitly forbidden in the original model. Many of these safety violations are non-Markovian, meaning they depend on a sequence of events over time rather than a single moment. For instance, a robot might safely traverse a fragile surface once, but repeated traversal could lead to structural failure.
This paper introduces a novel framework for safe Reinforcement Learning (RL) that identifies and avoids NSEs by learning from entire trajectories. By integrating a trajectory-classifying Recurrent Neural Network (RNN) into a differentiable computation graph, the proposed Model-Based Gradient Estimation (MBGE) method enables agents to satisfy complex safety constraints while maximizing rewards in both discrete and continuous environments.
Methodology
The authors propose a two-stage approach to address non-Markovian safety constraints and bridge the gap between human intuition and numerical cost functions.
Trajectory Classification with RNNs
Instead of per-step costs, the framework uses Gated Recurrent Units (GRUs) to classify an entire state-action trajectory into categorical NSE labels (e.g., "no-NSE," "mild," or "severe"). This approach is more intuitive for human experts, who find it easier to label a full trajectory as "unsafe" than to design precise numerical cost functions. By using RNNs, the agent can learn that safety is often a property of history—for example, that a specific action is safe in isolation but dangerous when preceded by a specific sequence of events.
Model-Based Gradient Estimation (MBGE)
To optimize the policy, the authors employ a Lagrangian multiplier method, treating safety as a constraint to be satisfied alongside reward maximization. The core innovation is the use of a Stochastic Computation Graph. By applying the reparameterization trick (similar to those used in Variational Autoencoders), the entire pipeline—including policy, environment transitions, and the RNN safety classifier—becomes differentiable.
This differentiability allows the agent to pinpoint which specific parts of a trajectory contributed to a safety violation, enabling targeted policy adjustments. Unlike model-free "score function" estimators that often suffer from high variance and over-correction, MBGE provides stable and efficient learning.
Experimental Evaluation
The method was evaluated across four distinct domains:
- Boxpushing & Autonomous Driving (Grid World): Tasks requiring the avoidance of fragile surfaces or puddles while reaching a goal.
- Navigation & HVAC Control (Continuous): Complex environments where safety depends on temporal thresholds, such as not exceeding a temperature limit for consecutive timesteps.
Results and Discussion
The MBGE method demonstrated a superior balance between safety and reward compared to state-of-the-art baselines like Markov-HA-S and model-free Lagrangian methods. In continuous domains, MBGE successfully discovered paths that bypassed danger zones entirely.
For example, in the Navigation task, MBGE maintained a 95% NSE-free rate, whereas standard Proximal Policy Optimization (PPO) failed almost 100% of the time because it was "blind" to the safety constraints. The model-based approach proved significantly more stable and sample-efficient than model-free alternatives, which often failed to converge in complex continuous spaces.
Limitations and Future Work
While effective, MBGE is model-based and requires an environment transition model, which may be difficult to obtain in some real-world scenarios. Additionally, the safety of the agent is contingent on the accuracy and generalization capabilities of the RNN classifier. Future work may explore incorporating uncertainty estimation, such as Bayesian Neural Networks, into the safety classifier to improve robustness.
Conclusion
By moving beyond Markovian assumptions and leveraging differentiable trajectory classification, MBGE provides a powerful tool for safe RL. It simplifies safety specification for human designers and achieves high performance in both discrete and continuous environments by learning to avert negative side effects through temporal pattern recognition.
Summary updated