TL;DR
Teaching Large Language Models (LLMs) to use external tools usually requires a costly "cold-start" phase of supervised fine-tuning (SFT) before reinforcement learning (RL) can begin. This paper introduces In-Context Reinforcement Learning (ICRL), an RL-only framework that replaces SFT with a multi-stage curriculum of few-shot prompts during RL rollouts. By gradually phasing out these in-context examples, the model smoothly transitions from imitating tool-use demonstrations to autonomously executing tools in a zero-shot setting, achieving state-of-the-art performance with zero labeled training trajectories.
What Problem Does This Paper Address?
While LLMs are powerful reasoners, they are bottlenecked by their static pre-trained knowledge. Augmenting them with external tools—such as search engines or Python code execution interpreters—helps overcome this limitation. However, training models to use these tools effectively is notoriously difficult.
The dominant paradigm relies on a two-step process: Supervised Fine-Tuning (SFT) on high-quality tool-use trajectories, followed by Reinforcement Learning (RL). Generating or annotating these SFT trajectories is incredibly expensive and labor-intensive. On the other hand, attempting RL from scratch usually fails because the model lacks initial tool-use capabilities, leading to highly inefficient exploration and sparse rewards. ICRL addresses this data-efficiency bottleneck by using in-context learning as a temporary scaffolding mechanism during RL exploration.
Methods
ICRL combines the sample efficiency of few-shot prompting with the optimization power of RL using a simple yet elegant curriculum:
- In-Context Rollouts: At the start of training, a small number of few-shot examples demonstrating proper tool use (e.g., formatting reasoning steps and queries inside XML tags like
<think>and<search>) are prepended to the RL rollout prompts. This guides the model's initial exploration. - Curriculum Reduction: As training progresses and the model starts internalizing the tool-use behavior, the number of examples is systematically reduced (e.g., from 3-shot to 2-shot, and finally to 0-shot).
- Group Relative Policy Optimization (GRPO): The policy is optimized using GRPO, an RL algorithm that removes the need for a separate critic model by computing advantages within a sampled group of outputs.
- Loss Masking: Crucially, external tool outputs (the text returned by a search engine or interpreter) are masked out during the loss computation. This ensures the model only updates its parameters based on tokens it actually generated.
- Composite Reward: The reward function balances task accuracy (Exact Match) with format correctness (penalizing missing or unbalanced XML tags).
Datasets
- Training: Natural Questions (NQ), containing real Google Search queries paired with Wikipedia passages.
- Evaluation (Web Search QA): TriviaQA, HotpotQA, 2Wiki, Musique, and Bamboogle. These include both in-domain general QA and challenging out-of-domain multi-hop reasoning tasks.
- Evaluation (Math QA / Code Execution): AIME2024 and AIME2025 benchmarks were used to test the framework's generalizability to code execution tools.
Key Insights and Ideas
- Scaffolding over Fine-Tuning: In-context examples act as "soft supervision." Instead of permanently baking behavior in via SFT weights, prompting guides the exploration phase of RL until the policy can stand on its own.
- The Danger of Aggressive Pruning: The authors discovered that a simpler 3 $\rightarrow$ 2 $\rightarrow$ 0 shot curriculum significantly outperformed a 4-stage 3 $\rightarrow$ 2 $\rightarrow$ 1 $\rightarrow$ 0 shot curriculum. Dropping down to a 1-shot prompt too early caused the model to prematurely stop its reasoning paths and perform worse on multi-hop tasks. Allowing the model more time to explore longer reasoning paths with more context before going straight to zero-shot yields better final policies.
- Format vs. Content: By decoupling format rewards from accuracy rewards and using loss masking, the model learns how to interact with the environment structurally before it fully masters what to ask to get the right answer.
Key Results
- State-of-the-Art Performance: ICRL significantly outperformed existing SFT+RL and RL-from-scratch baselines. On Qwen2.5-3B, it achieved an average exact match (EM) accuracy of 40.16%, beating the next best method (Search-R1) by +8.94%. On Qwen2.5-7B, it achieved 49.12%, outperforming ParallelSearch by +7.34%.
- SFT-Free Superiority: ICRL beat $O^2$-Searcher (an agent model that uses a cold-start SFT phase) on four out of five datasets, proving that explicit supervised pre-training on tool traces is unnecessary.
- Cross-Domain Generalization: When applied to math problem-solving using a Python interpreter (AIME benchmarks), ICRL matched or exceeded ReTool, a state-of-the-art SFT+RL baseline, despite using zero supervised training data.
Limitations and Future Work
- Prompt Length Overhead: In the early stages of training, prepending few-shot examples increases the prompt length (up to 5000 tokens in their setup), which increases computational overhead during the initial RL rollouts.
- Heuristic Reward Penalties: The format reward relies on hand-crafted penalties for XML violations, which might require tuning when adapting to highly complex or diverse tool APIs.
- Future Directions: The authors suggest exploring more complex multi-tool environments and automatically optimizing the curriculum schedule based on real-time model performance rather than fixed step intervals.
Summary updated