From Text to Trajectory: Exploring Complex Constraint Representation and Decomposition in Safe Reinforcement Learning

Pusen Dong, Tianchen Zhu, Yue Qiu, Haoyi Zhou, Jianxin Li

TL;DR

Researchers have developed the Trajectory-level Textual Constraints Translator (TTCT), a framework that allows Reinforcement Learning (RL) agents to follow complex safety rules described in plain English. By using contrastive learning to align robot trajectories with text and implementing a novel "cost assignment" trick, the system achieves up to 4x fewer safety violations than traditional methods and can even adapt to new environments without extra training.

What Problem Does This Paper Address?

In Safe Reinforcement Learning, we want agents to maximize rewards (like reaching a goal) while strictly obeying safety constraints (like not crashing). Traditionally, engineers have to manually write mathematical "cost functions" for every single rule. This is a bottleneck: it requires deep domain expertise, doesn't scale well, and usually limits constraints to simple, single-state checks (e.g., "Is the robot currently touching a hazard?").

Real-world safety is rarely that simple. Many rules are trajectory-level, meaning they depend on a sequence of events over time—for example, "Don't enter the gas area for more than 5 minutes" or "Don't drive the car after you have consumed alcohol." Existing methods struggle with these because the "failure" happens at the end of a long chain of actions, making it hard for the agent to know exactly which step led to the disaster (the "sparse cost" problem).

Methods: The TTCT Framework

The authors introduce TTCT, which treats safety as a multimodal translation problem. It consists of two primary parts:

The TTCT framework architecture, detailing Text-Trajectory Alignment and Cost Assignment.
  1. Text-Trajectory Alignment: Using a setup inspired by vision-language models, TTCT uses a Causal Transformer to encode the agent's history (states and actions) and a Pre-trained Language Model to encode the textual constraint. It uses a Multimodal Contrastive (MC) loss to ensure that a trajectory and its corresponding violated constraint have similar embeddings in a shared space. A second Within-Trajectory (WT) loss helps the model distinguish between safe early steps and the final "breaking point" of a violation.
  2. Cost Assignment (CA) Component: To solve the sparse cost problem, the authors use an attention mechanism to perform temporal credit assignment. Instead of just giving a penalty at the very end of a failed run, the CA component looks at the relationship between the text and each individual step. It "decomposes" the total failure cost and distributes it across the trajectory, giving the agent a denser, more informative training signal about which specific behaviors were risky.

Evaluation Environments

The researchers evaluated TTCT across several challenging environments to test its robustness and adaptability:

Evaluation environments: Hazard-World-Grid, SafetyGoal, and LavaWall.
  • Hazard-World-Grid: A 2D grid where agents collect objects while avoiding lava, water, and grass based on specific rules.
  • SafetyGoal (Safety-Gymnasium): A complex 3D navigation task involving moving obstacles and sensors.
  • LavaWall: A specific environment used to test zero-shot transfer, where the agent encounters hazards it hasn't seen in exactly that configuration before.
  • The Constraint Pool: The authors designed a new benchmark of over 200 trajectory-level textual constraints categorized into Quantitative, Sequential, Relational, and Mathematical types.

Key Insights and Results

  • Text as a Training Signal: Instead of just using text as a passive "rulebook," TTCT uses it as a unified supervisory signal. This allows the model to handle diverse, multi-dimensional constraints without needing a custom-coded detector for every new rule.
  • Solving the "Aha!" Moment: By decomposing episodic costs into step-wise penalties, the agent learns why it failed. For a rule like "Don't touch lava more than three times," the agent starts receiving higher "risk" signals on the second touch, rather than waiting for the third touch to realize it failed.
  • Zero-Shot Generalization: Because the model learns the semantic meaning of constraints (e.g., the concept of "lava" or "after"), it can follow these rules in entirely new map layouts without any fine-tuning.
  • Superior Safety: Policies trained with TTCT achieved significantly lower violation rates—up to 4.0x lower—compared to agents trained with standard, ground-truth cost functions.
  • Better Trade-offs: In multi-objective optimization, TTCT pushed the Pareto frontier closer to the origin, meaning it achieved a better balance of high reward and low cost than baseline algorithms like PPO-Lagrangian or FOCOPS.
  • High Accuracy: The alignment component reached an AUC of 0.98 in predicting whether a trajectory violated a given text constraint, proving that the multimodal embedding space effectively captures safety logic.

Limitations and Future Work

The authors identify a few areas for improvement:

  • The Contextual Bottleneck: As trajectories get extremely long, the Transformer's ability to capture global information slightly declines, leading to a small drop in violation detection accuracy.
  • Not "Absolute Zero": While violation rates are much lower, they are not yet zero. In high-stakes real-world deployments (like autonomous surgery or flight), even a 1% violation rate might be too high.
  • Future Directions: The team plans to explore meta-learning to help agents adapt even faster to complex environments and investigate how these models handle even more "free-form" or ambiguous human instructions.

Summary updated

BibTeX
@inproceedings{dong2024from,
  author = {Pusen Dong and Tianchen Zhu and Yue Qiu and Haoyi Zhou and Jianxin Li},
  title = {{From Text to Trajectory: Exploring Complex Constraint Representation and Decomposition in Safe Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=MDpIQ9hQ7H},
}
Figure