Papers
Topics
Authors
Recent
Search
2000 character limit reached

In-Context Environment Learning

Updated 12 July 2026
  • ICEL is a framework where models adapt at inference time by conditioning on structured contextual environments without updating their weights.
  • It leverages diverse context sources—such as demonstration neighborhoods, trajectory histories, and multimodal episodes—to infer latent regularities and boost prediction accuracy.
  • ICEL bridges non-parametric adaptation and parametric memory, enhancing applications from text classification to reinforcement learning through environment-conditioned behavior.

In-Context Environment Learning (ICEL) is a useful umbrella term—rather than a standardized name—for settings in which a model adapts to a task, domain, or interaction regime by conditioning on an in-context environment at inference time, rather than by updating its weights. Across the current literature, that environment may be a stream of unlabeled test examples, a prompt-local neighborhood of demonstrations, a trajectory history, a proof state with tool feedback, or a structured multimodal episode. “Context is Environment” makes the identification explicit through In-Context Risk Minimization, and “The Alchemy of Thought” supplies a closely related view in which the prompt plus demonstrations acts as a small, temporary training environment (Gupta et al., 2023, Narnoli et al., 3 Jan 2026).

1. Conceptual foundations

The most direct formalization of ICEL appears in domain generalization work that identifies context with environment. In that formulation, a training environment ee defines a joint distribution Pe(X,Y)P^e(X,Y), but the test-time environment is not represented by an abstract identifier alone. Instead, the observable signal is the context sequence cte=(x1e,,xt1e)c_t^e=(x_1^e,\ldots,x_{t-1}^e), and prediction takes the form

yieh(xie;x1e,,xi1e).y_i^e \approx h\big(x_i^e;\,x_1^e,\ldots,x_{i-1}^e\big).

