In-context learning (ICL) is the emergent ability of a large language model to learn and perform a new task based solely on a few examples, or a demonstration, provided within its input prompt, without updating its internal parameters via gradient descent. This capability is a cornerstone of prompt engineering and is fundamentally constrained by the model's context window. The model infers the pattern, format, and objective from the provided few-shot examples and applies it to a new query.
Glossary
In-Context Learning (ICL)

What is In-Context Learning (ICL)?
In-context learning is a defining emergent ability of large language models that enables task adaptation without weight updates.
ICL operates via the transformer's attention mechanism, which allows it to identify and leverage patterns between the demonstration and the target input. Its effectiveness depends on the quality and relevance of the examples, their order, and the model's pre-trained knowledge. For agentic workflows, ICL is a primary method for on-the-fly task specification, reducing the need for extensive fine-tuning. Related techniques include zero-shot learning (no examples) and fine-tuning, which involves permanent weight updates.
Core Characteristics of In-Context Learning
In-context learning is the emergent ability of a large language model to learn a new task from a few examples provided within its prompt context, without updating its internal weights through gradient descent. The following cards detail its defining mechanisms and constraints.
Weightless Adaptation
The defining feature of in-context learning (ICL) is that the model's underlying parameters remain frozen. Learning occurs dynamically within the forward pass as the model processes the provided examples and infers the task pattern. This is distinct from fine-tuning, which permanently alters model weights via gradient descent.
- Mechanism: The model uses its pre-trained knowledge of language and world patterns to recognize the mapping between inputs and outputs in the examples.
- Implication: Enables rapid, on-the-fly task adaptation without costly retraining, but the "learning" is transient and confined to the current context window.
Demonstration via Few-Shot Examples
ICL is typically activated by providing few-shot examples—a small set of input-output pairs—within the prompt. These examples demonstrate the desired task format and logic.
- Standard Format:
Instruction+Example 1 (Input → Output)+Example 2 (Input → Output)+...+Actual Query Input. - Role: The examples act as a dynamic, temporary task specification, conditioning the model's probability distribution for the next token.
- Performance: Effectiveness scales with the number and quality of examples, but is bounded by the context window size. Too many examples can lead to context window saturation.
Dependence on Model Scale & Architecture
ICL is an emergent ability that becomes robust only in models of sufficient scale (typically tens of billions of parameters). It is intrinsically linked to the transformer architecture and its attention mechanism.
- Scale Law: Larger models demonstrate dramatically better ICL performance, accurately inferring complex patterns from fewer examples.
- Architectural Basis: The transformer's ability to attend to and draw relationships between any tokens in the context window is essential for linking query inputs to the relevant demonstration examples.
- Limitation: Small language models often fail at reliable ICL, performing only simple pattern matching.
Example Sensitivity & Ordering
ICL performance is highly sensitive to the selection, format, and order of the provided examples, a phenomenon known as example sensitivity.
- Recency Bias: Models often give more weight to the most recent examples in the prompt.
- Order Dependence: Changing the sequence of examples can lead to different outputs. Optimal ordering is often task-specific.
- Mitigation: Techniques like example calibration or searching over multiple permutations are used in production systems to stabilize outputs. This makes ICL less deterministic than weight-based learning.
Transient & Non-Persistent Learning
Knowledge acquired via ICL exists only for the duration of the specific inference call. Once the context window is cleared, the "learned" task mapping is forgotten.
- Contrast with Memory: Unlike agentic memory systems that persist information across sessions, ICL is a form of short-term working memory for the model.
- Engineering Implication: For recurring tasks, ICL examples must be re-injected into every relevant prompt, consuming valuable context window tokens. This drives the need for context management APIs and dynamic context strategies to optimize token usage.
Interface for Tool Use & Reasoning
ICL is the primary mechanism for teaching models to use external tools, follow complex reasoning formats, or adhere to strict output schemas within agentic workflows.
- Tool Calling: Examples can demonstrate the exact JSON structure for invoking an API via a tool-calling protocol.
- Chain-of-Thought (CoT): Providing examples of step-by-step reasoning (few-shot CoT) triggers the model to generate explicit reasoning traces for new problems.
- Output Control: ICL is used for deterministic output formatting, ensuring model responses can be parsed by downstream systems. This makes it a cornerstone of contextual prompt engineering.
How Does In-Context Learning Work?
In-context learning (ICL) is an emergent capability of large language models (LLMs) to perform a new task based on examples provided within the prompt, without updating their internal parameters.
In-context learning operates through the transformer's attention mechanism. When a prompt containing a few input-output examples (the few-shot context) is processed, the model attends to the patterns and relationships within this demonstration sequence. It then applies these inferred task-specific mappings to generate a response for a final, unseen query. This process is a form of meta-learning executed in a single forward pass, leveraging the model's pre-trained knowledge of language structures and reasoning.
The efficacy of ICL depends on demonstration selection and ordering. The provided examples act as a temporary, task-specific program that steers the model's activation pathways. Critical engineering factors include the relevance of examples, their format, and the model's inherent inductive bias from pre-training. For agentic workflows, ICL is a core technique for dynamic task adaptation, allowing an agent to follow new instructions or formats presented within its managed context window without requiring retraining.
Frequently Asked Questions
In-context learning is a core capability of modern language models that enables task adaptation without weight updates. This FAQ addresses its mechanisms, limitations, and role in agentic systems.
In-context learning (ICL) is the emergent ability of a large language model (LLM) to perform a new task by learning from a few examples provided within its prompt, without updating its internal parameters via gradient descent. It works by leveraging the model's pre-trained knowledge and attention mechanism to infer patterns from the few-shot examples presented in the context window. The model treats the concatenated sequence of examples and a new query as a single input, using its self-attention layers to identify relationships and apply the demonstrated pattern to generate the correct output. This is fundamentally a form of meta-learning acquired during pre-training on diverse, multi-task datasets.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
In-context learning (ICL) is a core capability that operates within the strict constraints of a model's context window. These related terms define the mechanisms and strategies for managing that limited working memory.
Context Window
The context window is the fixed-size, sequential block of tokens a transformer model can attend to in a single forward pass. It acts as the model's working memory, imposing a hard limit on the amount of information (prompts, examples, conversation history) that can be processed at once. For ICL, the context window must contain both the task instructions and the few-shot examples.
Few-Shot Prompting
Few-shot prompting is the practical application of ICL. It involves providing a model with a small number of task demonstrations (the 'shots') within its prompt, without weight updates. This technique relies entirely on the model's emergent in-context learning ability.
- Example: To teach translation, a prompt might include:
'Hello' -> 'Hola', 'Goodbye' -> 'Adiós', 'Thank you' -> ? - The model infers the pattern and outputs
'Gracias'.
Instruction Tuning
Instruction tuning is a supervised fine-tuning process where a model is trained on diverse (instruction, output) pairs. This is distinct from ICL, as it updates the model's internal weights. The goal is to improve the model's ability to follow unseen instructions, making it more amenable to few-shot prompting and zero-shot generalization. ICL operates on top of this instruction-following foundation.
Chain-of-Thought (CoT) Prompting
Chain-of-Thought prompting is an advanced ICL technique where few-shot examples include step-by-step reasoning. By demonstrating a logical progression, the model is coaxed into generating its own reasoning trace before delivering a final answer. This significantly improves performance on complex reasoning tasks like math or logic problems, leveraging the model's in-context learning for multi-step inference.
Retrieval-Augmented Generation (RAG)
Retrieval-Augmented Generation (RAG) is an architecture that augments ICL with external knowledge. Instead of relying solely on examples in the context window, a retrieval system fetches relevant documents from a knowledge base. These documents are then injected into the context, providing factual grounding. This combines the adaptability of ICL with the precision of verified data, reducing hallucinations.
Meta-Learning
Meta-learning, or 'learning to learn', is a broader machine learning paradigm where a model is explicitly trained to adapt quickly to new tasks with minimal data. ICL is considered an emergent, implicit form of meta-learning in large language models. While traditional meta-learning algorithms have an inner-loop optimization, ICL achieves rapid adaptation purely through the forward pass and attention mechanism over provided examples.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us