Lecture 13

Meta-Reinforcement Learning

Learning to learn: meta-RL algorithms that adapt quickly to new tasks from limited experience.

Meta-Learning MAML Task Distribution Fast Adaptation
Original PDF slides

From Multi-Task Learning to Meta-Learning

In the previous lecture, we trained a single policy to handle a distribution of tasks by conditioning on a task identifier $z_i$. This works well when the task identifier is available at test time—for instance, when a human provides a language instruction. But what happens when the agent encounters a new task for which no explicit identifier is given? The agent must figure out what the task is from interaction alone, and it must do so quickly.

This is the domain of meta-reinforcement learning (meta-RL): training agents that can learn to learn, adapting to new tasks from a small amount of experience. Where multi-task RL asks "can we train one policy for many tasks?", meta-RL asks the deeper question: "can we train an agent that rapidly adapts to any task drawn from a distribution, using only a handful of episodes?"

Key Insight
The key shift from multi-task RL to meta-RL is about what is learned. In multi-task RL, the agent learns a single policy that covers all training tasks. In meta-RL, the agent learns a learning algorithm—an adaptation procedure that can be applied to produce task-specific behavior from limited data. The output of meta-training is not a fixed policy, but a mechanism for quickly generating good policies.

The Transfer Learning Spectrum

Meta-RL sits on a spectrum of approaches that leverage shared structure across tasks:

Meta-learning is the most ambitious of these: it asks the training process to discover not just good features or policies, but a good learning procedure.

The Meta-Learning Problem Setup

Meta-learning has been widely studied in supervised learning under the umbrella of few-shot learning. The setup there provides useful intuition for the RL case.

Few-Shot Learning in Supervised Settings

In few-shot image classification, the agent must classify images of new categories after seeing only a handful of labeled examples per category. The standard protocol involves:

  1. Meta-training: Present the learner with many "episodes," each consisting of a small support set (a few labeled examples of novel classes) and a query set (test images to classify).
  2. Meta-testing: Evaluate on entirely new classes not seen during meta-training, again with only a few examples per class.

The meta-learner is trained end-to-end across episodes so that its adaptation mechanism (whether gradient-based, metric-based, or memory-based) becomes effective at few-shot classification.

Meta-RL Problem Formulation

We now translate this to reinforcement learning. We have a distribution over tasks $p(\mathcal{M})$, where each task $\mathcal{M}_i$ is an MDP. The meta-RL protocol mirrors the few-shot setup:

Definition
Episodic Meta-RL. Given a task distribution $p(\mathcal{M})$, the episodic meta-RL setting proceeds as follows:
  • Meta-training: For each training iteration, sample a task $\mathcal{M}_i \sim p(\mathcal{M})$. Allow the agent $K$ exploration episodes in $\mathcal{M}_i$ to gather information. Then evaluate the agent's performance on an execution episode in the same task. The meta-objective is to maximize expected return on the execution episode, averaged over the task distribution.
  • Meta-testing: Sample a new task $\mathcal{M}_j \sim p(\mathcal{M})$ not seen during meta-training. The agent again gets $K$ exploration episodes, and is evaluated on execution.

The critical distinction from multi-task RL is that the agent receives no explicit task identifier $z_i$. Instead, it must infer the task identity from its exploration experience. The exploration episodes serve as the "support set," and the execution episode as the "query set," drawing a direct parallel to few-shot supervised learning.

Example
Maze Navigation. Consider a distribution of maze environments. Each maze has a different layout and a hidden goal location. During exploration episodes, the agent can navigate the maze, discovering the layout and searching for the goal. During the execution episode, it must reach the goal efficiently using the information gathered during exploration. A meta-RL agent learns a strategy for systematic exploration (e.g., searching unexplored corridors) that transfers across maze layouts.

Examples of Task Distributions

Task distributions arise naturally in many settings:

Black-Box Meta-RL

The most conceptually simple approach to meta-RL is the black-box (or context-based) method: train a neural network with memory that takes in the entire history of interactions and outputs actions. The adaptation to a new task happens implicitly within the network's forward pass—the memory accumulates information about the task, and the policy conditions on this accumulated context.