The target is therefore P(YX,C)P(Y\mid X,C), used to “zoom-in” on the environment-specific conditional Pe(YX)P^{e'}(Y\mid X) without any test-time gradient updates. In this view, a model adapts because the context itself is a description of the current environment (Gupta et al., 2023).

This perspective broadens the usual interpretation of in-context learning. A prompt is no longer merely a sequence of examples; it is an environment-conditioned state from which the model must infer latent regularities. In text classification, the same idea appears in a more local form: for each test point, the top-kk semantically similar examples define a neighborhood that serves simultaneously as the prompt demonstrations for the LLM and as the training set for simple supervised classifiers. This suggests an ICEL interpretation in which the relevant environment is often local rather than global: a test-dependent micro-environment of nearby exemplars (Narnoli et al., 3 Jan 2026).

A further implication is that the environment need not be labeled in the ordinary sense. In ICRM, unlabeled inputs arriving from the current test environment are sufficient to improve prediction, because the model is trained to infer environment structure from context alone. This sharply distinguishes ICEL from conventional fine-tuning and from test-time adaptation methods that require explicit parameter updates (Gupta et al., 2023).

2. Pretraining, context, and the emergence of environment-conditioned behavior

Several recent analyses argue that ICEL-like behavior is a predictable consequence of next-token pretraining. One information-theoretic account models corpora as stochastic sources, including non-ergodic mixtures of environments. In that setting, minimizing autoregressive loss necessarily produces context-dependent loss reduction on correlated sources, and the model’s in-context performance on any task is mathematically coupled to the ensemble of tasks seen in pretraining. The latent environment is represented by the source component generating the sequence, and longer context reduces uncertainty by identifying that component more precisely (Riechers et al., 23 May 2025).

A complementary Bayesian framework separates the pre-training stage, with many tasks generated by latent concepts, from the in-context stage, where a target concept generates a demonstration set SnS_n and a test input XtestX_{\text{test}}. The central result states that, under suitable assumptions, the model’s argmax prediction conditioned on pretraining data plus context matches the Bayes-optimal predictor conditioned on the target concept. In a one-layer transformer example, a properly constructed context shifts the output distribution toward the query task distribution in a quantifiable manner, and the paper derives a precise relationship between ICL performance, context length, and the KL divergence between pre-train and query task distributions (Song et al., 26 Oct 2025).

The origin of ICEL can also be investigated at the level of individual pretraining instances. “Understanding In-Context Learning via Supportive Pretraining Data” identifies small subsets of pretraining data whose gradient directions align with improvements in ICL loss, and shows that continued pretraining on such subsets improves ICL ability by up to 18%. The supportive subsets are not more domain-relevant to downstream tasks, but they have a higher mass of rarely occurring, long-tail tokens and below-average information gain from long-range context, suggesting that difficult long-context prediction problems encourage later in-context adaptation (Han et al., 2023).

A training-time analogue appears in “On the Power of Context-Enhanced Learning in LLMs.” There, standard gradient-based learning is augmented with additional context on which no autoregressive gradients are computed. In a simplified multi-step reasoning task, this context-enhanced regime can be exponentially more sample-efficient than standard learning when the model is already capable of ICL, and the proposed explanation is that the added context yields a more accurate gradient learning signal (Zhu et al., 3 Mar 2025).

3. Behavioral and mechanistic accounts

A central behavioral account of ICEL comes from text classification. “The Alchemy of Thought” compares LLM predictions under ICL with k-nearest neighbors, weighted kNN, and logistic regression trained on the same demonstration set. Across six datasets and three LLMs, the models behave similarly when demonstration relevance is high, and on average ICL is closer to kNN than logistic regression. The paper reports, for GPT‑4o‑mini and kNN at k=20k=20, a correlation Pe(X,Y)P^e(X,Y)0 between human relevance and model agreement, with Pe(X,Y)P^e(X,Y)1. When relevance is low, LLMs outperform these classifiers and show high agreement with their own zero-shot behavior—for GPT‑4o‑mini, Kappa values of 0.86 on AG News, 0.98 on News Category, and 0.96 on AuTexTification—supporting the interpretation that the model backs off to parametric memory when the in-context environment is weak (Narnoli et al., 3 Jan 2026).

Architectural analyses refine this picture. “Context-Scaling versus Task-Scaling in In-Context Learning” distinguishes two phenomena: improvement with more context examples and improvement with more pretraining tasks. Transformers exhibit both; standard MLPs with vectorized input exhibit only task-scaling. The paper’s simplified transformer, with attention

Pe(X,Y)P^e(X,Y)2

shows that a single attention-like feature map can implement kernel-smoother behavior and thereby support context-scaling, while the MLP components support task-scaling. This yields an explicit decomposition of ICEL into a local, data-dependent adaptation mechanism and a global prior acquired across tasks (Abedsoltan et al., 2024).

A plausible synthesis is that ICEL often has two interacting modes. When the environment is relevant and coherent, the model behaves like a non-parametric learner over the context. When the environment is noisy, mismatched, or sparse, pretrained parametric knowledge dominates. The literature does not yet reduce this trade-off to a single settled mechanism, but it consistently treats the balance between contextual evidence and stored knowledge as central (Narnoli et al., 3 Jan 2026, Abedsoltan et al., 2024).

4. Representative instantiations across domains

ICEL is not confined to prompt-based classification. It appears in domain generalization, agentic tool use, reinforcement learning, test-time calibration, and structured reasoning.

Setting In-context environment Adaptation mechanism
ICRM Unlabeled context sequence from a test environment Learn Pe(X,Y)P^e(X,Y)3 and “zoom-in” on Pe(X,Y)P^e(X,Y)4
COPRA Proof state, search history, error messages, retrieved lemmas Stateful GPT-4-guided backtracking search
ICEE / SICQL / DICP Trajectory histories and return or prompt embeddings In-context exploration-exploitation, Q-learning, or planning
Self-Improving ICL Fixed prompt plus demonstration log-probabilities Zeroth-order optimization over prompt embeddings
SIE Structured triples and verifiable answers in prompt RL in structured in-context environments

In formal theorem proving, COPRA exemplifies environment-driven adaptation through iterative interaction with Lean and Coq. The prompt is built from the current proof state, prior tactics, error messages, retrieved lemmas, and search history; GPT-4 proposes one tactic at a time inside a backtracking search. On Lean miniF2F, few-shot GPT-4 solves 13.52% of the test set, whereas COPRA solves 26.63% without retrieval, 29.09% with retrieval, and 30.74% with retrieval plus informal proofs under a larger budget; it also exceeds ReProver’s 25.00% pass@1 while using far fewer queries per theorem (Thakur et al., 2023).

In reinforcement learning, the environment is often a trajectory history rather than a static prompt. ICEE uses multi-episode sequences and a two-part return-to-go to perform in-context exploration-exploitation, learning new RL tasks in only tens of episodes rather than the hundreds of episodes required by the previous in-context method. SICQL constructs a compact prompt Pe(X,Y)P^e(X,Y)5 from a generalized world model and trains a transformer with policy, value, and Q heads; it shows consistent gains, especially on suboptimal data, including a DarkRoom return of Pe(X,Y)P^e(X,Y)6. DICP adds an in-context world model and model-based planning, reaching 46.9% success on Meta-World ML10, compared with 35.8% for RLPe(X,Y)P^e(X,Y)7 under a much larger interaction budget (Dai et al., 2024, Liu et al., 2 Jun 2025, Son et al., 26 Feb 2025).

Other instantiations push ICEL toward explicit test-time adaptation. “Self-Improving In-Context Learning” optimizes continuous prompt embeddings at inference time by maximizing a bounded confidence proxy computed from log-probabilities on demonstration outputs, requiring no fine-tuning and no external data. On ICLEval, mean accuracy improves from 0.67 to 0.71 for Llama 3.1‑8B, from 0.65 to 0.72 for Qwen3‑4B, and from 0.45 to 0.48 for Gemma 2‑2B (Saglam et al., 22 May 2026). At the opposite end of the spectrum, SIE constructs RL environments directly from structured knowledge graphs; for Qwen2.5‑7B‑Instruct, WebQSP rises from 26.3 to 93.4 in SIE‑100%, and GSM8K rises from 29.2 to 87.4, indicating that structured in-context environments can drive both in-domain and out-of-domain reasoning gains (Yu et al., 27 Sep 2025).

5. Multimodal environments and capability stratification

In multimodal settings, the environment is not just a set of demonstrations but a mixed text–image field in which representational interference becomes a first-order problem. “Multimodal Contrastive In-Context Learning” interprets ICL as a contrastive process over key–value representations, with the distance between internal question and answer representations acting as a differentiator. The paper shows that semantically aligned examples can still help in unseen formats, especially on difficult tasks: for InternVL on GQA, ICL lowers performance on easy subsets from 59.7 to 52.5 for steps 1–5, but slightly improves performance on harder subsets from 83.5 to 84.6 for steps 6–9. On hateful memes, ordinary ICL degrades zero-shot performance from 61.4 to 58.5 F1, whereas Anchored-by-Text ICL improves it to 62.2, and a linear probe on distance features reaches AUC Pe(X,Y)P^e(X,Y)8 (Miyanishi et al., 2024).

UniICL systematizes this multimodal problem by proposing a six-level taxonomy—Perception, Imitation, Conception, Deduction, Analogy, and Discernment—together with UniICL-760K and UniICL-Bench. The training corpus contains 766,868 curated 8-shot episodes across 15 subtasks, and the benchmark contains 1,250 controlled episodes with evaluations at 0, 1, 2, 4, and 8 shots. The paper argues that the functional role of demonstrations differs by capability level: demonstrations can operate as perceptual anchors, instructors, concept definers, rule trajectories, analogical mappings, or value exemplars. This suggests that multimodal ICEL is best understood not as a single generic prompting phenomenon, but as a family of environment-conditioned adaptations with distinct cognitive demands (Xu et al., 25 Mar 2026).

The same paper proposes the Context-Adaptive Prototype Modulator as a lightweight architectural intervention to stabilize few-shot adaptation in unified models, and reports highly competitive unified results, outperforming larger-parameter multimodal LLM baselines on most understanding ICL tasks (Xu et al., 25 Mar 2026). In encyclopedic terms, this marks a shift from viewing the environment merely as prompt content to treating it as an object that can be architecturally mediated.

6. Limits, controversies, and open questions

ICEL remains a synthetic term across much of the literature. Several papers state explicitly that they do not use the term, even while providing its ingredients. This is not a merely terminological point: the field does not yet agree on whether in-context adaptation is best described as environment inference, kNN-like retrieval, implicit Bayesian updating, kernel smoothing, world-model conditioning, contrastive representational shift, or prompt-level optimization. A plausible interpretation is that these are complementary descriptions of different regimes rather than mutually exclusive theories (Narnoli et al., 3 Jan 2026, Gupta et al., 2023).

A recurring misconception is that “more context” is always better. The evidence is consistently more qualified. In text classification, relevance of demonstrations is decisive, and too many less relevant examples dilute the environment signal (Narnoli et al., 3 Jan 2026). In architectural studies, transformers context-scale, but standard MLPs can stagnate or degrade as context length grows (Abedsoltan et al., 2024). In multimodal ICL, cross-modal interference and formatting bias make shot-scaling non-monotonic and strongly task-dependent (Miyanishi et al., 2024). ICEL therefore depends not only on the amount of environmental information, but on its organization, relevance, and modality alignment.

Another unresolved issue is the boundary between environment-conditioned behavior and parametric recall. The kNN-versus-logistic-regression comparison was calibrated against a simple linear GD baseline, so the claim that ICL is “closer to kNN than GD” is specific to that comparison, not a universal theorem (Narnoli et al., 3 Jan 2026). More broadly, a plausible synthesis is that models interpolate between non-parametric environment use and parametric memory, but the weighting mechanism remains underdetermined and task-sensitive.

There are also substantive concerns about robustness and governance. ICRM notes that context can zoom in on spurious but highly predictive correlations just as easily as on useful environment structure, and its strongest out-of-distribution theorem depends on Gaussian latent assumptions and Voronoi-cell conditions (Gupta et al., 2023). Context-enhanced learning further suggests that materials supplied only in context during training may be hard to detect or recover afterward, with potential implications for data security and copyright (Zhu et al., 3 Mar 2025). These issues make ICEL not only a theory of adaptation, but also a theory of hidden influence.

Open problems follow directly from these tensions. The literature repeatedly calls for controlled causal manipulations of context quality, richer comparisons with nonlinear gradient-based learners, circuit-level analyses of environment-conditioned behavior, better handling of long and dynamic contexts, and clearer accounts of how environment-specific adaptation should be balanced against invariance and generalization. As the field expands from classification to multimodal reasoning, theorem proving, and RL, ICEL increasingly denotes not a single mechanism but a research program centered on one question: how much of a model’s effective learning can be relocated from parameter updates into the structured environments it encounters in context?

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to In-Context Environment Learning (ICEL).