Hierarchy, Meta-Learning & Generalist Agents
Options, goals, and agents that learn to learn.
Every agent so far learned one task from scratch, one primitive action at a time. People do neither: they act in chunks ("walk to the door"), pursue goals they can swap ("now the window"), and learn each new task faster than the last. This lesson builds the three matching ideas, options, goal-conditioned policies with hindsight relabeling, and meta-RL, and then looks carefully at what agents trained on many tasks at once have and have not achieved as of the mid-2020s.
What you’ll learn
- Explain why long horizons with sparse rewards make undirected exploration exponentially slow, and how temporal abstraction, goals and meta-learning each attack the problem.
- Define an option and the semi-MDP it induces, compute an option's discounted model, and write the SMDP Q-learning update.
- Define goal-conditioned values, implement hindsight relabeling, and explain why it is valid for off-policy learners.
- State the meta-RL objective, contrast recurrent (RL²) and gradient-based (MAML) meta-learners, and relate both to Bayes-optimal adaptation.
- Describe generalist and open-ended agents (Gato, decision transformers, RT-2, POET, XLand, AdA), separating what is established from what is claimed.
Why long horizons are hard
Two quantities make an RL problem hard: how many decisions separate an action from its consequence, and how rarely the consequence is signaled. With a sparse reward the agent learns nothing until it reaches the reward once, and with undirected exploration the chance of reaching a reward that needs specific decisions in a row shrinks geometrically in . Once it is found, credit must still travel back through all decisions.
The chain below makes this concrete. Reaching its far end requires going right times in a row. An -greedy agent that has learned to prefer the small reward near the start goes right only on exploratory steps, half of which pick "right": with , a run of rights has probability about , roughly for .
Directed exploration is one cure (Posterior Sampling & Deep Exploration). This lesson develops three others, each attacking the horizon differently.
- Temporal abstraction. If the agent can choose "go right until the wall" as a single decision, the chain is one decision long. Options make such extended actions first-class.
- Goals. A sparse task is one goal among many. A policy that takes the goal as input learns from every state it reaches, because every state reached is some goal achieved.
- Meta-learning. An agent trained on many related tasks can learn an exploration strategy that is good for the whole family, and adapt to a new member in a few episodes.
Options: actions that last
Planning with options needs each option's model: its expected discounted reward and its discounted distribution of where it ends. For an option that terminates after steps,
An option walks right along a corridor to a door 5 cells away, each step costing 1, and stops at the door. It always takes steps, so with
The Bellman equation over options uses the model exactly as an ordinary backup uses and ; the discount is folded into , which therefore sums to less than 1:
In the corridor example (), the value of the state at the door is 10. What is the value of starting the option, ?
Show the answer
1.81
. Five primitive backups give the same number, , but the option's model does the work of five steps in one: values travel five cells per backup.
Sutton, Precup & Singh demonstrated this in a gridworld of four rooms, with options that lead from anywhere in a room to one of its doorways: planning over these options spreads values across the grid in far fewer iterations than planning over primitive moves. The options framework then raises four questions, each a Fixed Point topic of Options & Hierarchical RL. How to learn about many options at once from one stream of experience (intra-option learning); how to learn options end to end with policy gradients (the option-critic); how to let a manager set subgoals for a worker (feudal RL, FeUdal Networks, HIRO); and where good options come from (bottlenecks, eigenoptions, covering options).
A caveat runs through all of it: hierarchy does not help automatically. A careful study found that most of its benefit on standard continuous-control tasks came from better exploration, and that flat agents given similar temporally extended exploration did about as well (Nachum et al., 2019). Poor options can hurt, by removing the primitive actions an optimal policy needs or by committing to them for too long.
In SMDP Q-learning, why is the bootstrapped value multiplied by rather than ?
- To penalize long options so that the agent prefers primitive actions
- Because the next decision happens steps later, so its value is discounted by steps
- Because options are less reliable than primitive actions
- It is a heuristic with no derivation
Show the answer
B. Because the next decision happens steps later, so its value is discounted by steps
The discounted return splits at the option's end: . The first part is the reward collected while the option ran, and the second is the value of the state where it ended, steps away.
Goals as inputs, and hindsight
In goal-conditioned RL (Kaelbling, 1993) the task is a goal given as input: the reward is, say, when the next state achieves and 0 otherwise, and the agent learns and for all goals at once. A universal value function approximator (Schaul, Horgan, Gregor & Silver, 2015) is one network for all goals, so that what it learns about reaching one goal generalizes to others.
Sparse goal rewards are as hard as any sparse reward, until one notices that a failed attempt is a success for a different goal. An episode that aimed for and ended at is a perfect demonstration of how to reach . Hindsight experience replay (HER; Andrychowicz et al., 2017) stores every transition again, once for each of goals actually achieved later in the episode ( in the code below), and recomputes the reward. With the future strategy, which samples goals achieved after the transition, it worked best among the strategies the authors compared.
import random
def her_relabel(episode, compute_reward, k=4):
"""episode: list of (obs, action, next_obs, goal) with obs['achieved'] the goal it achieves.
Returns the original transitions plus k 'future' relabelings of each."""
out, T = [], len(episode)
for t, (obs, action, next_obs, goal) in enumerate(episode):
out.append((obs, action, next_obs, goal,
compute_reward(next_obs['achieved'], goal)))
for _ in range(k):
later = random.randint(t, T - 1) # a step at or after t
new_goal = episode[later][2]['achieved'] # a goal reached later on
out.append((obs, action, next_obs, new_goal,
compute_reward(next_obs['achieved'], new_goal)))
return outThe relabeled tuples go into the replay buffer of an off-policy learner such as DQN or DDPG, whose networks take the goal as an extra input. Relabeling needs a reward that can be recomputed for any goal; here it is a function of the achieved and desired goals.
Why is this legitimate? The transition was generated by the environment's dynamics, which do not depend on the goal, and the reward is recomputed for the new goal. An off-policy learner such as Q-learning needs only transitions drawn from and the correct reward; it does not care which policy, aiming at which goal, chose . An on-policy method could not reuse the data this way. In a bit-flipping puzzle with bits and a reward only for matching a target string, DQN alone could solve it only for , while DQN with HER solved it for up to 50.
One caveat is real. Relabeling with goals achieved after the transition makes the chosen goal depend on where the transition led. In a deterministic world that is harmless; in a stochastic one it makes lucky outcomes look reliable. Goal-Conditioned RL & Hindsight Relabeling computes this hindsight bias and its corrections.
Learning to learn
In meta-reinforcement learning the agent faces not one MDP but a distribution of related ones: mazes with different layouts, bandits with different arm means, robots with different masses. A trial draws one task and lets the agent interact with it for steps, often several episodes, and the agent is scored on its return over the whole trial. Doing well means exploring the new task efficiently and then exploiting what it found: the agent must learn within the trial, and meta-training optimizes how it does so.
Two families of meta-learners dominate.
- Recurrent (RL²). Duan et al. (2016) and Wang et al. (2016) gave a recurrent policy its previous action and reward as inputs (RL² also a flag marking the end of each episode) and kept its hidden state for as long as the task stayed the same, resetting it only when a new task was drawn. An ordinary RL algorithm trains the weights; the network's dynamics then are a learning algorithm. On random bandits and small MDPs, RL² performed close to algorithms designed with optimality guarantees.
- Gradient-based (MAML). Finn, Abbeel & Levine (2017) learn an initialization such that one or a few policy-gradient steps on a new task's data, , give a good policy, and meta-train by maximizing . Adaptation is a gradient step, which keeps improving with more data even on unfamiliar tasks, but a few gradient steps from a few episodes explore far less cleverly than a learned recurrent strategy.
In RL², the recurrent state persists across the episodes of a trial and is reset only when a new trial begins. Why?
- To save memory during training
- The outer-loop algorithm cannot compute gradients otherwise
- So that the agent remembers every task it has ever seen
- What the agent learned about the current task in earlier episodes must carry over to later ones, while a new trial is a new task
Show the answer
D. What the agent learned about the current task in earlier episodes must carry over to later ones, while a new trial is a new task
The hidden state is the inner loop's memory, its estimate of which task it is in and what works there. Carrying it across episodes lets later episodes exploit what earlier ones explored; resetting at a trial boundary matches the fact that the task has been redrawn.
Generalist agents and open-ended learning
Large sequence models trained on broad data, foundation models, have entered decision making in several forms.
- One network for many tasks. Gato (Reed et al., 2022) is a single 1.2-billion-parameter transformer trained on 604 tasks, from Atari games and image captioning to dialogue and stacking blocks with a real robot arm, all serialized as token sequences, with the same weights for every task. It was trained by supervised learning on expert data, not by RL, and its performance relative to the experts that produced the data varied widely across tasks.
- Return-conditioned sequence models. The decision transformer (Chen et al., 2021) predicts actions from past states, actions and the desired return-to-go, turning offline RL into supervised learning (RL as Sequence Modeling).
- Vision–language–action models. RT-2 (Brohan et al., 2023) fine-tunes a pretrained vision–language model to output robot actions as text tokens, each of 7 action dimensions discretized into 256 bins, while continuing to train on web vision–language data. The authors reported better generalization to new objects and instructions than earlier robot policies, drawing on knowledge from web data. Such a vision–language–action model is mostly a product of imitation; as of the mid-2020s, RL fine-tuning on top of it is an active area.
- In-context RL. Transformers trained on the learning histories of RL algorithms can improve on new tasks within their context window, without weight updates (Meta-RL & In-Context Reinforcement Learning).
Open-ended training asks where the tasks come from. POET (Wang, Lehman, Clune & Stanley, 2019) co-evolves obstacle courses for a two-legged walker with the agents that solve them, admits new courses only if they are neither trivial nor impossible and are novel, and transfers agents between courses; it produced walkers for courses that direct optimization on those courses failed to solve. XLand (Open Ended Learning Team, 2021) procedurally generates 3D worlds and multiplayer games, adapts the task distribution to the agent, and trains generations of agents; the final agents were broadly capable across a held-out task space. The Adaptive Agent (AdA; Adaptive Agent Team, 2023) combined meta-RL over XLand 2.0's space of more than tasks with a transformer memory and an automated curriculum, and reported adaptation to held-out tasks within minutes, on a timescale comparable to human players.
Key takeaways
- Long horizons with sparse rewards defeat undirected exploration exponentially, about for the chain; options shorten the horizon, goals turn one sparse task into many, and meta-learning amortizes exploration across tasks.
- An option is an action that lasts; options turn an MDP into a semi-MDP whose Bellman equation uses discounted option models, and SMDP Q-learning discounts by . Hierarchy helps mostly through exploration, and only with good options.
- Goal-conditioned values learn many tasks at once; hindsight relabeling turns failures into successes for achieved goals and is valid for off-policy learners, but biased in stochastic environments.
- Meta-RL maximizes return over trials drawn from a task distribution: RL² adapts in a recurrent state, MAML in a gradient step; the ideal is the Bayes-optimal policy of the Bayes-adaptive MDP.
- Generalist agents such as Gato (2022), decision transformers (2021) and RT-2 (2023) are trained mostly by imitation; open-ended training (POET, XLand, AdA) generates its own tasks; "general" means general within a designed distribution.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
An -greedy agent (, two actions) prefers "left" and must choose "right" 10 times in a row to reach a reward. Roughly how likely is that within one attempt?
- About
- About
- About
- About
Show the answer
D. About
Each step goes right only on an exploratory move that picks "right", probability , so ten in a row has probability . Undirected exploration fails exponentially in the number of required decisions, which is why the chain defeats -greedy.
An option's discounted transition model is . What does equal?
- Exactly 1, as for any transition probability
- , which is less than 1
- The expected duration
Show the answer
B. , which is less than 1
Summing over end states leaves . The discount is folded into the model, so the Bellman equation over options needs no separate ; in the corridor example it is .
Why can hindsight experience replay give a transition a goal that the behavior policy was not pursuing?
- Because the reward does not depend on the goal
- Because the policy is goal-independent
- Because the transition was produced by goal-independent dynamics, the reward is recomputed for the new goal, and an off-policy learner does not need the data to come from the policy it evaluates
- Because HER uses on-policy updates
Show the answer
C. Because the transition was produced by goal-independent dynamics, the reward is recomputed for the new goal, and an off-policy learner does not need the data to come from the policy it evaluates
regardless of the goal, and Q-learning's target needs only such samples and the right reward. Which goal the behavior policy was chasing affects which actions were taken, not the validity of the transition. The subtlety comes when the new goal is chosen because of where the transition led, which biases things in stochastic environments.
Where does adaptation to a new task happen in RL² and in MAML?
- RL²: in the recurrent hidden state, with the weights fixed; MAML: in one or a few gradient steps from a learned initialization
- In both, in gradient steps on the new task
- RL²: in gradient steps; MAML: in a hidden state
- In neither: both simply memorize the training tasks
Show the answer
A. RL²: in the recurrent hidden state, with the weights fixed; MAML: in one or a few gradient steps from a learned initialization
RL²'s weights encode a learning algorithm that runs in its activations; nothing is updated at test time. MAML runs an ordinary policy-gradient update at test time, from an initialization chosen so that the update works well.
How was Gato, the single network trained on 604 tasks, trained?
- By RL from scratch on every task
- By supervised learning on data from expert agents and other sources, with the same weights for all tasks
- By evolution strategies
- By separate networks per task, merged afterward
Show the answer
B. By supervised learning on data from expert agents and other sources, with the same weights for all tasks
Gato serialized observations and actions of all tasks into token sequences and trained one transformer to predict them, a form of behavior cloning at scale. Many generalist agents of the mid-2020s share this recipe, with RL, if any, used afterward.
Go deeper
- Options & Hierarchical RL · Semi-MDPs, the option-critic and feudal agents.
- Goal-Conditioned RL & Hindsight Relabeling · Universal value functions, HER, and learning many tasks at once.
- Meta-RL & In-Context Reinforcement Learning · RL², Bayes-adaptive agents, and transformers that learn to reinforcement-learn in context.
Further reading
- R. S. Sutton, D. Precup & S. Singh, "Between MDPs and semi-MDPs: A framework for temporal abstraction in reinforcement learning," Artificial Intelligence 112, 181–211 (1999).
- M. Andrychowicz, F. Wolski, A. Ray, J. Schneider, R. Fong, P. Welinder, B. McGrew, J. Tobin, P. Abbeel & W. Zaremba, "Hindsight experience replay," NeurIPS (2017).
- Y. Duan, J. Schulman, X. Chen, P. L. Bartlett, I. Sutskever & P. Abbeel, "RL²: Fast reinforcement learning via slow reinforcement learning," arXiv:1611.02779 (2016).
- S. Reed et al., "A generalist agent," Transactions on Machine Learning Research (2022).