# Where Should LLM Agents Adapt at Test Time? In Context, in Weights, or Both

In-context learning gives LLM agents the largest gain, and weight updates add on top

Parsa Mirtaheri, Mohammadreza Armandpour, Keivan Alizadeh, Iman Mirzadeh, Parshin Shojaee, Aryo Lotfi and 2 more · arXiv · 2026-11-15

- **Problem** Context-based and weight-based adaptation are usually studied apart, so it is unclear what each contributes and when they complement each other.
- **Method** The authors compare in-context learning, GRPO and SDPO on matched task streams. Each task is scored before the agent adapts, and learning uses only its own attempts and feedback.
- **Results** In-context learning raised mean success from 28.8% to 49.4%, and adding GRPO reached 51.6%.

## Why adaptation channel choice matters

An LLM agent that works repeatedly in one environment meets tasks that share latent structure specific to that environment. Experience from earlier tasks can reveal that structure, so a later task can be solved with fewer queries. For a fixed architecture, the policy is governed by the context and the weights, so experience has only two routes to change behavior.

The open question is which of those two channels should carry the experience forward.

Context is cheap to change, because adding experience to the prompt needs no training and the next task can use it at once. Context is also bounded by the context window, so different experiences compete for room. Conditioning the model on a long context also adds computational cost.

Test-time training methods instead write experience into the weights. Systems that optimize a prompt together with model weights suggest the two channels can complement each other.

The authors study this with a controlled comparison built on streams of tasks that share one environment. Their research questions ask what each channel contributes, whether combining them helps, and how the two should be coordinated. Their four worlds cover SWE-bench Verified, AppWorld, ScienceWorld, and BIRD-Critic-SQLite.

## A stream of related tasks as the test bed

Xarray comes from SWE-bench Verified, where the agent resolves issues of pydata/xarray with shell commands, for 22 tasks. Financial comes from BIRD-Critic-SQLite, where the agent fixes faulty SQL for one database that it can query before submitting, for 44 tasks. Across the four worlds this gives 109 tasks, and each world runs under five task orders.

For each task, the agent makes m rounds of k parallel attempts, and each attempt is a multi-turn session with a fresh copy of the environment. The benchmark then returns an outcome with a reward, a success flag and textual feedback, such as how many tests passed.

Only the first round of each task is scored, before any adaptation to that task. This score-then-update order means each task tests transfer from earlier tasks rather than memory of its own attempts. Because the framework reuses each benchmark's tasks, environments and graders, other benchmarks can be added the same way.

Mechanisms learn only from their own attempts and the environment's outcomes, which keeps the comparison matched across context and weights. Raw-trajectory replay keeps the source of experience consistent across mechanisms, without extra summarization or retrieval steps. The gain of each mechanism is measured against the same agent run without adaptation.

## How each mechanism carries experience forward

The design runs every mechanism on the same stream, so context-only, weight-only and combined adaptation can be compared on equal terms. ICL replays earlier attempts as conversation turns, including environment observations and outcome feedback. Under a bounded token allowance, the retention rule decides what gets dropped: FIFO evicts the oldest episodes, while Prefix stops admitting episodes after the first overflow.

The admission rule decides which attempts qualify, with All taking the highest-reward attempt from each round even if it failed, and Successful taking at most one successful attempt per task. Crossing two retention rules with two admission rules gives four ICL policies.

GRPO updates a persistent LoRA adapter from each round's attempts, scoring each attempt by its reward relative to the round mean. It uses PPO's clipped surrogate loss, without a KL penalty or standard-deviation normalization. The self-teacher sees the original context plus a successful sibling attempt, or the attempt's feedback when no sibling succeeded.

A hybrid pairs one ICL policy with one weight-update rule, so the same attempts feed both channels. The adapter trains on those attempts conditioned on the context that produced them, while the ICL policy chooses which attempts stay in context for later attempts. In total the study compares fourteen adaptation mechanisms with the stateless baseline, which runs with frozen weights and no retained experience.