Definition
Black-Box Meta-RL. A black-box meta-RL agent uses a neural network $f_\theta$ with memory (e.g., an RNN, transformer, or external memory module) that maps the history of past observations, actions, and rewards to the next action: $$a_t = f_\theta(s_1, a_1, r_1, s_2, a_2, r_2, \ldots, s_t)$$ The parameters $\theta$ are trained via standard RL across many tasks during meta-training. At meta-test time, $\theta$ is frozen, and the network adapts to a new task purely through its internal memory dynamics.

Training Black-Box Meta-RL

The training procedure for black-box meta-RL is straightforward:

Black-Box Meta-RL Training
  1. Sample a batch of tasks $\{\mathcal{M}_i\}$ from $p(\mathcal{M})$.
  2. For each task $\mathcal{M}_i$:
    • Reset the agent's memory (hidden state).
    • Collect $K$ exploration episodes in $\mathcal{M}_i$, updating the hidden state but not the parameters.
    • Collect an execution episode and compute its return $R_i$.
  3. Update $\theta$ to maximize $\E_i[R_i]$ using any policy gradient or actor-critic algorithm.
  4. Repeat until convergence.

The key property: the memory is reset between tasks (to prevent information leaking across tasks) but persists across episodes within the same task (to allow information accumulation).

At test time, the procedure is identical except that we freeze $\theta$. The agent encounters a new task, and its internal memory state evolves as it interacts, effectively performing task inference and policy adaptation through the learned dynamics of the recurrent network.

Architectures for Black-Box Meta-RL

Several neural network architectures have been proposed for black-box meta-RL, each offering different tradeoffs in terms of memory capacity, computational efficiency, and the types of adaptation they can express:

Key Insight
All three architectures implement the same conceptual idea—accumulate information from past experience and condition the policy on this accumulated context—but they differ in how information is aggregated. RNNs aggregate sequentially and can learn order-dependent strategies. Attention mechanisms aggregate selectively. PEARL's averaging aggregates symmetrically. The best choice depends on whether task identification requires remembering specific sequences of events or merely collecting sufficient statistics.

Examples and Capabilities

Black-box meta-RL agents can exhibit remarkably sophisticated behavior. In maze navigation tasks, an RL$^2$ agent learns to systematically explore corridors it has not visited, building an internal map of the maze layout. When placed in a new maze, it navigates to the goal far more efficiently than an agent trained from scratch. In continuous control tasks, PEARL adapts its locomotion strategy within a few episodes when the dynamics change—for instance, when a leg becomes injured or the terrain properties shift.

Perhaps most strikingly, black-box meta-RL has connections to the way modern large language models reason. Systems like DeepSeek R1 use chain-of-thought reasoning that can be viewed as a form of in-context adaptation: the model processes the problem description (analogous to exploration episodes) and then generates a solution (the execution episode), with the "adaptation" happening entirely within the forward pass of the transformer. Both are instances of using the meta-learned network dynamics to implement a learned algorithm in the activations.

Connection to Multi-Task Policies

There is a deep connection between black-box meta-RL and the multi-task policies from Lecture 12. Recall that a multi-task policy conditions on a task identifier: $\pi(a \mid s, z_i)$. In black-box meta-RL, the accumulated experience $\mathcal{D}_{\text{tr}} = \{(s_t, a_t, r_t, s_{t+1})\}$ from exploration episodes serves as an implicit task identifier.

