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

Anaïs Berkes, Vincent Taboga, Donna Vakalis, David Rolnick, Yoshua Bengio · Submission to ICLR 2026 · Rejected

TL;DR

Current in-context reinforcement learning (ICRL) methods struggle when pretrained on suboptimal data because they act as glorified imitators without principled exploration mechanisms. SPICE (Shaping Policies In-Context with Ensemble prior) resolves this by equipping a Transformer backbone with a deep ensemble of value heads, updating this value prior at test time via closed-form Bayesian fusion with local context evidence, and acting via an Upper Confidence Bound (UCB) rule. As a result, SPICE achieves provably optimal regret rates in both bandits and MDPs—where poor pretraining data contributes only a constant warm-start penalty rather than permanent performance degradation.

What Problem Does This Paper Address?

In-context reinforcement learning (ICRL) aims to adapt policies to unseen tasks without gradient updates or fine-tuning: an agent conditions on a prompt-like history of past transitions $(s, a, r, s')$ and outputs actions directly.

Despite its promise, current ICRL faces three major roadblocks:

  1. Behavior-Policy Bias: Supervised objectives like behavioral cloning (e.g., Decision-Pretrained Transformers, DPT) inherit the flaws of the logging policy. If the training data is suboptimal, standard models mimic that mediocrity.
  2. Lack of Calibrated Uncertainty: Effective online exploration requires epistemic uncertainty over value functions (Q-values) to run algorithms like UCB or Thompson Sampling. Existing sequence models output action logits, not actionable value distributions.
  3. Unrealistic Data Demands: Approaches like Algorithm Distillation (AD) require full learning trajectories from already-trained RL algorithms, which are rarely available in real-world offline logs.

Methods

SPICE introduces a hybrid architecture combining a causal Transformer trunk with Bayesian value inference:

[Query state; Context] ──► Frozen Causal Transformer Trunk
                                │
               ┌────────────────┴────────────────┐
               ▼                                 ▼
       Value Ensemble Heads               Kernel Similarity
       (Mean & Variance Prior)            (Context Evidence)
               │                                 │
               └────────► Bayesian Fusion ◄──────┘
                          (Closed-Form)
                                │
                                ▼
                       Posterior-UCB Action
  • Trunk Representation Shaping: During pretraining, an auxiliary policy head shapes trunk representations using a three-way reweighted cross-entropy loss: $$\omega = \omega_{\text{IS}} \cdot \omega_{\text{adv}} \cdot \omega_{\text{epi}}$$ accounting for propensity correction ($\omega_{\text{IS}}$), advantage weighting ($\omega_{\text{adv}}$), and epistemic uncertainty ($\omega_{\text{epi}}$). This head is discarded at inference time.

  • Value Ensemble Prior: $K$ independent value heads (trained via $TD(n)$ regression, randomized priors, and Bayesian shrinkage) produce a Gaussian prior over action values $\mathcal{N}(\bar{Q}(a), \sigma_Q^2(a))$ at the query state.

  • Context Evidence Extraction: Using an RBF kernel over latent transformer representations $h$, SPICE measures similarity between context transitions and the query to aggregate state-weighted sufficient statistics (pseudo-counts $c_a$ and targets $\tilde{y}_a$).
  • Closed-Form Bayesian Fusion: Exploiting Normal-Normal conjugacy, SPICE combines prior and empirical precision to compute per-action posterior means ($m_a^{\text{post}}$) and variances ($v_a^{\text{post}}$).
  • Test-Time Control: The agent selects actions greedily for offline decision-making, or via a posterior-UCB rule ($a^* = \arg\max_a [m_a^{\text{post}} + \beta_t \sqrt{v_a^{\text{post}}}]$) for online exploration.

Datasets

The authors evaluate SPICE under deliberately challenging, weak-supervision protocols:

  • Stochastic Multi-Armed Bandits: 5-arm and 20-arm Gaussian bandits evaluated over a horizon $H=500$ with varying noise levels ($\sigma \in \{0.0, 0.3, 0.5\}$). Pretraining uses heterogeneous, non-optimal behavior mixtures (e.g., random policy with Dirichlet distributions, or an 80% optimal / 20% random label split).
  • Darkroom Gridworld (MDP): A $10 \times 10$ navigation grid with sparse rewards. The pretraining distribution consists of 100,000 tasks generated by a uniform random policy paired with a "weak-last" label (the arbitrary last action in the context). The evaluation tests extrapolation to 20% held-out target goal locations ($N=100$ unseen environments).

Key Insights and Ideas

  • Suboptimal priors only incur a constant warm-start penalty: The authors prove that SPICE achieves the minimax-optimal $O(\log K)$ regret in bandits and $O(H\sqrt{SAK})$ in finite-horizon MDPs. Even if the pretraining dataset is severely biased, the prior miscalibration term is bounded by a constant additive cost ($\sum O(N^{\text{pri}} |\mu^{\text{pri}} - Q^*|)$) that does not scale with horizon or episode count.
  • Decoupling representation learning from test-time control: While the policy head provides training signals that bias the latent space toward reward-relevant and uncertain regions, the actual decision controller relies strictly on the posterior value distribution.
  • Kernel matching in latent space: Applying the similarity kernel to learned Transformer representations ($h$) rather than raw states ensures that states sharing similar values and uncertainty profiles are grouped together during Bayesian updating.

Key Results

  • Bandit Benchmark: SPICE closely matches classical UCB and Thompson Sampling in online regret and achieves near-optimal offline selection. When shifting test reward noise ($\sigma=0.5$), SPICE degrades smoothly, whereas DPT's cumulative regret is two orders of magnitude worse due to its inability to adapt beyond training labels.
  • Darkroom MDP: Under "weak-last" random pretraining, DPT and Algorithm Distillation completely fail—exhibiting flat returns and linear regret ($\sim 76$ cumulative regret at step 100). In contrast, SPICE discovers the unseen goals rapidly, flattening regret after a brief initial warm-up period.
  • Weighting Ablation: An ablation in Darkroom shows that epistemic uncertainty weighting ($\omega_{\text{epi}}$) in the representation loss is the single biggest driver of performance, decreasing cumulative regret by 68% (from 76 down to 24), while importance weighting accounts for a 29% reduction.

Limitations and Future Work

  • Kernel Sensitivity: Bayesian updating relies on accurate kernel smoothing; poorly tuned bandwidths ($\tau$) or ill-suited metrics in non-stationary or partially observable environments could over-smooth or misattribute context evidence.
  • Prior Misspecification: Although asymptotic convergence is guaranteed, highly confident yet misspecified priors can lengthen the initial warm-up phase.
  • Action Space: The primary implementation focuses on discrete action spaces (though the authors outline extensions to continuous domains using parametric density heads and action-space kernels).

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