## Scoring each task before adapting to it

Each task is scored on its first round, before the mechanism adapts to that task. Later rounds on the same task still produce experience, but they never enter the main score. This keeps each task testing transfer from earlier tasks rather than its own experience.

Each mechanism completes its updates before the next round, so the order of scoring and adapting is fixed. For task j, the first-round success rate p\_j is the mean of the binary success flags s\_j,i over the k attempts. The world's success rate S averages p\_j over its N tasks, and the gain ΔS is the difference from the stateless baseline.

Each round draws 16 parallel attempts at temperature 1, and the scored round is always the first one. Because the stream and the scoring rule are shared, a gain over the baseline reflects the mechanism rather than a different set of tasks.

## Context gives the largest single gain

With frozen weights, the four ICL policies raise mean success from the baseline's 28.8% to between 43.5% and 49.4%. Prefix·Successful is the strongest ICL policy, so admitting only successful attempts gives the best standalone result. Both Successful-admission policies beat the baseline in all 20 stream pairs, as Appendix Figure 11 shows.

All-admission policies sometimes lower success on AppWorld or BIRD, so what gets admitted matters as much as whether ICL runs.

GRPO improves on the baseline in 19 of 20 pairs, so its gain is consistent even though it is smaller.

Adding GRPO raises the overall mean under all four ICL policies, so the weight update helps on top of context. The largest gain is 6.3 percentage points for Prefix·All, which improves in all 20 stream pairs. Under the other three policies, GRPO improves success in 13 to 14 of the 20 pairs. The three highest means all come from ICL with GRPO, led by 51.6% for Prefix·Successful.

On seed 4 of the scikit-learn and Toxicology worlds, ICL with GRPO ranks highest among the six mechanisms tested there. The gain from adding GRPO to the best ICL policy is smaller than ICL's own gain over the 28.8% baseline. So the two channels read as partly overlapping sources of improvement rather than as independent additions.

## Why ICL shortens attempts but can skip checks

ICL shortens attempts along every stream, and the drop is largest on AppWorld and BIRD. The authors attribute the shorter attempts to reuse: retained experience records the environment's structure, so the agent doesn't rediscover it on each task.

That reduction holds in every seed, which the authors read as less repository exploration inside shorter attempts. On AppWorld, API-documentation lookups fall toward zero under ICL, alongside shorter attempts and higher success. GRPO and SDPO stay near the baseline on that measure. In the vacation-photo example, the ICL attempt makes one documentation lookup, while the Frozen attempt makes seven.

On BIRD, ICL increasingly submits without any exploratory query, and SDPO also reduces querying. GRPO keeps querying in a larger share of attempts than ICL or SDPO does. Shorter BIRD attempts leave fewer chances to test a proposed SQL answer, which doesn't hold for the AppWorld lookups. ICL raises success on BIRD, but it also produces more wrong submissions.

Fewer turns don't automatically mean a safer outcome, because finding task-specific information and checking a proposed solution may still need new interactions. The authors conclude that effective adaptation should reuse environment knowledge while keeping the exploration and verification each new task needs.

## Where GRPO restores task-specific checks

The authors examine the hybrid ICL with GRPO against ICL alone to see whether the shortcut savings survive. Adding GRPO keeps ICL's reduced code, API and environment lookups on SWE-bench, AppWorld and ScienceWorld, so success improves while lookups stay low.

On BIRD, querying falls under ICL and then recovers toward the frozen baseline later in the stream once GRPO is added. The same late-stream pattern appears under all four ICL policies.

On AppWorld, adding GRPO raises final-state inspection while API lookups stay reduced, and SDPO stays close to ICL. On ScienceWorld, GRPO raises state inspection toward the frozen baseline, and SDPO shows no comparable rise. On SWE-bench both weight updates increase rechecking after edits, with the larger increase under GRPO.

