Scalable In-Context Q-Learning

Jinmei Liu, Fuhong Liu, Zhenhong Sun, Jianye Hao, Huaxiong Li, Bo Wang, Daoyi Dong, Chunlin Chen, Zhi Wang

Overview

Scalable In-Context Q-Learning (S-ICQL) is an innovative framework that brings the power of dynamic programming (Q-learning) and world modeling to In-Context Reinforcement Learning (ICRL). By utilizing a multi-head transformer to predict values and policies simultaneously, S-ICQL can effectively "stitch" together suboptimal experiences to discover optimal behaviors on the fly. This approach significantly outperforms existing imitation-based methods, particularly on unseen tasks and when learning from suboptimal data.

The Challenge of In-Context Reinforcement Learning

In-Context Reinforcement Learning aims to create agents capable of adapting to new tasks simply by observing a few "prompt" transitions, without requiring any gradient updates at test time. This mirrors the few-shot learning capabilities of Large Language Models (LLMs).

However, current ICRL methods—such as Algorithm Distillation (AD) or Decision-Pretrained Transformers (DPT)—face three major hurdles:

  1. Suboptimal Data: Most existing methods rely heavily on supervised learning (imitation). If the training data consists of mediocre trajectories, the agent simply learns to replicate that mediocrity.
  2. Bloated Prompts: Raw transitions $(s, a, r, s')$ are long, redundant, and computationally expensive to process. They often include "noise" from the specific behavior policy that collected the data.
  3. Lack of "Stitching": Traditional RL excels at taking bits and pieces of different suboptimal paths to piece together a globally optimal one (known as the "stitching property"). Purely imitation-based ICRL fundamentally lacks this capability.

Methods: The S-ICQL Framework

To address these limitations, S-ICQL combines the scalability of transformers with the fundamental principles of Reinforcement Learning.

Overview of the S-ICQL framework

1. The World Model (The "Semantic Filter")

Before training the main agent, the framework pretrains a generalized world model. This model learns to predict the next state and reward based on a short history of interactions.

  • Why it matters: This allows the system to extract a compact "task representation" ($z_t$). Instead of feeding the transformer raw, noisy transitions, it uses these task-relevant embeddings. This makes the prompt lightweight, precise, and invariant to the specific behavior policy.

2. Multi-Head Transformer Architecture

S-ICQL employs a single causal transformer backbone equipped with three specialized "heads":

  • Policy Head ($ \pi$): Predicts the optimal action.

  • Value Head ($V$): Estimates the state value.

  • Q-Head ($Q$): Estimates the action value.

3. In-Context Q-Learning

Instead of merely imitating the prompt, S-ICQL performs iterative policy improvement during pretraining. It fits the $V$-function to an upper expectile of the $Q$-function (similar to Implicit Q-Learning). This effectively instructs the model to focus on the best possible outcomes seen in the data, rather than the average. It then extracts the policy using Advantage-Weighted Regression (AWR), weighting actions by their advantage over the average expected return.

Datasets and Evaluation

The researchers evaluated S-ICQL across a diverse set of benchmarks to test its robustness and adaptability:

  • DarkRoom: A 2D discrete grid-world navigation task.
  • MuJoCo (Continuous Control): Environments including Cheetah-Vel (running at target speeds), Walker-Param (varying physics), and Ant-Dir (moving in specific directions).
  • Meta-World (Robotic Manipulation): Challenging tasks like Reach, Push, and PickPlace.

To prove the model can learn from "bad" examples, they tested on both "Mixed" (diverse quality) and "Medium" (purely suboptimal) datasets.

Key Insights and Results

Performance comparison across various environments
  • The Stitching Breakthrough: S-ICQL is the first ICRL framework to demonstrate a clear "stitching" property. In experiments, S-ICQL's performance actually exceeded the best trajectory present in the training data. Imitation-based baselines, by contrast, were capped by the quality of the data they observed.
  • Superior Performance: As seen in the learning curves, S-ICQL (red line) consistently outperformed six major baselines (including DPT, AD, and IC-IQL) across almost all environments.
  • Suboptimal Data King: On the "Medium" (suboptimal) Ant-Dir task, S-ICQL achieved a return of ~600, while the next best baseline (IC-IQL) trailed at ~500, and pure imitation (DPT) failed completely at ~73.
  • Zero-Shot Generalization: Because the world model captures fundamental dynamics, S-ICQL generalizes remarkably well to Out-of-Distribution (OOD) tasks, such as target velocities or directions never seen during training.

Limitations and Future Work

While S-ICQL represents a significant leap forward, there are areas for future exploration:

  • Prompt Length: Although more compact than raw transitions, the prompt still scales with the number of sampled transitions. Future work could condense an entire episode or "skill" into a single token.
  • Long-Horizon Tasks: The current architecture might struggle with tasks requiring extremely long-term planning over thousands of steps.
  • Natural Language Integration: A promising next step is incorporating natural language instructions as high-level prompts to guide the in-context Q-learning process.
  • Distribution Shift: The authors plan to utilize the dynamics decoder at test time to detect when the environment has changed, allowing for even more robust adaptive learning.

Summary updated

BibTeX
@inproceedings{liu2026scalable,
  author = {Jinmei Liu and Fuhong Liu and Zhenhong Sun and Jianye HAO and Huaxiong Li and Bo Wang and Daoyi Dong and Chunlin Chen and Zhi Wang},
  title = {{Scalable In-Context Q-Learning}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=NuGAhTDYTd},
}
Figure