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. Comprehensive experiments show that T2MIR significantly facilitates in-context learning capacity and outperforms various types of baselines.
Introduction
In-Context Reinforcement Learning (ICRL) aims to develop "generalist" agents capable of adapting to novel tasks by observing a "prompt" of previous interactions, analogous to the few-shot capabilities of Large Language Models (LLMs). Despite its potential, ICRL is hindered by two primary obstacles:
- Intrinsic Multi-modality: RL data is composed of diverse signals—continuous physical states, high-frequency action torques, and sparse scalar rewards. Standard transformer architectures often struggle to process these disparate modalities effectively within a single layer.
- Task Heterogeneity and Gradient Conflicts: In multi-task environments, different tasks may demand contradictory actions in identical states (e.g., navigating to opposite goals). This leads to "gradient conflicts" during training, where the model receives inconsistent signals, impeding generalization.
The T2MIR Framework
To address these challenges, we introduce T2MIR, which replaces the standard feedforward layers in a Transformer block with two parallel Mixture-of-Experts (MoE) components.
Token-wise MoE
This component is designed to capture the distinct semantics of individual input tokens. Since states, actions, and rewards represent fundamentally different types of information, the router learns to assign them to specialized experts. Load-balancing and importance losses are employed to ensure even expert utilization and prevent collapse.
Task-wise MoE
This layer routes entire sequences to experts specialized in specific task categories. This modularity allows the model to handle broad task distributions while minimizing gradient interference between conflicting tasks.
Contrastive Routing
To refine task-wise routing, we incorporate a contrastive learning objective (InfoNCE). By maximizing the mutual information between a task and its router representation, the model becomes more adept at distinguishing between tasks, even when provided with limited data.
Experimental Evaluation
T2MIR was evaluated across several diverse benchmarks, including DarkRoom (grid-world), Point-Robot (2D navigation), Multi-task MuJoCo (locomotion control), and Meta-World (robotic manipulation). The framework was tested using various dataset qualities—Mixed, Medium-Expert, and Medium—to assess robustness.
Key Insights and Results
The integration of MoE into ICRL yields several significant advantages:
- Emergent Specialization: Visualization via t-SNE reveals that the Token-wise MoE naturally learns to cluster state, action, and reward tokens into distinct expert groups without explicit supervision. Similarly, the Task-wise MoE effectively differentiates between tasks based on their underlying dynamics or goals.
- Mitigating Gradient Conflicts: T2MIR drastically reduces gradient interference. In the Point-Robot environment, the baseline Algorithm Distillation (AD) model exhibited negative gradient correlations in 31.1% of task pairs; T2MIR-AD reduced this conflict rate to just 7.4%.
- State-of-the-Art Performance: T2MIR consistently outperformed competitive baselines such as AD, DPT, IDT, DICP, and UNICORN. It demonstrated faster adaptation, reaching higher returns in fewer in-context episodes.
- Robustness: While baselines often faltered on lower-quality "Medium" datasets, T2MIR maintained high performance, proving its ability to extract task-relevant information from suboptimal demonstrations.
Conclusion and Future Work
T2MIR demonstrates the power of MoE architectures in advancing In-Context Reinforcement Learning. By explicitly addressing multi-modality and task heterogeneity, it offers a scalable path toward more capable generalist agents. Future work will explore T2MIR's performance in massive-scale environments like XLand-MiniGrid and its potential integration into Vision-Language-Action (VLA) models to handle even more complex multi-modal inputs.
Summary updated