[KongchangAI]
· 2 min read· 1,119 words

Where Should LLM Agents Adapt at Test Time: Context or Weights?

Where Should LLM Agents Adapt at Test Time: Context or Weights?

Research compares in-context learning and weight updates as adaptation paths, finding their combination works best.

This study systematically compares two channels for LLM agent test-time adaptation: in-context learning (ICL) and weight updates (GRPO reinforcement learning, SDPO self-distillation). Experiments on Qwen3.5-9B cover 109 tasks across SWE-bench Verified, AppWorld, ScienceWorld, and BIRD-Critic-SQLite, using matched task streams and an evaluate-before-adapt protocol. ICL provides the largest independent gain, raising the average success rate from 28.8% to 49.4%; adding GRPO reaches the highest 51.6% and improves under every ICL strategy, while SDPO yields mixed results. Trajectory analysis shows ICL reduces environment lookups but often skips verification, and GRPO restores these behaviors. The authors recommend jointly studying context management and weight updates.

LLM agents repeatedly executing tasks in fixed environments—code repositories, databases, or application suites—keep encountering tasks that share latent structure. Experience can reveal this structure, allowing agents to reuse environment knowledge and learn from feedback. But should the adaptation process rely on retaining experience in context, or on updating model weights? A new study systematically compares these two paths and offers an illuminating answer.

Study title screenshot

Two Adaptation Channels: Context and Weights

The research team divides test-time adaptation into two channels: one that retains experience in context (In-Context Learning, ICL), and one that updates weights via reinforcement learning or self-distillation. In the past, these two paths were usually studied separately, leaving it unclear what each contributes and when they complement each other.

To clarify this, the authors compare three mechanisms under a shared online protocol and modular framework: in-context learning, reinforcement learning with verifiable rewards using GRPO, and self-distillation using SDPO. Agents face matched task streams, are evaluated before adapting to each task, and learn only from their own attempts and environment feedback.

GRPO (Group Relative Policy Optimization) is a reinforcement learning algorithm proposed by DeepSeekAd, a simplified variant of PPO. Instead of relying on a separately trained value network (critic), it samples a group of responses for the same prompt and computes the advantage function from the relative magnitudes of rewards within the group, thereby eliminating the memory and compute overhead of a value model. In scenarios with verifiable rewards (e.g., code passing tests, SQL executing successfully), the reward signal is rule-based and automatically determinable, so GRPO can directly optimize the policy without human preference annotations. This makes it particularly suitable for settings where agents learn online from environment feedback: the success or failure of each attempt can be converted into a training signal.

SDPO (Self-Distillation Policy Optimization) represents the self-distillation route: the model uses better trajectories generated by itself (or historical versions) as supervision targets, updating weights through imitation rather than directly performing policy gradients based on environment rewards. Self-distillation can compress and internalize experience, but without explicit reward signals it tends to reinforce existing behavioral biases, which explains the mixed results observed for SDPO in this paper.

Experimental Setup: Multiple Environments and Task Streams

Experiments are conducted on the Qwen3.5-9B model, covering four environments: SWE-bench Verified, AppWorld, ScienceWorld, and BIRD-Critic-SQLite, totaling 109 tasks. Each environment uses five task orders to test the stability of the adaptation mechanisms. The study evaluates 14 adaptation mechanisms plus a stateless baseline.

The key to this design is "matched task streams" and "evaluate before adapting"—agents cannot see task answers in advance and can only accumulate experience through their own attempts, thereby simulating online learning in real deployment.

The four evaluation environments test different capabilities: SWE-bench Verified is a real GitHub issue-fixing benchmark requiring agents to locate and modify code in a repository so that tests pass; AppWorld provides simulated everyday applications and API suites, testing multi-step interaction and state management; ScienceWorld is a text-based scientific experiment environment focused on long-horizon reasoning and exploration; BIRD-Critic-SQLite targets natural language to SQL generation and correction. What they share is that tasks share underlying structure (the same repository, the same API semantics, the same database schema), which is precisely the source of reusable experience for agents.

Task stream refers to the sequence in which tasks are presented to the agent in a particular order. The reason for setting five different orders is that online adaptation is highly sensitive to task ordering—if similar tasks appear consecutively, agents more easily accumulate reusable knowledge; shuffling the order tests the stability and generalization of the mechanisms. The stateless baseline refers to an agent that retains no cross-task experience and starts from scratch for each task, used to measure the net gain from adaptation.

In-Context Learning Contributes Most, GRPO Adds the Finishing Touch

Results show that ICL provides the largest independent gain: its best strategy raises the cross-environment average success rate from 28.8% to 49.4%. Adding GRPO on top achieves the highest average success rate of 51.6%.

Interestingly, adding GRPO under every ICL strategy improves the overall mean, indicating that the combination of reinforcement learning and in-context learning is robust. In contrast, SDPO's results are mixed and show no stable gain.

This finding aligns with intuition: in-context learning directly leverages shared structural knowledge in the environment, allowing agents to quickly reuse experience; GRPO further fine-tunes how agents use this experience, and the two are complementary.

Behavioral Analysis: ICL Reduces Lookups but May Skip Verification

Trajectory analysis reveals deeper mechanisms. Under ICL, agents exhibit fewer lookups and shorter attempts, consistent with reusing shared structural knowledge—agents do not need to explore the environment from scratch each time.

But ICL also brings a side effect: agents often skip checking and verifying the current task. In other words, experience reuse makes agents "confident" but may cause them to overlook the uniqueness of the current task.

Adding GRPO to ICL helps restore these checking and verification behaviors while preserving ICL's advantage of reducing environment lookups. This indicates that reinforcement learning with verifiable rewards can refine how agents use retained experience rather than simply replacing in-context learning.

Implications: Context Management and Weight Updates Need Joint Research

The core message of this study is: in-context learning and weight updates are not an either-or choice. ICL excels at quickly reusing environment knowledge, while GRPO can correct behavioral biases introduced by experience reuse; only their combination achieves the best results.

The authors therefore propose that future work should jointly study context management and weight updates rather than separating them. For building LLM agents that operate long-term in fixed environments, this idea has direct engineering guidance—agents should both remember the structure of the environment and learn to remain cautious in the face of specific tasks.

In the design of test-time adaptation, context provides "what to know," while weight updates adjust "how to act." Their synergy may be the key to agents continuously evolving in complex environments.

One-line Summary

A study compares two adaptation paths—in-context learning and weight updates—and finds that combining them works best.

Paragraph Summary

This study systematically compares two channels for LLM agent test-time adaptation: in-context learning (ICL) and weight updates (GRPO reinforcement learning, SDPO self-distillation). Experiments on Qwen3.5-9B cover 109 tasks across four environments—SWE-bench Verified, AppWorld, ScienceWorld, and BIRD-Critic-SQLite—using matched task streams and an evaluate-before-adapt protocol. Results show that ICL provides the largest independent gain, raising the average success rate from 28.8% to 49.4%; adding GRPO reaches the highest 51.6% and improves under every ICL strategy, while SDPO's results are mixed. Trajectory analysis shows that ICL reduces environment lookups but often skips verification, and GRPO can restore these behaviors. The authors accordingly recommend jointly studying context management and weight updates.

#LLM agents#test-time adaptation#in-context learning#GRPO#SDPO#reinforcement learning#Qwen3.5-9B
Share:

Related articles