---
title: Dynamic In-Context Learning (DynaICL)
url: https://www.emergentmind.com/topics/dynamic-in-context-learning-dynaicl
type: topic
---

# Dynamic In-Context Learning (DynaICL)

Dynamic In-Context Learning (DynaICL) refers to a set of mechanisms, architectures, and algorithms enabling models—particularly large language models (LLMs) and multimodal systems—to adapt their predictions, plans, or behaviors at inference time by building, updating, and exploiting context or demonstration sets in a dynamic, input- and state-dependent fashion. Unlike static in-context learning, where context is fixed and predefined before inference, DynaICL emphasizes ongoing, context-sensitive modification of the model input—incorporating new evidence, perceptual data, or demonstration subsets as the computation proceeds. This approach has proven central to modern LLM-augmented agentic systems, embodied robotics, retrieval-augmented generation, and adaptive decision-making agents.

## 1. Formalism and Mechanisms

At its core, Dynamic In-Context Learning maintains a context buffer or memory $C_t$ at time or step $t$, which encodes the history of perceptual inputs, symbolic trajectories, natural language instructions, and other task-relevant state. This context is updated as new perceptual or interaction events occur, with the principal update rule (as in DynaMIC) given by
\[
C_t = C_{t-1} \cup \{ z_t \},
\]
where $z_t$ is a structured natural language (NL) transcription of a new sensor observation, perception, or action at step $t$ [2509.24413]. The context may include:

- $q \in \mathcal Q$: Current human instruction.
- $K_u$: Human prior knowledge of the scene.
- $K_m$: Robot's base affordances, sensors, and actions.
- $K_p^t = \bigcup_{i=1}^{t} P_i$: All multimodal perceptual data up to $t$.
- $J^t = \langle j^0, \ldots, j^t \rangle$: Executed semantic actions/perceptions.

Dynamic context is central to agentic decision-making and error detection, particularly for handling cases such as Directive Counterfactuals (DCFs) in robotics—where the "in-context" memory enables robots to compare perceived knowledge with prior assumptions and halt execution upon epistemic disagreement.

In general, DynaICL updates are governed by workflow- or observation-triggered expansions of $C_t$, with optional pruning or prioritization:
\[
C_t \leftarrow \mathrm{top\text{-}K}_{\mathrm{Score}}(C_t),
\]
where
\[
\mathrm{Score}(z_i; q, K_u) = \alpha \cdot \mathrm{sim_{text}}(q, z_i) + (1-\alpha) \cdot \mathrm{sim_{vis}}(K_v, z_i)
\]
governs relevance-based retention if context window size is a constraint.

## 2. Architectural Realizations

Dynamic In-Context Learning is instantiated in various LLM-centric and multimodal architectures designed for sequential, embodied, or agentic reasoning. The DynaMIC framework exemplifies a leading multimodal design [2509.24413]:

- *Visual Encoder*: A large-scale Transformer-based model (CogVLM) processes high-dimensional inputs (e.g., RGB images), producing prompt-conditioned, natural-language attribute summaries via independent, relative, and interactivity heads ($p_{v_i}$, $p_{v_r}$, $p_{v_c}$), which are concatenated into $K_v$.
- *Textual Planner*: A language model (e.g., GPT-4 Turbo) is prompted with ($q$, $K_v$, $K_b$, optional $C_{t-1}$), performing a two-pass process: (1) intention alignment with knowledge grounding and DCF detection, and (2) trajectory generation and refinement. The separation of modal encodings is preserved up to the point of prompt concatenation, leveraging pretrained alignments without additional cross-modal attention.
- *Dynamic Loop*: The forward pass at each step potentially yields new perception transcriptions, dynamically grown context, and replanning, all mediated by explicit high-level symbolic updates and NL feedback.

This pattern recurs throughout state-of-the-art DynaICL frameworks: dynamic construction of the in-context input to the LLM or agent, recalibration of demonstrations, and closed-loop interaction across modalities and time.

## 3. Algorithmic Procedures and Updating Strategies

Central to DynaICL are explicit, stage-wise procedures for expanding, pruning, and utilizing in-context knowledge. For instance, in DynaMIC [2509.24413]:

**Algorithm A (DCF-aware Trajectory Pre-generation):**
1. Loop:
   - Generate intention $\xi$ from $q$ and try to align with $K_v$ via generation $G$; if misaligned, halt and request revision.
2. Given intention $\xi$, generate initial plan $J_0$.
3. Insert perception steps after actions in $J_0$ as needed to increase DCF observability.
4. Return refined plan $J^*$.

**Algorithm B (Execution, In-Context Update, Replanning):**
1. For each step $j \in J^*$:
   - If movement: execute.
   - If perception: obtain raw sensor data, transcribe to $z$, update $K_p$, expand $C_t$.
2. Re-prompt the LLM for DCF detection; on positive, replan or fail out.

