A flat policy that slips once in 20 steps finishes a 100-step task 0.6% of the time. Cut the task into 10 rooms, check each doorway, retry a failed room, and about half the runs finish.
Learn how a high-level policy picks subgoals and a low-level policy carries them out, with every equation read aloud.
Press Run one episode and watch both agents walk the corridor. Then press Run 500 and drag Rooms. Then we build it piece by piece: the two policies, their two clocks, the doorway check, goal types, training, switching and hierarchical RL.
You need a little Python and what a probability is. Imitation learning helps in Chapter 5. We build the rest from zero.
Re-taught from the lecture Hierarchy in Imitation and Reinforcement Learning of Stanford CS 224R: Deep Reinforcement Learning. The explanations, toys and numbers here are our own; every toy number is illustrative.
Illustrative toy. Each room is 10 steps. At every step each agent slips with the chance you set. The flat policy cannot tell it is off course, so one slip ends its run. The two-level policy checks each doorway and retries a room up to 3 times. Ticks on the bars mark the formula of Chapter 3.
Chapter 0
Multiply a small chance of error over many steps and watch the finish rate collapse
A robot must make a sandwich. That takes about 100 small motions: reach, grip, lift, carry, spread, place. A flat policy is one network that maps what the robot sees, plus the task, to the next motor command. It does this at every step, from the first reach to the last.
Each motion is easy. The whole task is hard, for three reasons.
| Trouble | What happens | Size |
|---|---|---|
| Many paths | The number of action sequences grows with every step | 4 actions over 50 steps: 450, about 1.3 × 1030 |
| Compounding error | Every step is one more chance to go wrong | The equation below |
| Getting stuck | Some mistakes have no way back | A dropped slice of bread ends the run |
How likely is a long run with no mistake? Call the chance of a slip at one step ε (epsilon). Call the number of steps T. Call the chance that every step goes right P-finish.
P-finish equals one minus epsilon, to the power T.
One step goes right with chance one minus epsilon. The steps do not depend on each other, so multiply that chance once per step, T times. The product is P-finish.
With made-up numbers: epsilon 0.05 and T 100. P-finish = 0.95100 = 0.0059. A policy that is right 95% of the time at each step finishes 0.6% of its runs.
The orange curve is the flat policy's finish chance against task length. Drag the slip chance, then the length.
The formula above, drawn for every length from 0 to 200 steps. The slips are independent in this toy.
The failure. A flat policy scores well on each piece of the task in testing and near zero on the whole task. To measure it, log the step where each failed run went wrong. If the failures spread over the whole run, compounding is the cause. The fix is to shorten the stretch that any one policy must get right. That is what a hierarchy does.
Chapter 1
Split the policy into a slow planner that names the next subgoal and a fast controller that reaches it
"Bake a cheesecake" is hard as one task. "Buy the cream cheese" is easier. "Walk to the door" is easier still. People break long tasks into a ladder of shorter ones. A hierarchical policy does the same with two networks.
The high-level policy reads the observation and the task and picks a subgoal: a short target such as "pick up the bread". The low-level policy reads the observation and the subgoal and picks the motor command. Papers also call the subgoal a skill, a subtask, an option or a high-level action.
Call the observation at step t o-t, the subgoal g-t and the motor command a-t.
g-t is drawn from pi-H-L of g given o-t and the task. a-t is drawn from pi-L-L of a given o-t and g-t.
The high level reads o-t and the task and samples a subgoal g-t. The low level reads o-t and that g-t and samples a motor command a-t. Only the low level moves the motors.
With made-up numbers: pi-H-L picks "open the drawer" with chance 0.7. Given that subgoal, pi-L-L picks "pull" with chance 0.9. The chance of this pair is 0.7 × 0.9 = 0.63.
Pick a design. The boxes show who reads what. The rows below light up each time a model runs.
Illustrative: the two-level design here picks a new subgoal every 10 steps.
A third design, the chain-of-thought policy, is one model that writes the subgoal and then the action at every step.
| Property | Flat | Two-level | Chain-of-thought |
|---|---|---|---|
| Models | 1 | 2 | 1 |
| Learns from subtask labels | No | Yes | Yes |
| Two speeds | No | Yes | Hard |
| Swap one level | No | Yes | No |
The failure. The high level asks for a subgoal that the low level never trained on, so the low level moves at random. The symptom is a sensible plan and a wrong motion. Measure the low level's success on each subgoal the high level sends. The fix is to keep the high level to subgoals the low level can do (Chapter 5).
Chapter 2
Run the high level now and then and the low level at every step, and share the cost of the slow model
Here is how two trained policies become behaviour. This loop is the rollout.
| Step | High level says | Low level does |
|---|---|---|
| t = 1 | "pick up the bread" | move to the bread, close the gripper |
| t = 20 | (same subgoal) | lift, carry to the plate |
| t = 35 | "spread the peanut butter" | pick up the knife, scoop, spread |
| t = 70 | "place the second slice" | reach, position, release |
Three high-level decisions cover about 70 low-level ones. That gap lets the high level be a big, slow vision-language model (VLM): a network that reads images and text. The low level must keep up with the robot, at say 50 commands a second.
Call the time of one low-level call c-LL and of one high-level call c-HL. Call the number of steps per subgoal n. Call the average time per control step t-bar.
t-bar equals c-L-L plus c-H-L divided by n.
Every step pays for one low-level call, c-L-L. The n steps of a subgoal share one high-level call, so each step pays c-H-L divided by n.
With made-up numbers: c-L-L 5 ms, c-H-L 300 ms and n 20. t-bar = 5 + 300/20 = 20 ms, which is 50 commands a second. With n = 1, t-bar is 305 ms, about 3 commands a second.
Each column is one control step. Teal is the low-level call. Purple is a high-level call, spread over its n steps. The dashed line is the 20 ms budget for 50 commands a second.
Illustrative timings: the low-level call is fixed at 5 ms. The average assumes one processor that takes turns.
The failure. If the high level runs in the control loop, the robot freezes for the whole call, once every n steps. The symptom is a pause at each subgoal switch. Measure the gap between motor commands. The fix is to run the high level on its own thread while the low level keeps the last subgoal.
Chapter 3
Derive the hero's formula and find where the gain comes from
Go back to the corridor in the hero. Each doorway is a subgoal, and reaching it is a checkpoint: a test the system can pass or fail. The hierarchy helps in four ways.
| Benefit | How it works |
|---|---|
| Denser supervision | Each subgoal gives its own signal: did the robot pick up the bowl? |
| Shared skills | Learn "pick up" once and use it in many tasks: K skills plus N plans, not N whole tasks |
| Exploration in goal space | Try "go to that door", not random joint wiggles |
| Two clocks | A slow, big model plans and a fast, small one acts (Chapter 2) |
The hero shows the checkpoint benefit. Here is its formula, step by step.
P-finish equals: one minus the quantity one minus one-minus-epsilon to the n, raised to the r, and all of that to the K.
Find the chance that one try at a room goes right. Find the chance that all r tries fail, and subtract it from one. Multiply that room chance across the K rooms.
With the hero's numbers: epsilon 0.05, n 10, r 3, K 10. One try: 0.9510 = 0.599. Three fails: 0.4013 = 0.065, so a room passes with 0.935. The run: 0.93510 = 0.51. The flat policy over the same 100 steps finishes 0.006.
Set r to 1. The formula becomes (1 − ε)nK, the flat policy's. In this toy, the whole gain comes from the check and the retry.
Orange is flat. Teal is two-level. Each room is 10 steps. Set tries to 1 and the two curves become one.
The formula above. Illustrative: real checks make mistakes, and real retries cost time.
The failure. A check that cannot see failure gives no gain. The symptom is a two-level policy that does no better than a flat one. Measure how often the check disagrees with a human label. The fix is a better check, or a fixed replan clock (Chapter 6).
Chapter 4
Choose words, a picture or a position for the subgoal, and see what each one cannot say
The high level hands over g. What is g in the computer: a string, an image or a vector? The choice decides what data you need and what the low level can be told.
| Goal type | What g is | Needs | Weak at |
|---|---|---|---|
| Language | A string: "open the drawer" | Demos cut into pieces and labelled in words | Vague phrases: "move it over there" |
| Image | A picture of the scene after the subtask | Video; no actions or segment labels | The path; flaws in drawn images |
| State | A target vector: a hand position (x, y, z) | A state space with meaning | How to get there |
| Latent | A learned vector | Care: see Chapter 5 | Meaning; it can collapse to a flat policy |
A good goal type has three properties.
The robot can grasp the bowl from the left or the right. Pick a goal type and a grasp. Compare the two subgoals it would send.
Illustrative scene. The bowl ends in the same place for both grasps.
Each type reaches the low level as a different input: a text embedding, a second camera-sized image, or a few numbers. Real systems pick by data. Yell At Your Robot uses language, SuSIE uses images and HIRO uses states (Chapters 7 and 8).
A state goal makes success easy to test. With made-up numbers: the target is (0.40, 0.25) m and the hand stops at (0.43, 0.21) m. The miss is the square root of 0.032 + 0.042, which is 0.05 m. Inside a 0.06 m tolerance, the subgoal counts as reached.
The failure. A vague language goal gives different results on different runs. Measure it: send one command 20 times and compare the end states. The fix is a more exact phrase, or a goal image or target position next to the words.
Chapter 5
Cut demos into labelled pieces, train each level on its own loss, then fit one level to the other
Each level depends on the other. The low level should train on the subgoals the high level will send. The high level should pick subgoals the low level can do. Neither exists yet.
Imitation learning breaks the loop with a segmented demonstration: a demo cut into pieces, each labelled with its subgoal. The low level learns the motor command from the observation and the label. The high level learns the label from the observation.
Call one recorded step i. It has the observation o-i, the demo's motor command a-i and the label g-i. There are N steps. The low level's weights are θ (theta).
L-L-L of theta equals minus one over N, times the sum over i of log pi-L-L of a-i, given o-i and g-i.
For each step i, ask the low level how likely it finds the demo's command a-i, given o-i and the label g-i. Take the log of each chance, average, and flip the sign.
With made-up chances 0.9, 0.6 and 0.2 on three steps: the minus logs are 0.105, 0.511 and 1.609. Their average is 0.742. The step at 0.2 costs the most, so training pushes hardest on it.
The high level uses the same loss with the label g* in place of the motor command, and no subgoal as input.
The strip is one demo cut into four labelled pieces. Drag the step to see what each level learns there. Drag the chance to see that step's loss.
Illustrative demo: 120 steps in four pieces of 30, in the style of a bag-packing task.
Train each level alone first. Then fit one to the other: if the low level fails at some subgoals, teach the high level to avoid them. A pre-trained language model can often serve as the high level as it is, since it already knows how tasks break down.
Why not let g be a learned vector and train both levels end to end on one loss? Then the pair is a flat policy with a hidden layer named g. The gain comes from giving g a meaning and each level its own supervision.
The failure. The high level sends subgoals the low level fails at. Measure the low level's success per subgoal, sorted by how often the high level sends it. The fix is to fine-tune the high level on what the low level did, or to train the low level more on those subgoals.
Chapter 6
Decide when the high level picks again, and value a skill that runs for many steps
The rollout says "until it is time to switch". When is that? Sutton, Precup and Singh (1999) gave the classic answer. An option is a skill with three parts: the states where it may start, its own policy, and a termination rule. The termination rule gives the chance that the option stops in each state.
The high level picks options. Each runs for several steps. This is temporal abstraction: one high-level decision covers many time steps. How much is starting an option worth?
Call the worth of starting option o in state s Q(s, o). The option runs k steps and collects rewards r-1 to r-k. Each step of delay shrinks a reward by γ (gamma). The option ends in state s′ (s-prime).
Q of s and o equals r-1 plus gamma r-2, and so on up to gamma to the k minus 1 times r-k, plus gamma to the k times the max over o-prime of Q of s-prime and o-prime.
Add up the rewards the option collects, each shrunk by gamma once per step of delay. Then add the worth of the best next option, shrunk by gamma once for each of the k steps.
With made-up numbers: k is 4, the rewards are 0, 0, 0 and 1, gamma is 0.9, and the best next option is worth 2. Q = 0.93 × 1 + 0.94 × 2 = 0.729 + 1.312 = 2.04.
In practice there are two switch rules. Completion-based: ask the high level again when a detector says the subgoal has finished. Fixed interval: ask it every n steps.
Four subtasks of 30 steps each. Purple ticks are high-level calls. Grey is idle time, red is wasted work. Turn on the slip and compare the rules.
Illustrative toy. The high level always picks the right subtask. The slip adds a 10-step subtask, "pick up the scoop", before the scooping can go on.
The failure. A completion detector that never fires leaves the agent on one subgoal forever. That is worse than a wrong subgoal, which the next replan fixes. Measure time spent in each subgoal; one that runs far past its usual length means a stuck detector. The fix is a timeout, which falls back to a fixed interval.
Chapter 7
Correct the high level by speaking to it, or let it draw the next scene
Language as the interface. Yell At Your Robot (Shi et al., RSS 2024) puts a two-armed ALOHA robot under a two-level policy. The high level is a vision-language model that writes the next command as text, such as "pick up the bag". The low level is a language-conditioned behaviour cloning (LCBC) policy: it maps images, joint angles and that command to motor targets.
Both start from segmented demos. Then the team improves the high level with DAgger: run the learner, have an expert label the states it reaches, add those labels, retrain. Here the expert speaks.
Each cell is a situation and the command the high level picks there. Red cells are wrong. Each round runs 10 episodes; a person corrects every wrong pick the robot reaches.
Illustrative toy. Each episode has four stages; each stage turns into its recovery case with chance 0.12. The demos showed few recovery cases.
Why it pays, with made-up numbers: the high level makes 4 decisions per run. If each is wrong 10% of the time, a run has no wrong pick with chance 0.94 = 0.66. Cut the error to 2% and that becomes 0.984 = 0.92. The correction costs a sentence, not a session of driving the robot by hand. Hi Robot (Shi et al., 2025) extends this to open-ended prompts and feedback. π0.5 (Physical Intelligence, 2025) has one model first predict a subtask in words, then the motor actions for it.
Images as the interface. SuSIE (Black et al., ICLR 2024) makes the high level an image-editing diffusion model. It reads the current image and the task in words, and draws what the camera should see a short time later. The low level is a goal-image-conditioned policy that drives the scene toward that picture; it never sees words. The high level needs no actions and no segment labels, so it can learn from video of people as well as robots.
| Level | Learns | Data |
|---|---|---|
| High level (image goals) | What the scene looks like next | Plenty and cheap: any video |
| Low level | How to move the arm to match a picture | Scarce: robot data, but short, simple goals |
The failure. The drawn goal image has a flaw, such as a bowl in two places, and the low level chases a scene it cannot reach. Measure the gap between the final frame and the goal image per subgoal. The fix is to draw goals often and train the low level on imperfect goal images.
Chapter 8
Reward the low level for reaching a target, relabel old goals, and find skills with no task reward
With rewards and no demos, HIRO (Nachum, Gu, Lee and Levine, NeurIPS 2018) gives the low level a reward of its own. The high level outputs a goal as an offset: "move 2 m forward and 1 m left". Call the state now s-t, the offset g-t and the next state s-t+1.
r-L-L equals minus the length of s-t plus g-t minus s-t-plus-1.
Add the offset g-t to where the agent is, s-t. That point is the target. Measure how far the next state s-t-plus-1 lands from it, and use minus that distance as the reward.
With made-up numbers: s-t (0, 0), g-t (2, 1), s-t-plus-1 (0.5, 0.2). The miss is (1.5, 0.8), of length 1.7, so the reward is −1.7. HIRO then sets the next offset to (1.5, 0.8), so the target point stays put.
The purple flag is the target the high level asked for. Press Run 8 steps. The dashed purple arrow is the offset the low level reached.
Illustrative toy. A weaker low level takes shorter, noisier steps.
The low level keeps changing, so old high-level records stop being true. HIRO relabels each stored goal with the candidate that makes the recorded low-level actions most likely now. The simplest candidate is the offset reached. Jiang, Gu, Murphy and Finn (NeurIPS 2019) relabel with a sentence that describes what the agent did.
Can skills appear with no task reward? DIAYN (Eysenbach, Gupta, Ibarz and Levine, ICLR 2019) picks a skill z at random with chance p(z). A discriminator q(z | s) guesses the skill from the state.
r equals log q of z given s, minus log p of z.
Reward the skill when the state gives away which skill is running, compared with a blind guess. Skills that end in different places earn the most.
With made-up numbers: 4 skills, so p(z) is 0.25. If q(z | s) is 0.9, r = log 0.9 − log 0.25 = −0.105 + 1.386 = 1.28. If q is 0.25, r is 0: the state tells nothing.
Each shape is where one skill ends, over many runs. Drag the spread and watch the average reward rise toward its ceiling, log 4.
Illustrative: end states scatter with a spread of 0.5 around each skill's centre; the discriminator is the best guess for that scatter.
The failure. Skills can be easy to tell apart and still useless, such as four ways to twitch in place. Measure them with a high level trained on top, on a real task. The fix: let the discriminator see only the features that matter, such as position.
Chapter 9
Find the subgoal length that balances the two levels, and test for the six usual failures
A hierarchy does not remove errors. It moves them to the hand-off between levels. Ask where your gain comes from: goals with meaning, a loss for each level, two clocks, or a pre-trained high level. If you cannot name one, a flat policy of the same size may do as well.
The first test is the subgoal length n. Short subgoals make the high level decide often, and each decision can be wrong. Long subgoals make the low level stay right for many steps.
Take a 120-step task. The high level picks each subgoal right with chance 1 − δ (delta). The low level carries it out within 2 tries. Multiply over the 120/n subgoals.
The curve is the finish chance against steps per subgoal, on a log scale. The left end micromanages; the right end is a flat policy. Drag the two error rates.
Illustrative toy: a 120-step task, 2 tries per subgoal, the corridor model of Chapter 3 plus a high-level error per decision.
With the default numbers, one decision per step (n = 1) finishes 0.2% of runs. One subgoal for the whole task (n = 120) finishes 4.8%. Subgoals of 10 steps finish 22.9%, the best of the three.
| Failure | Symptom | Measure | Fix |
|---|---|---|---|
| Low level cannot do the subgoal | Good plan, wrong motion | Low-level success per subgoal | Fit the high level to the low level |
| Stuck detector | One subgoal forever | Time in each subgoal | A timeout or a fixed interval |
| Latent goal, end to end | No gain over flat | Same-size flat baseline | Give g a meaning and its own loss |
| Wrong subgoal length | Micromanaging, or long low-level runs that fail | Success against n | Sweep n |
| Vague goals | One command, many outcomes | Repeat one command 20 times | Exact phrases, images or targets |
| Slow domain | Two models where one would do | Compare with a chain-of-thought policy | No conclusive comparison exists yet |
Many current robot systems use hierarchical imitation learning. Fine-tuning such a large two-level system with RL is still an open research problem.
Chapter 10
Keep the terms, the numbers, a checklist and the core code on one page
A long task kills a flat policy by compounding small errors. A hierarchy splits it: a slow high level picks subgoals, a fast low level reaches them. The gain comes from checkpoints, a loss for each level, shared skills and two clocks. It is lost when the levels do not fit each other.
| Term or quantity | Meaning or value | Chapter |
|---|---|---|
| Flat finish chance | (1 − ε)T; 0.95100 = 0.6% | 0 |
| Subgoal g | The high level's output, the low level's input | 1 |
| Time per step | c-LL + c-HL/n; 5 + 300/20 = 20 ms | 2 |
| Checkpoint finish chance | K rooms, r tries: 51% against flat 0.6% | 3 |
| Goal types | Language, image, state, latent | 4 |
| Low-level loss | Minus the average log chance; 0.742 for 0.9, 0.6, 0.2 | 5 |
| Option | Start states, a policy, a termination rule | 6 |
| Option worth | Q = 0.729 + 1.312 = 2.04 in the example | 6 |
| High-level DAgger | Spoken corrections; low level frozen | 7 |
| HIRO reward | Minus the miss distance; −1.7 in the example | 8 |
| DIAYN reward | log q − log p; 1.28 at q = 0.9 with 4 skills | 8 |
| Best subgoal length | n = 10 gives 22.9% against 0.2% at n = 1 | 9 |
The rollout with a fixed replan interval, and the low-level loss on segmented demos.
pythondef rollout(env, pi_hl, pi_ll, task, n=20, max_steps=1000): o = env.reset() for t in range(max_steps): if t % n == 0: # fixed interval: replan every n steps g = pi_hl.sample(o, task) # subgoal: text, goal image or target state a = pi_ll.sample(o, g) # motor command, e.g. 14 joint targets o, done = env.step(a) if done: return True return False def low_level_loss(pi_ll, obs, acts, goals): # segmented demos: one (o, a, g) per step; obs [N, ...], acts [N, act_dim], goals [N, ...] return -pi_ll.log_prob(acts, obs, goals).mean() def high_level_loss(pi_hl, obs, labels): # same loss: predict the labelled subgoal g* from the observation return -pi_hl.log_prob(labels, obs).mean()
| Paper | Idea | Goal type |
|---|---|---|
| Options (1999) | Skills with start states and a termination rule | Any |
| HIRO (2018) | Off-policy HRL with goal relabelling | State |
| DIAYN (2019) | Skills with no task reward | Latent |
| Language as an abstraction (2019) | Language goals with hindsight relabelling | Language |
| SuSIE (2024) | An image-editing model as the high level | Image |
| Yell At Your Robot (2024) | High-level DAgger from spoken corrections | Language |
| Hi Robot, π0.5 (2025) | Two-level vision-language-action models | Language |
Now press Present or Teach and derive the checkpoint formula from memory, then explain why r = 1 gives the flat policy back. Then go back to the corridor, set 12 rooms, and say why the two-level bar barely moves while the flat bar vanishes.
This lesson re-teaches the lecture Hierarchy in Imitation and Reinforcement Learning of Stanford CS 224R: Deep Reinforcement Learning. The papers behind it: Sutton, Precup and Singh (1999), options; Nachum, Gu, Lee and Levine, HIRO (2018); Eysenbach, Gupta, Ibarz and Levine, DIAYN (2019); Jiang, Gu, Murphy and Finn, language as an abstraction (2019); Black et al., SuSIE (2024); Shi et al., Yell At Your Robot (2024) and Hi Robot (2025); Physical Intelligence, π0.5 (2025). The toys and numbers here are our own.