Model-Based RL: Learning to Plan
Learning how the world works, then planning, searching and dreaming inside the model.
Before a chess player touches a piece, she plays out a few moves in her head. An agent that has a model of its world can do the same: imagine where each action leads, practice in its imagination, and only then act. This lesson follows that idea from a maze solver to AlphaZero and the controllers that steer robots, and shows why a model that is only slightly wrong can lead a planner badly astray.
What you’ll learn
- Explain what a model of the environment predicts, and how model-based agents differ from model-free ones.
- Describe how Dyna turns each real step into many imagined ones, and see the effect of planning in a maze.
- Describe how Monte Carlo tree search looks ahead selectively, and how AlphaZero and MuZero combine search with learning.
- Explain how world models let agents learn in imagination, and how model predictive control replans at every step.
- Explain why model errors compound over long imagined trajectories, and why planners exploit them.
A model: predicting what happens next
A reinforcement learning agent acts, and its environment answers with a new state and a reward. A model of the environment is anything that lets the agent predict that answer before acting: given the current state and an action, it predicts the next state and the reward. The part that predicts the next state is a dynamics model.
Agents that learn what to do straight from experience are model-free. Q-learning, for instance, keeps a score for every action in every state, its action value, and nudges each score toward what actually happens when it tries that action. Agents that use a model, given to them or learned, are model-based. A model can be used in two ways. The agent can generate imagined experience and learn from it as if it were real, or it can look ahead before every decision and compare where different actions would lead. Both are planning: computing better behavior from a model instead of from more real experience.
| Aspect | Model-free | Model-based |
|---|---|---|
| What is learned | Values or a policy, directly | How the world responds, then values or a policy by planning |
| Real experience needed | Often a lot | Often less: each real step is reused many times |
| Computation per real step | Small | Large: planning costs simulated steps |
| Main risk | Slow learning | Trusting a model that is wrong |
A robot vacuum keeps a map of the room and uses it to predict where it will end up after each move. Which part of a reinforcement learning agent is that?
- A policy
- A value function
- A model of the environment
- A reward function
Show the answer
C. A model of the environment
It predicts the consequence of an action, the next state, which is exactly what a model does. A policy would say which move to make, and a value function how good each position is for cleaning.
Dyna: practice in your head
Richard Sutton's Dyna (1990) is the simplest way to learn from a model. After every real step the agent does three things:
- It updates its action values from the real transition, exactly as Q-learning would.
- It records the transition in its model: "in this state, this action led there and paid this much".
- It replays remembered transitions from the model and updates its values on each of them as well.
Step 3 is planning: learning from simulated experience with the same update rule as real learning. With , Dyna is plain Q-learning.
A Q-learning agent (no planning) starts with every action value at 0 in a maze where the only reward, +1, comes on entering the goal. After its first episode, which wanders until it stumbles into the goal, how many of its action values are no longer 0?
Show the answer
1
Only one: the value of the last move, the one that entered the goal. Every earlier update used the target "reward 0 plus the discounted value of the next state", and those values were all still 0. Each further episode can push the reward back by only about one more step. Planning replays the remembered transitions over and over, so the reward spreads back along the whole path without any new real experience.
Planning costs computation, not experience. When real steps are slow, risky or expensive, as with a physical robot, trading cheap simulated steps for real ones is the whole point of model-based RL.
Search: looking ahead before each move
In board games the model is given: the rules say exactly what each move does. A player can look ahead through the game tree of moves and replies. Checking every line to the end is hopeless, though: a game with legal moves per turn and turns has about lines of play, and Go has about 250 legal moves in a typical position and games of about 150 moves.
Monte Carlo tree search (MCTS) looks ahead selectively. Each simulation walks down the tree, preferring moves that have scored well so far but sometimes trying neglected ones, adds one new position to the tree, plays the rest of the game out with random moves, and records the result at every position it passed through. After many simulations the tree is deep along the promising lines and shallow elsewhere, and the agent plays the move it explored most.
Dreaming: learning inside a world model
When the agent sees the world through a camera, predicting every pixel of the next frame is hard and mostly pointless. A world model first compresses each observation into a small internal state, then learns how that internal state changes with each action. The agent can then imagine whole trajectories inside its model, quickly and in parallel.
Ha and Schmidhuber (2018) trained a controller for a game based on Doom entirely inside such a model's "dream" and then ran it in the real game. The Dreamer agents repeat a loop: collect real experience, improve the world model, imagine thousands of short trajectories inside it, and train an actor and a critic on the imagined ones. DreamerV3 (preprint 2023, published in Nature in 2025) used one fixed set of settings across very different tasks and was the first algorithm reported to collect diamonds in Minecraft from scratch, without human demonstrations or a hand-designed curriculum.
Think first A Dreamer-style agent improves its policy mostly on imagined trajectories. What must stay true for the policy it learns to work in the real world?
The imagined trajectories must resemble real ones where it matters for the decisions. That is why the agent keeps collecting real experience to correct its model, imagines only short trajectories that start from states it has really seen, and learns a critic so that it need not imagine all the way to the end of an episode. As of the mid-2020s, large generative video models are also being explored as interactive world simulators; how faithful they are over long stretches is an open question.
Control engineering: plan, act, replan
Engineers were planning with models long before deep RL, in autopilots, chemical plants and rockets. Their models are usually equations of motion: the next state is a function of the current state and the control , such as a force. Optimal control picks controls that minimize a total cost, for example how far the system is from where it should be plus how much effort it spends.
When the dynamics are linear and the cost is quadratic, the answer is remarkably simple: the linear–quadratic regulator (LQR) applies a force proportional to the state, , with a gain computed once in advance. When the problem is messier, model predictive control (MPC) plans the next steps with the model, applies only the first control, measures the new state, and plans again. Because every plan starts from a fresh measurement, the controller keeps correcting for model errors and disturbances: the receding horizon idea.
The catch: a wrong model, trusted
A learned model is never exactly right, and two things make its errors worse than they look. First, they compound: an imagined trajectory feeds each predicted state back in as the next input, so a small error at one step shifts every later step, and the trajectory drifts into states the model has never seen, where it is even less accurate.
A model gets each single step right 99% of the time, independently. What is the chance that a 100-step imagined trajectory contains no wrong step at all?
Show the answer
0.37
. Over 50 steps it would still be about , and over 500 steps less than 1%. Long imagined trajectories are almost never fully right, which is why modern methods imagine only short stretches and start them from real states.
Second, planners exploit errors. A planner searches for the plan with the best predicted outcome, and if the model wrongly believes that some route is excellent, say straight through a wall, that is precisely the plan the planner picks. Random errors become systematic ones, aimed at the agent's own decisions.
| Defense | Idea | Where you will meet it |
|---|---|---|
| Short rollouts from real states | Imagine only a few steps, starting where the agent has really been | MBPO, Dreamer |
| Uncertainty-aware models | Know where the model is unsure, and avoid relying on it there | PILCO, PETS ensembles |
| Replanning | Use each plan for one step, then measure and plan again | MPC |
| Value-focused models | Predict only what decisions depend on: rewards and values | MuZero |
In the Bootstrapping lessons you'll build each idea properly. Dyna: Learning, Planning & Acting develops Dyna-Q, changing environments and prioritized sweeping. Monte Carlo Tree Search builds the four phases of a simulation and the bandit rule that steers them, and works through tic-tac-toe. World Models: Learning in Imagination opens up Dreamer's loop. Optimal Control & Model Predictive Control solves LQR and builds MPC planners. The Fixed Point lessons then prove when a model can be trusted, why search improves a policy, and what a model really needs to predict.
Key takeaways
- A model predicts the next state and reward from the current state and action. Model-based agents plan with it; model-free agents learn behavior directly from experience.
- Dyna learns from simulated experience: after every real step it replays remembered transitions, so planning steps replace many real episodes.
- MCTS plans at decision time by growing a selective search tree from simulations. AlphaZero pairs it with networks trained by self-play, and MuZero searches inside a model it learned itself.
- World models let agents practice in imagination (Dreamer), and control engineering's MPC plans a short horizon, applies the first action and replans.
- Model errors compound over long imagined trajectories and planners exploit them; short rollouts from real states, uncertainty estimates, replanning and value-focused models are the main defenses.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Between real steps, an agent draws transitions from its learned model and updates its action values on them. What is this?
- Model predictive control
- Dyna-style planning: learning from simulated experience
- Monte Carlo tree search
- Model-free Q-learning
Show the answer
B. Dyna-style planning: learning from simulated experience
Dyna applies the same value update to remembered or simulated transitions as to real ones, so each real step is reused many times. With zero planning steps it reduces to Q-learning.
Why can Monte Carlo tree search play Go well when searching every line of play to the end is impossible?
- It searches every move to the same fixed depth
- It stores the best move for every possible position
- It needs no model of the game
- It concentrates its simulations on promising moves, so its tree grows deep only where it matters
Show the answer
D. It concentrates its simulations on promising moves, so its tree grows deep only where it matters
MCTS spends simulations unevenly: moves that keep scoring well get explored further, so the tree is deep along good lines and shallow elsewhere. AlphaGo and AlphaZero add neural networks that suggest moves and evaluate positions, which focuses the search even more.
Model predictive control plans steps ahead but executes only the first action before planning again. Why?
- So that every new plan starts from the real, measured state, correcting for model errors and disturbances
- Because the later actions of a plan are always wrong
- To save computation
- Because the model can only predict one step ahead
Show the answer
A. So that every new plan starts from the real, measured state, correcting for model errors and disturbances
Replanning turns an open-loop plan into feedback control: whatever the model got wrong shows up in the next measurement and is accounted for in the next plan. It costs extra computation, the opposite of saving it.
A learned model makes very accurate one-step predictions, yet a policy trained on 500-step imagined trajectories performs badly in the real world. What is the most likely reason?
- The policy was trained on too little imagined data
- Errors compound along long imagined trajectories, and the policy learned to exploit states where the model is wrong
- One-step accuracy guarantees long-horizon accuracy, so the real environment must have changed
- Imagined data can never be used to train a policy
Show the answer
B. Errors compound along long imagined trajectories, and the policy learned to exploit states where the model is wrong
Each prediction is fed back in as the next input, so small errors accumulate and carry the trajectory into unfamiliar states. A policy optimized on such trajectories is drawn toward wherever the model is too optimistic. Short rollouts from real states and uncertainty estimates are the usual remedies.
AlphaZero searched with the game's rules. What did MuZero have to learn that AlphaZero was given?
- The value of positions
- A policy that suggests moves
- A model of what its moves lead to, learned from experience instead of the rules
- The rules of human opening theory
Show the answer
C. A model of what its moves lead to, learned from experience instead of the rules
MuZero learns a model that predicts, for any sequence of moves, the quantities its search needs (rewards, values and move probabilities) and plans inside that learned model. AlphaZero also learned values and a policy, but it simulated moves with the true rules.
Go deeper
- Dyna: Learning, Planning & Acting · One loop for real and simulated experience.
- Monte Carlo Tree Search · Selective lookahead with a bandit at every node.
- World Models: Learning in Imagination · Latent dynamics models that let agents practice in their own dreams.
- Optimal Control & Model Predictive Control · LQR, trajectory optimization and replanning at every step.
Further reading
- R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, ch. 8 (MIT Press, 2nd ed., 2018).
- J. Schrittwieser et al., "Mastering Atari, Go, chess and shogi by planning with a learned model," Nature 588, 604–609 (2020).