Safe In-Context Reinforcement Learning
Amir Moeini, Minjae Kwon, Alper Kamil Bozkurt, Yuichi Motai, Rohan Chandra, Lu Feng, Shangtong Zhang
TL;DR
This work addresses the safety gap in in-context reinforcement learning (ICRL) by embedding safety constraints into a constrained MDP (CMDP) and enabling zero-update adaptation on new tasks. It proposes two pretraining paradigms: Safe Supervised Pretraining, which distills safe RL behavior conditioned on return-to-go and cost-to-go, and Safe Reinforcement Pretraining, which uses Exact Penalty Policy Optimization (EPPO) to enforce per-episode cost limits via a dual surrogate and iterative updates, with ties between fixed points and primal optimality. The authors validate OOD generalization and flexible reward–cost trade-offs on SafeDarkRoom and SafeDarkMujoco, showing that reinforcement pretraining robustly generalizes to unseen and out-of-distribution tasks while respecting safety constraints, whereas supervised pretraining struggles in more complex domains. Theoretical results establish that EPPO’s fixed points are primal-optimal under mild conditions, and extensive ablations reveal robustness to context length, model size, and dataset size. Overall, the paper advances safe, adaptable RL that operates without updating parameters during test-time, with practical implications for real-world autonomous systems.
Abstract
In-context reinforcement learning (ICRL) is an emerging RL paradigm where the agent, after some pretraining procedure, is able to adapt to out-of-distribution test tasks without any parameter updates. The agent achieves this by continually expanding the input (i.e., the context) to its policy neural networks. For example, the input could be all the history experience that the agent has access to until the current time step. The agent's performance improves as the input grows, without any parameter updates. In this work, we propose the first method that promotes the safety of ICRL's adaptation process in the framework of constrained Markov Decision Processes. In other words, during the parameter-update-free adaptation process, the agent not only maximizes the reward but also minimizes an additional cost function. We also demonstrate that our agent actively reacts to the threshold (i.e., budget) of the cost tolerance. With a higher cost budget, the agent behaves more aggressively, and with a lower cost budget, the agent behaves more conservatively.
