In-Context Reinforcement Learning through Bayesian Fusion of Context and Value Prior

Anaïs Berkes, Vincent Taboga, Donna Vakalis, David Rolnick, Yoshua Bengio

TL;DR

The paper introduces SPICE, a novel Bayesian approach to In-Context Reinforcement Learning (ICRL) that enables agents to adapt rapidly to unseen tasks without gradient updates. By fusing a learned Q-value ensemble prior with test-time context evidence via closed-form Bayesian updates, SPICE achieves optimal online exploration and regret bounds even when pretrained entirely on highly suboptimal data.

What Problem Does This Paper Address?

In-Context Reinforcement Learning (ICRL) leverages the power of sequence models (like Transformers) to adapt policies to new environments purely through context—the history of states, actions, and rewards—without changing any model weights.

However, existing ICRL methods face three major bottlenecks:

  1. Behaviour-Policy Bias: Most methods rely on supervised pretraining (like Maximum Likelihood Estimation) to mimic action labels. If the data collection policy is suboptimal, the model inherits these flaws and fails to improve beyond the training distribution.
  2. Lack of Uncertainty Quantification: Successful online adaptation requires an agent to know what it doesn't know. Current ICRL models output action logits but lack actionable posteriors over action values (Q-values), preventing principled exploration.
  3. Unrealistic Data Requirements: Leading approaches require optimal expert demonstrations or complete reinforcement learning training traces during pretraining, which are rarely available in real-world applications.

The authors tackle these challenges by introducing a principled Bayesian framework that quantifies epistemic uncertainty and enables robust exploration from weak data.

Methods

The authors propose SPICE (Shaping Policies In-Context with Ensemble prior), which splits the problem into representation learning, value prior estimation, and test-time Bayesian fusion.

  • Transformer Trunk: A causal GPT-2 architecture encodes the query state and context transitions into latent features.
  • Value Ensemble Prior: Instead of predicting actions directly, SPICE attaches a $K$-head deep ensemble to the transformer trunk. This ensemble outputs a calibrated Gaussian prior over Q-values, capturing epistemic uncertainty via randomized priors and anchor regularizers.
  • Representation Shaping: During pretraining, an auxiliary policy head is optimized using a weighted cross-entropy loss. This loss combines propensity correction, advantage weighting, and epistemic uncertainty weighting to force the transformer trunk to learn features ideal for value estimation. Crucially, this policy head is discarded at test time.
  • Test-Time Bayesian Fusion: At inference, SPICE treats context transitions as local evidence. It computes state-weighted counts and targets using a Radial Basis Function (RBF) kernel applied to the transformer's latent features. It then combines this evidence with the ensemble prior using closed-form Gaussian conjugate updates (precision additivity).
  • Action Selection: Online, the agent selects actions using a posterior Upper-Confidence Bound (UCB) rule, turning value uncertainty into directed exploration.

Datasets

The method was evaluated on two primary benchmarks:

  • Stochastic Multi-Armed Bandits: Tested on 5-armed and 20-armed setups with Gaussian rewards. Pretraining contexts were intentionally corrupted using highly heterogeneous and suboptimal behavior distributions to evaluate adaptation from poor logs.
  • Darkroom Gridworld: A $10 \times 10$ navigation task with sparse rewards. Pretraining data was generated using a worst-case "weak-last" dataset (where labels correspond to the last action of a uniform random policy). Evaluation required zero-shot extrapolation to out-of-distribution goal locations.

Key Insights and Ideas

  • Decoupling Representation from Control: By using an auxiliary policy head only to shape the latent space during training and relying entirely on the Q-ensemble at test time, SPICE successfully bypasses behavior-policy bias.
  • Miscalibration is Forgiven: The authors mathematically prove that a biased or miscalibrated prior resulting from poor pretraining data only adds a constant warm-start penalty to the cumulative regret. As test-time evidence accumulates, the Bayesian update quickly overrides the prior bias, recovering optimal asymptotic convergence rates ($O(\log K)$ for bandits and $O(H\sqrt{SAK})$ for MDPs).
  • Latent-Space Kernel Density: Rather than computing state similarity in raw state space, SPICE applies its kernel to the transformer's latent space. Because the trunk is trained to group states with similar advantages and uncertainties, this drastically improves robustness under distribution shifts.

Key Results

  • Bandit Performance: When trained on weak data, standard sequence-modeling baselines like Decision-Pretrained Transformers (DPT) suffer from linear regret growth. SPICE, however, achieves near-optimal suboptimality offline and closely tracks classical UCB online, maintaining logarithmic regret.
Figure 2: Bandit performance evaluation. (a) Offline selection quality. (b) Online cumulative regret (zoomed view). (c) Online cumulative regret (full scale). Shaded regions are ± SEM over N=200 test environments.
  • Robustness to Noise: Under distribution shifts in reward noise, SPICE's performance degrades smoothly, whereas imitation-based methods fail to adapt entirely.
  • Darkroom Navigation: In the sparse-reward gridworld, SPICE rapidly flattens its regret curve and achieves high returns, while DPT and Algorithm Distillation (AD-BC) remain bound to the random behavior policy, yielding near-zero returns.

Limitations and Future Work

  • Kernel Sensitivity: The choice and bandwidth of the state-similarity kernel are critical. In highly non-stationary or partially observable environments, a poorly tuned kernel could lead to over-fitting or over-smoothing of context evidence.
  • Prior Misspecification: SPICE assumes the deep ensemble produces reasonably calibrated priors. If the learned prior is systematically and confidently misspecified, the posterior fusion can inherit this bias, slowing down early test-time adaptation despite long-term regret guarantees.

Summary updated

BibTeX
@misc{berkes2026context,
  author = {Anaïs Berkes and Vincent Taboga and Donna Vakalis and David Rolnick and Yoshua Bengio},
  title = {{In-Context Reinforcement Learning through Bayesian Fusion of Context and Value Prior}},
  year = {2026},
  eprint = {2601.03015},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.03015},
}
Figure