Mixture-of-Experts Meets In-Context Reinforcement Learning

Wenhao Wu, Fuhong Liu, Haoru Li, Zican Hu, Daoyi Dong, Chunlin Chen, Zhi Wang

TL;DR

The paper introduces T2MIR (Token- and Task-wise MoE for In-context RL), a novel framework that integrates the Mixture-of-Experts (MoE) architecture into transformer-based decision models. By deploying parallel token-wise and task-wise MoE layers, T2MIR successfully addresses the challenges of multi-modal data streams and task heterogeneity, significantly boosting the adaptation speed and performance of reinforcement learning agents on unseen tasks.

What Problem Does This Paper Address?

In-Context Reinforcement Learning (ICRL) allows an agent to adapt to new downstream tasks purely through prompt conditioning (using past experiences as context) without updating its model weights. While promising, ICRL faces two major bottlenecks:

  1. Intrinsic Multi-Modality: Unlike language models that process uniform text tokens, ICRL models must digest sequences of states (continuous physical quantities or images), actions (high-frequency control signals), and rewards (sparse scalars). These modalities possess vastly different semantic structures.
  2. Task Diversity and Heterogeneity: Training a single model across highly diverse tasks often triggers gradient conflicts. For example, two navigation tasks with opposite destination goals will demand completely contrary actions under the identical state, causing opposing gradients that stall the learning process.

Methods

To overcome these challenges, the authors propose T2MIR, which replaces the standard feedforward network (FFN) in transformer blocks with two parallel MoE layers:

  • Token-wise MoE: This layer automatically routes individual tokens to specialized experts based on their modality (state, action, or reward). To prevent all tokens from collapsing onto a few favorite experts, the authors incorporate load-balancing and importance regularization losses.
  • Task-wise MoE: This layer uses sparse routing to assign diverse tasks to specialized task-level experts, effectively isolating distinct task behaviors and mitigating gradient conflicts.

To make task routing more precise, the authors introduce a contrastive learning method (InfoNCE loss). It maximizes the mutual information between a task and its router representation, ensuring the model captures task-relevant features while remaining invariant to behavior policies. The outputs of both MoE components are concatenated and passed to the next transformer layer.

Overview of the T2MIR framework, highlighting the parallel token-wise and task-wise MoE architecture.

T2MIR is highly flexible and was successfully implemented on top of two mainstream ICRL backbones: Algorithm Distillation (T2MIR-AD) and Decision-Pretrained Transformer (T2MIR-DPT).

Datasets

The framework was evaluated across several multi-task reinforcement learning benchmarks using offline datasets of varying qualities (Mixed, Medium-Expert, and Medium):

  • DarkRoom: A discrete grid-world environment with multiple goals.
  • Point-Robot: A 2D navigation environment.
  • MuJoCo Locomotion: Cheetah-Vel (running at target velocities) and Walker-Param (locomotion with randomized physical parameters like friction and mass).
  • Meta-World: Robotic manipulation tasks (Reach and Push).
  • Ant-Dir & ML10: Evaluated in the appendix to test scalability on harder task suites.

Key Insights and Ideas

  • Natural Modality Clustering: t-SNE visualizations revealed that the token-wise MoE naturally segregates tokens by their semantic modality (states, actions, rewards) into distinct expert clusters without manual labeling.
  • Task Space Separation: The task-wise MoE successfully maps similar tasks closely together and separates distinct ones based on task parameters (like target velocity), as seen in the visualization below.
Figure 1: t-SNE visualization of expert assign- ments on Cheetah-Vel where tasks differ in target velocities. Left: token-wise MoE enables differ- ent experts to process tokens with distinct seman- tics. Right: task-wise MoE effectively manages a broad task distribution, where the difference between expert assignments is positively related to the difference between tasks.
  • Gradient Conflict Resolution: By routing conflicting tasks to different experts, T2MIR maintains nearly orthogonal gradients across diverse tasks, preventing opposing objectives from canceling each other out during training.
  • Backbone Synergy: Ablation studies showed that the token-wise MoE is more vital for the AD backbone (which handles long historical contexts), whereas the task-wise MoE is more critical for the DPT backbone (which relies on short, precise task prompts).

Key Results

T2MIR consistently outperformed strong baselines (including vanilla AD, DPT, DICP, IDT, and UNICORN) across almost all environments in both learning efficiency and final asymptotic return.

  • Cheetah-Vel (Mixed Dataset): T2MIR-DPT achieved a top score of -43.2, significantly outperforming vanilla DPT (-56.1) and AD (-119.2).
  • Meta-World Reach: T2MIR-AD reached a return of 823.9, outperforming vanilla AD (790.4) and IDT (808.5).
  • Robustness to Low-Quality Data: When trained on suboptimal Medium datasets, standard baselines suffered severe performance drops. T2MIR maintained stable, high-tier performance, proving its viability for real-world scenarios where expert data is scarce.

Limitations and Future Work

While T2MIR demonstrates clear architectural benefits, the authors note a few limitations:

  • Lightweight Datasets: Due to compute constraints, the model was validated on relatively small datasets. Testing T2MIR on massive datasets like XLand-MiniGrid is an essential next step to unlock its true scaling properties.
  • Massive Task Scaling: The efficiency of the contrastive loss router when dealing with a massive or infinite number of tasks remains an open question.
  • VLA Integration: A promising future direction is deploying T2MIR within Vision-Language-Action (VLA) models, which inherently deal with high multi-modality and diverse task distributions.

Summary updated

Abstract

In-context reinforcement learning (ICRL) has emerged as a promising paradigm for adapting RL agents to downstream tasks through prompt conditioning. However, two notable challenges remain in fully harnessing in-context learning within RL domains: the intrinsic multi-modality of the state-action-reward data and the diverse, heterogeneous nature of decision tasks. To tackle these challenges, we propose T2MIR (Token- and Task-wise MoE for In-context RL), an innovative framework that introduces architectural advances of mixture-of-experts (MoE) into transformer-based decision models. T2MIR substitutes the feedforward layer with two parallel layers: a token-wise MoE that captures distinct semantics of input tokens across multiple modalities, and a task-wise MoE that routes diverse tasks to specialized experts for managing a broad task distribution with alleviated gradient conflicts. To enhance task-wise routing, we introduce a contrastive learning method that maximizes the mutual information between the task and its router representation, enabling more precise capture of task-relevant information. The outputs of two MoE components are concatenated and fed into the next layer. Comprehensive experiments show that T2MIR significantly facilitates in-context learning capacity and outperforms various types of baselines. We bring the potential and promise of MoE to ICRL, offering a simple and scalable architectural enhancement to advance ICRL one step closer toward achievements in language and vision communities. Our code is available at https://github.com/NJU-RL/T2MIR.
BibTeX
@inproceedings{wu2025mixture,
  author = {Wenhao Wu and Fuhong Liu and Haoru Li and Zican Hu and Daoyi Dong and Chunlin Chen and Zhi Wang},
  title = {{Mixture-of-Experts Meets In-Context Reinforcement Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=VMqxRPqdPw},
}
Figure