NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Can large language models explore in-context?

Akshay Krishnamurthy, Keegan Harris, Dylan J Foster, Cyril Zhang, Aleksandrs Slivkins

Introduction

In-context learning (ICL) has demonstrated remarkable success in enabling Large Language Models (LLMs) to solve supervised tasks like classification and regression through few-shot prompting. However, real-world decision-making often involves a fundamental challenge: the exploration-exploitation tradeoff. This requires an agent to occasionally choose suboptimal actions to gather information, potentially leading to better long-term outcomes. This paper investigates whether contemporary LLMs, such as GPT-4, possess an innate ability to perform such exploration in-context without explicit fine-tuning.

Methodology

The authors evaluate LLMs as agents within synthetic Multi-Armed Bandit (MAB) environments, the simplest framework for studying exploration. They explore a vast prompt design space, testing variables such as task framing (e.g., "pressing buttons" vs. "displaying ads"), history representation (raw vs. summarized statistics), and reasoning methods (direct answers vs. Chain-of-Thought (CoT)).

Performance is measured against standard reinforcement learning (RL) baselines: Upper Confidence Bound (UCB), Thompson Sampling (TS), and a Greedy algorithm. To diagnose long-term failures, the authors introduce Suffix Failure Frequency, which tracks how often a model permanently stops selecting the optimal arm.

Results: The Necessity of Prompt Engineering

The study reveals that LLMs do not explore "out of the box." Most configurations default to a greedy strategy, quickly converging on a suboptimal choice and failing to revisit the best arm—a phenomenon termed "suffix failure."

Comparison of standard GPT-4 vs. GPT-4 with Chain-of-Thought (CoT) and summarized history. The top row shows standard GPT-4 failing to explore effectively, while the bottom row shows GPT-4-CoT matching the performance of Thompson Sampling (TS).

As shown in the figure above, standard GPT-4 (top row) exhibits high suffix failure and lower rewards compared to UCB and TS. However, when provided with summarized history (sufficient statistics) and instructed to use Chain-of-Thought reasoning (bottom row), GPT-4's performance improves dramatically, matching the gold-standard Thompson Sampling algorithm.

Bimodal Behavior and the "Greedy" Trap

A key insight is the bimodal nature of LLM performance. In many replicates, the model either identifies the best arm almost immediately or fails to pick it entirely after the initial rounds. This suggests that their reasoning is brittle and highly sensitive to early random noise.

Distribution of the number of times the best arm was played. GPT-4 (top) shows a heavy concentration at low play counts (failure), while GPT-4-CoT (bottom) shows a more balanced distribution, indicating more robust exploration.

This bimodal distribution illustrates the "greedy trap." Standard GPT-4 often falls into a state where early noise leads it to abandon the best arm. The addition of CoT and summarization helps the model overcome this sensitivity, though the reasoning remains less robust than formal mathematical algorithms.

Discussion and Future Work

While GPT-4 can be coaxed into exploring, its success is highly dependent on external summarization of interaction history. LLMs struggle with the mental arithmetic needed to aggregate raw data into the averages required for informed decision-making.

Future research directions include:

  1. Fine-tuning models on RL trajectories to internalize exploratory logic.
  2. Tool-use integration, allowing LLMs to leverage calculators or randomizers to implement formal RL algorithms.
  3. Complex Environments, extending evaluations to contextual bandits and high-dimensional tasks where summarization is less straightforward.

In conclusion, while LLMs show a "spark" of exploratory capability, robust in-context exploration currently requires significant prompt engineering and external data processing.

Summary updated

BibTeX
@inproceedings{krishnamurthy2024can,
  author = {Akshay Krishnamurthy and Keegan Harris and Dylan J Foster and Cyril Zhang and Aleksandrs Slivkins},
  title = {{Can large language models explore in-context?}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=OWPzhVqIux},
}
Figure