Consider the PEARL architecture specifically. It computes a context vector $z = \frac{1}{|\mathcal{D}_{\text{tr}}|} \sum_{(s, a, r, s') \in \mathcal{D}_{\text{tr}}} q_\phi(s, a, r, s')$, where $q_\phi$ is a learned encoder. The policy then acts as $\pi(a \mid s, z)$—which is exactly a multi-task policy conditioned on a learned task embedding. The difference from Lecture 12 is that $z$ is inferred from experience rather than given as input.

Definition
Task Inference. In the meta-RL setting, task inference is the process of identifying which task the agent is in based on interaction data. Formally, it corresponds to computing a posterior distribution over tasks (or a point estimate) given the exploration data: $p(\mathcal{M}_i \mid \mathcal{D}_{\text{tr}})$. The quality of this inference directly determines the quality of the execution policy.

Meta-RL as a POMDP

A powerful theoretical perspective views meta-RL through the lens of partially observable Markov decision processes (POMDPs). The task identity $\mathcal{M}_i$ is a hidden variable that the agent cannot directly observe. Instead, the agent receives observations, rewards, and transitions that are generated by the unknown task. The agent must maintain a belief over which task it is in and act optimally given this uncertainty.

Formally, we can construct a POMDP where:

Under this POMDP view, the optimal meta-RL policy is the Bayes-optimal policy for this POMDP. It maintains a belief over tasks and takes actions that are optimal given the current belief—including actions that are informative (exploration) rather than immediately rewarding (exploitation).

Theorem
Bayes-Optimal Meta-RL (Informal). The optimal policy for the meta-RL POMDP balances two objectives: (1) taking actions that yield high immediate reward given the current task belief, and (2) taking actions that reduce uncertainty about the task identity, enabling higher reward in the future. A policy that only exploits (ignoring exploration value) or only explores (ignoring exploitation) is generally suboptimal.

This Bayes-optimal perspective clarifies why exploration and exploitation must be interleaved: each exploration action has both an immediate cost (potentially suboptimal reward) and an information-gathering benefit (reducing task uncertainty for future decisions).

The Exploration Challenge in Meta-RL

Exploration is the central challenge that distinguishes meta-RL from multi-task RL. In multi-task RL, the task identifier is given explicitly. In meta-RL, the agent must discover the task through exploration, and the quality of exploration directly determines the quality of execution. This creates a difficult optimization landscape.

The Chicken-and-Egg Problem

End-to-end meta-RL training faces a fundamental coupling problem between exploration and execution:

This chicken-and-egg problem can trap the meta-learner in poor local optima. Consider a cooking robot that must first find ingredients (exploration) and then cook a dish (execution). If the robot never learns to find the right ingredients, it cannot learn to cook, and if it cannot cook, it has no incentive to search for ingredients more carefully. End-to-end training must simultaneously improve both, which is challenging when the reward signal is sparse.

Key Insight
The coupling between exploration and execution is the primary reason why end-to-end meta-RL methods (like RL$^2$) struggle in environments that require complex exploration. The gradient from the execution reward must propagate back through the exploration episodes to improve the exploration strategy—a long credit assignment chain that becomes increasingly difficult as the exploration horizon grows.

Alternative Exploration Strategies

Several approaches have been proposed to sidestep the chicken-and-egg problem by decoupling exploration from end-to-end training:

Summary of Meta-RL Approaches

The meta-RL landscape offers several design choices, each with characteristic strengths and weaknesses:

Definition
Three Paradigms for Meta-RL.
  • End-to-end (e.g., RL$^2$, VariBAD): Optimize exploration and execution jointly. Leads to the optimal strategy in principle, but challenging optimization when exploration is hard due to the coupling problem.
  • Alternative exploration strategies (e.g., PEARL, MAME, MetaCURE): Replace learned exploration with a hand-designed strategy. Easy to optimize and based on principled strategies, but can be suboptimal by an arbitrarily large amount in some environments.
  • Decoupled exploration and execution (e.g., DREAM): Separate the exploration and execution learning problems. Leads to the optimal strategy in principle and is easier to optimize in practice, but requires additional structure such as a task identifier during meta-training.

The choice between these paradigms depends on the specific problem characteristics. End-to-end methods are most appropriate when the exploration horizon is short and the reward signal is dense. Alternative strategies work well when standard exploration methods (like Thompson sampling) happen to align with the task structure. Decoupled methods shine when the exploration problem is complex but the task-relevant information is low-dimensional.

Looking Ahead

This lecture introduced meta-RL as an extension of multi-task RL where the agent must infer the task identity from interaction rather than receiving it as input. The black-box approach uses neural networks with memory to implement learned adaptation algorithms. The POMDP perspective reveals meta-RL as optimal decision-making under task uncertainty, inherently requiring a balance between exploration and exploitation.

Key takeaways:

In the next lecture, we examine the exploration problem in greater depth. We will study principled exploration strategies for bandits and MDPs—from upper confidence bounds to posterior sampling—and then return to the meta-learning setting to see how the DREAM algorithm elegantly decouples exploration from execution.