The authors suggest that GRPO refines behavior the retained context encourages but the current reward doesn't favor. Their self-distillation explanation is different: the SDPO self-teacher may pull the student toward skipping exploration, and this remains a hypothesis.

## Limitations of the context and weights comparison

The chosen metrics and the specific update recipes may not generalize to every ICL policy. The authors used raw-trajectory context policies, so summarization or retrieval machinery was not part of the comparison.

The behavioral metrics don't establish what causes the success gains. Inspection and verification give the agent chances to receive feedback, but the metrics don't show whether it uses that feedback correctly. Interventions that require or suppress these checks would be needed to test how much they contribute. The SDPO self-teacher explanation remains a hypothesis that the authors didn't test directly.

Self-distillation may share some limits of ICL, reinforcing similar shortcuts instead of correcting them.

GRPO adds more to Prefix than to FIFO under All admission, but the gains are similar under Successful admission. Transfer and component ablations of the final seed-4 agents appear separately in Appendix F.

## Paper info

- **Authors**: Parsa Mirtaheri, Mohammadreza Armandpour, Keivan Alizadeh, Iman Mirzadeh, Parshin Shojaee, Aryo Lotfi, David Harrison, Mehrdad Farajtabar
- **Venue**: arXiv · Preprint
- **First published**: 2026-11-15
- **Added**: 2026-11-17
- **Updated**: 2026-11-15
- **Version**: v1
- **arXiv**: 2611.19700
- **Category**: cs.LG · cs.AI · cs.CL
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2611.19700v1) · [PDF ↗](https://arxiv.org/pdf/2611.19700v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

LLM agents operating repeatedly in the same environment, such as a code repository, a database, or an application suite, encounter tasks that share latent structure. Experience can reveal this structure, allowing agents to reuse environment knowledge and learn from environmental feedback. Agents can adapt at test-time using this experience through two channels: retaining it in context and updating their weights. These channels are usually studied separately, leaving unclear what each contributes and when they complement each other. We compare in-context learning (ICL), reinforcement learning with verifiable rewards using GRPO, and self-distillation using SDPO, alone and in combination, using a shared online protocol and modular framework. Agents encounter matched task streams, are evaluated on each task before adapting to it, and learn only from their own attempts and environment feedback. We evaluate 14 adaptation mechanisms and a stateless baseline with Qwen3.5-9B on 109 tasks from four environments drawn from SWE-bench Verified, AppWorld, ScienceWorld, and BIRD-Critic-SQLite, using five task orders per environment. ICL provides the largest standalone gain: its best policy raises mean success across environments from 28.8% to 49.4%. Adding GRPO to this policy achieves the highest mean success, 51.6%. While adding GRPO improves the overall mean under every ICL policy, SDPO has mixed effects. Trace analyses show fewer lookups and shorter attempts under ICL, consistent with reusing knowledge of the shared structure. However, ICL also frequently skips inspection and verification for the current task. Adding GRPO to ICL helps restore these behaviors while preserving its reduced environment lookups. These observations suggest that reinforcement learning with verifiable rewards can refine how agents use retained experience, motivating the joint study of context management and weight updates.

## Quote from the paper

Parsa Mirtaheri, Mohammadreza Armandpour, Keivan Alizadeh, Iman Mirzadeh, Parshin Shojaee, Aryo Lotfi, David Harrison, Mehrdad Farajtabar (2026). Where Should LLM Agents Adapt at Test Time? In Context, in Weights, or Both. arXiv:2611.19700v1. https://arxiv.org/abs/2611.19700v1

**BibTeX**

```
@misc{mirtaheri2026where,
  title = {{Where Should LLM Agents Adapt at Test Time? In Context, in Weights, or Both}},
  author = {Parsa Mirtaheri and Mohammadreza Armandpour and Keivan Alizadeh and Iman Mirzadeh and Parshin Shojaee and Aryo Lotfi and David Harrison and Mehrdad Farajtabar},
  year = {2026},
  eprint = {2611.19700},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.19700v1}
}
```

## Other paper commentary

- [Beyond Plain MCP: Do Decision Models and Code Mode Make Tool Use Cheaper and Faster?](https://refivu.com/en/papers/88efe713-93d8-47d6-b8be-667c299e21ae-beyond-plain-mcp-do-decision-models-and-code.md)
- [Distilling Safety Filters for Filter-free Multi-agent RL](https://refivu.com/en/papers/21f25915-d36f-4f26-a265-4e45ef0cc511-distilling-safety-filters-for-filter-free-multi-agent.md)
- [Imitation Bootstrapped Multi-Agent Reinforcement Learning](https://refivu.com/en/papers/511a869c-410d-47b0-9d94-36dde9bb5cef-imitation-bootstrapped-multi-agent-reinforcement-learning.md)
- [Agentic AI for Discovering Fault-Tolerant Quantum Circuits](https://refivu.com/en/papers/e6680a5e-8c8b-48e6-aa57-a669a9a0c6a1-agentic-ai-for-discovering-fault-tolerant-quantum-circuits.md)
- [Do Verifier Judgments Survive Abstraction? Measuring Verification Transport for LLM Agent Evaluation](https://refivu.com/en/papers/14bd2e4c-85ea-4184-a7c7-04ab89b28c5b-do-verifier-judgments-survive-abstraction-measuring.md)
- [Do Machines Learn Deviance From Their Peers? A Randomized Test of Differential Association With AI Agents](https://refivu.com/en/papers/58c15c7f-5939-4116-a0a3-1907381f3dd8-do-machines-learn-deviance-from-their-peers-a.md)
- [ROUNDS: Source-Framed Diagnostic Revision after Multi-Turn Clinical Evidence](https://refivu.com/en/papers/70f56aaf-6635-4760-874c-f2838c87a8ac-rounds-source-framed-diagnostic-revision-after-multi-turn.md)
- [LLM Trading Agents Earn Beta, Not Alpha: A Look-Ahead-Free Benchmark](https://refivu.com/en/papers/0b5e933e-a378-4fe4-8e1f-5ea009d86411-llm-trading-agents-earn-beta-not-alpha-a.md)
- [Do Probing and Steering Favor the Same Directions Within and Across Language Models?](https://refivu.com/en/papers/e8384f8c-0c68-4463-a9b8-a660e20c616c-do-probing-and-steering-favor-the-same-directions.md)
- [Predicting, Fast and Slow: SSD Already Knows Which Guess Is Wrong](https://refivu.com/en/papers/2072ed08-6618-4ac5-bbf3-169d7b94921f-predicting-fast-and-slow-ssd-already-knows-which.md)
- [Isolating Perception for Multi-View Planning under Occlusion-Induced Partial Observability](https://refivu.com/en/papers/6ac42b45-0624-43a7-9143-e917da2b7cc2-isolating-perception-for-multi-view-planning-under-occlusion.md)
- [Latency, Speech Recognition and Turn-Taking in Voice Agents for Spanish Phone Negotiation: An Externally Measured Comparison of Pipecat, LiveKit and GPT-Live](https://refivu.com/en/papers/c1b5695f-c69b-4548-a3bd-417b75affe95-latency-speech-recognition-and-turn-taking-in-voice.md)

## Terms in this paper

- [LoRA](https://refivu.com/en/terms/bee764895c36-lora)
- [GRPO](https://refivu.com/en/terms/17129d1bafd8-grpo)
- [in-context learning](https://refivu.com/en/terms/d53d2af6b551-in-context-learning)
- [Prefix](https://refivu.com/en/terms/add1416d36e4-prefix)
- [SDPO](https://refivu.com/en/terms/8e0da1a25059-sdpo)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/39fae58e-bc8b-4dc6-bf76-acf24f94a299-where-should-llm-agents-adapt-at-test-time)
