Temporal Logic Specification-Conditioned Decision Transformer for Offline Safe Reinforcement Learning

Zijian Guo, Weichao Zhou, Wenchao Li

Introduction

The Specification-conditioned Decision Transformer (SDT) is a novel framework that brings the rigor of formal logic to the flexibility of offline reinforcement learning (RL). By conditioning a Decision Transformer on Signal Temporal Logic (STL), SDT enables agents to learn high-reward policies that respect complex, time-dependent safety rules—such as "stop at the sign, wait for traffic, then proceed"—directly from static datasets.

The Challenge of Non-Markovian Safety

Standard Reinforcement Learning is highly effective at maximizing rewards but notoriously struggles with following complex rules. In "Safe RL," the typical approach is to keep a "cost" below a certain threshold. However, most current methods assume these costs are Markovian, meaning the safety of an action depends only on the current state.

Real-world safety is rarely that simple. Consider an autonomous vehicle: "Safety" isn't just about avoiding collisions; it involves temporal logic, such as coming to a complete stop before entering an intersection. Standard cost functions struggle to capture these "if-then-eventually" structures. Furthermore, in Offline RL, agents cannot explore the environment to find these boundaries through trial and error; they must learn them from a fixed, often imperfect, dataset. Existing offline safe RL methods frequently fail when tasks involve these rich temporal and logical constraints.

Methodology: Introducing SDT

To address this gap, researchers built their solution on the Decision Transformer (DT), which treats RL as a sequence modeling problem—predicting the next action based on a history of states and desired outcomes.

To handle complex rules, they integrated Signal Temporal Logic (STL). Instead of treating rule satisfaction as a simple "yes/no" binary, STL provides a robustness value—a continuous number where positive values indicate satisfaction (and how much "buffer" remains) and negative values indicate a violation.

SDT Architecture

The core innovation of SDT is conditioning the transformer on two new types of logical information alongside the standard return-to-go, state, and action tokens:

  1. Prefix Robustness: A measure of how well the agent has followed the rules from the start of the episode up to the current moment.
  2. Suffix Robustness: The desired degree of rule satisfaction for the remainder of the trajectory.

By training the model to predict actions that match specific "suffix" values found in the data (hindsight information matching), the agent learns to associate specific behaviors with specific logical outcomes. At test time, a user can simply prompt the model with a high satisfaction score, and it generates the corresponding safe actions.

Key Insights

  • Logic as a Language: Transformers are fundamentally designed to understand sequences in language. By treating a trajectory’s logical robustness as just another "token" in the sequence, the model can effectively learn the "grammar" of safety.
  • The Power of the Prefix: Most RL models only look forward (e.g., "Return-to-Go"). In logic, however, the past matters. Knowing whether you have already satisfied a prerequisite task or are dangerously close to a violation (the Prefix) fundamentally changes what the optimal next move should be.
  • Non-Markovian Mastery: Because Transformers utilize an attention mechanism (memory), they are naturally suited for STL rules where the correct action depends on events that occurred many steps prior.
  • Zero-Shot Adaptation: Once trained, SDT does not need to be retrained to alter its safety behavior. Users can dial the "target suffix" up for maximum safety or down for more aggressive, high-reward behavior.

Key Results

The authors evaluated SDT using the DSRL (Datasets for Safe RL) benchmark, specifically focusing on the Bullet-Safety-gym environments (Run, Circle, and Reach).

Quantitative Results on DSRL Benchmark

SDT significantly outperformed state-of-the-art baselines like the Constrained Decision Transformer (CDT) and various Lagrangian-based methods:

  • Higher Satisfaction: In the "Circle" environment (where robots must move in a circle while staying within a narrow safe zone), SDT achieved an 86% satisfaction rate, while the next best conditioned RL baseline (CDT) only managed 49%.
  • Handling Complexity: In the "Reach" task—which involves sequential goals that are very difficult to define with standard cost functions—SDT achieved a 76% satisfaction rate. Most baselines could not even be applied to this task because they require simple, relabelable Markovian costs.
  • Alignment: The model demonstrated a strong correlation between the "requested" safety level and the "actual" safety level achieved, proving it truly learned to condition its behavior on the STL specifications.

Limitations and Future Work

While SDT presents a significant step forward, the authors note a few challenges. First, STL robustness values can be "sparse," meaning they might stay constant for long periods, giving the agent limited feedback until a rule is actually broken. Second, during evaluation, the user must manually set a "target suffix." While a fixed small positive value works well, automating the selection of optimal targets could improve performance. Finally, while STL is currently used for safety constraints alongside standard rewards for performance, future work could explore using STL to define the primary task goals themselves, potentially allowing for even more complex "programmatic" behavior.

Summary updated

BibTeX
@inproceedings{guo2024temporal,
  author = {Zijian Guo and Weichao Zhou and Wenchao Li},
  title = {{Temporal Logic Specification-Conditioned Decision Transformer for Offline Safe Reinforcement Learning}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=7bg10Jj3bG},
}
Figure