Other notable DynaICL algorithms include:
- Dynamic Demonstrations Controller: Performs offline pilot runs to estimate the optimal number of in-context demonstrations $k^*$ per dataset/model, avoiding the assumption that "more is always better," and using KL-based intra/inter-class scoring for demonstration selection [2310.00385].
- Dynamic retrieval and self-learning: RAG systems maintain large pools of prior queries/templates, leveraging contextual embedding-based retrieval, robust clustering, and on-the-fly labeling/self-learning to assemble and update few-shot prompts for each query [2601.08105].

## 4. Applications and Case Studies

Dynamic In-Context Learning mechanisms are deployed in a broad range of practical domains:

- **Embodied Robotics**: DynaMIC enables robots to avoid failure modes induced by misleading or erroneous human instructions, employing dynamic context memory, counterfactual detection, and iterated feedback/plan refinement. Success rates for DCF detection and safe plan execution reach $88\%$ in tested tabletop scenarios [2509.24413].
- **Retrieval-Augmented Generation (RAG)**: DynaICL underpins robust query suggestion by dynamically retrieving workflow-similar positive/negative exemplars, substantially increasing answerable suggestion rates in multi-agent RAG pipelines [2601.08105].
- **Agentic Sequential Decision-Making**: DynaICL with dynamic demonstration set selection and real-time snippet retrieval elevates the performance and reliability of LLM agents for compositional, multi-step environments [2506.13109].
- **Dynamic Data Extraction**: Scientific information extraction pipelines update the prompt's in-context examples with newly verified extractions, substantially increasing precision/recall as well as data trust [2405.10448].

## 5. Comparative Results and Empirical Impact

Empirical studies confirm that dynamic context strategies outperform static few-shot selection in both accuracy and auxiliary criteria (e.g., safety, fairness, efficiency):

| Method                                      | Task                  | Primary Eval Metric       | DynaICL Gain                | Reference      |
|----------------------------------------------|-----------------------|--------------------------|-----------------------------|---------------|
| DynaMIC (dynamic multimodal context)         | Robot DCF detection   | Success rate (safe)      | 88% (vs lower for ablated)  | [2509.24413]  |
| D²Controller (dynamic $k$ pilot)             | LLM text classification | Avg accuracy            | +5.4% rel. improvement      | [2310.00385]  |
| Robust dynamic retrieval (dynamic pool)      | RAG query suggestion  | Answerability rate       | +5–28% over static          | [2601.08105]  |
| Dynamic demonstration/snippet selection      | Agentic LLMs          | Task Goal Completion     | Up to +14 pts (mini model)  | [2506.13109]  |

Further, ablation experiments validate that dynamic context expansion (vs. static or naively pruned context) is critical for robust in-context adaptation, especially under context window constraints or in environments where heterogeneity in task difficulty or environmental configuration is significant.

## 6. Limitations, Open Challenges, and Theoretical Insights

Key limitations and open questions for DynaICL include:

- **Context-Length Constraints**: While most applications encounter few context window overflows, anticipatory pruning (by relevance or recency) can be needed, but introduces nontrivial strategy design and trade-offs.
- **Choice of Demonstrations**: Dynamic expansion/picking is shown to outperform static blocks, but optimal retrieval, ranking, and clustering strategies remain an open, context- and task-dependent research frontier.
- **Implicit Dynamics**: Theoretical work indicates that transformers may realize DynaICL via implicit low-rank weight updates, suggesting that dynamic adaptation is a first-class phenomenon even in the forward pass [2507.16003].
- **Modality and Architecture Generalization**: Most results are in textual or relatively low-dimensional multimodal spaces; scaling DynaICL practices to high-dimensional continuous or richly structured domains is an active area.
- **Robustness to Adversarial Contexts**: Dynamic in-context mechanisms can in principle detect or recover from misalignment or partial knowledge, but their performance in highly adversarial or distribution-shifting scenarios requires further study.

## 7. Synthesis and Theoretical Foundation

Dynamic In-Context Learning establishes a paradigm where task-relevant context is adaptively constructed, revised, and exploited on the fly, enabling large models and embodied agents to achieve gradient-free, data-efficient, and robust adaptation across a wide spectrum of tasks. The architecture-agnostic principle—updating the in-context buffer and consequently the "input program" for a model at each interaction—unifies disparate approaches in robotics, retrieval-augmented NLP, vision, and agentic planning, and is firmly grounded in both algorithmic innovation (such as dynamic $k$-shot estimation, pilot-based selection, robust retrieval) and theoretical insight (low-rank weight adaptation, context-dependent error minimization).

By separating the context memory from static, frozen inputs, DynaICL positions in-context learning as a model- and domain-agnostic substrate for closed-loop intelligent systems, capable of self-improving performance, error detection, and human-in-the-loop feedback realization [2509.24413][2310.00385][2601.08105][2507.16003].

Source: https://www.emergentmind.com/topics/dynamic-in-context-learning-dynaicl