Abstract
Large Language Models (LLMs) have traditionally relied on supervised demonstrations for In-Context Learning (ICL). This paper explores a more autonomous paradigm: In-Context Reinforcement Learning (ICRL). We demonstrate that LLMs can function as contextual bandit learners, improving their performance on-the-fly through trial-and-error feedback. By introducing Stochastic ICRL, which utilizes randomized prompt construction to encourage exploration, we show that models can achieve significant accuracy gains without parameter updates.
Introduction
Standard ICL requires high-quality, human-labeled "gold" examples. However, many real-world applications provide only sparse reward signals, such as user feedback or execution success. This research investigates whether LLMs can bridge this gap by learning from a history of interactions consisting of inputs, predicted outputs, and binary rewards.
Methods: Eliciting Reinforcement Learning
The study evaluates several strategies for managing the interaction history within the model's context window:
- Naive ICRL: Includes the full history of all past interactions, regardless of the reward received.
- Naive+ ICRL: Filters the history to include only successful episodes (positive rewards), mimicking the structure of standard supervised ICL.
- Stochastic ICRL: The primary contribution of this work. Instead of a static history, this method randomly samples a subset of past successful episodes for each new query. This stochasticity in prompt construction acts as a mechanism for exploration, preventing the model from converging prematurely on incorrect patterns.
Experimental Results
The methods were tested on five many-label classification tasks, including Banking77 (77 labels) and CLINC150 (150 labels).
Performance Gains
Stochastic ICRL consistently outperformed other methods. For instance, on the Banking77 dataset, Qwen2.5-7B improved its accuracy from a 6.2% zero-shot baseline to 72.2%.
The "Positive-Only" Learning Trait
A key finding is that LLMs are primarily "positive-only" learners in this context. Including negative-reward episodes (Naive ICRL) often hindered performance. Models learned most effectively when the context was curated to show only what did work, suggesting that current LLMs struggle to implicitly reason about what not to do from raw feedback.
Scaling and Stability
The ability to perform ICRL scales with model size. Larger models (up to 72B parameters) demonstrated higher peak accuracy and greater stability over long interaction sequences. Furthermore, experiments with "Abstract Labels" (replacing semantic names with arbitrary strings) confirmed that models are truly learning the mapping from feedback rather than relying solely on pre-trained semantic priors.
Conclusion
LLMs possess a latent ability to act as reinforcement learners within their context window. Stochastic ICRL provides a robust framework for unlocking this capability, enabling models to adapt to complex, many-label tasks through simple binary feedback. Future work will explore multi-step RL environments and methods to help models learn more effectively from negative examples.
Summary updated