The Dyna architecture is a reinforcement learning framework, introduced by Richard Sutton around 1990, that integrates learning, planning and acting in one agent. The agent updates its value function or policy from real experience, learns a model of the environment from the same experience, and then performs extra updates on simulated experience generated by that model.
Its best-known instance, Dyna-Q, combines one-step Q-learning with a simple table model and a fixed number of planning updates per real step. Dyna showed that model-free and model-based reinforcement learning are not opposites: the same update rule can learn from both, and planning becomes simply learning from imagined transitions.
How the Dyna architecture combines learning and planning
The Dyna architecture runs a loop with two sources of experience. Real interaction with the environment drives both direct reinforcement learning and model learning, while the learned model feeds an inner loop of indirect learning, which Sutton called planning.
In each cycle the agent acts, observes a reward and next state, updates its value estimates, stores the transition in its model, and then replays n simulated transitions drawn from the model. The table below names the four processes and what each contributes.
| Process | Input | Output |
|---|---|---|
| Acting | Current policy and state | Real transition in the environment |
| Direct learning | Real transition | Updated value function or policy |
| Model learning | Real transition | Updated transition and reward model |
| Planning | Simulated transitions from the model | Further value or policy updates |
Because direct learning and planning use the same update rule, the value function becomes a shared memory. Every real step improves the model, and every planning step propagates value information further through the state space without additional interaction.
The Dyna-Q algorithm step by step
Dyna-Q is the tabular version of the Dyna architecture for deterministic environments, and it is the form taught in most courses. It keeps a Q-table and a model table that maps each visited state-action pair to the last observed reward and next state.
- Observe the current state and choose an action with an epsilon-greedy policy.
- Execute the action and observe the reward and next state.
- Apply a Q-learning update to the real transition.
- Store the reward and next state in the model for that state-action pair.
- Repeat n planning steps: sample a previously visited pair, query the model, and apply the same Q-learning update.
The parameter n controls the planning budget. Setting n to zero reduces Dyna-Q to ordinary Q-learning, while larger values trade extra computation for fewer real interactions. The table summarizes the main parameters.
| Parameter | Typical range | Effect |
|---|---|---|
| Planning steps n | 0 to several hundred | More planning, faster value propagation |
| Step size alpha | 0.1 to 0.5 in tabular tasks | Speed versus stability of updates |
| Discount factor gamma | 0.9 to 0.99 | Weight of future rewards |
| Exploration epsilon | 0.05 to 0.2 | Share of random actions |
| Exploration bonus kappa | Small positive value in Dyna-Q+ | Encourages revisiting old states |
Variants and modern descendants
The original Dyna-Q samples state-action pairs uniformly, which wastes planning effort on states whose values do not change. Later variants focus planning where it matters or handle environments that change over time.
| Method | Key idea | Main benefit |
|---|---|---|
| Dyna-Q | Uniform replay from a table model | Simple and sample efficient |
| Dyna-Q+ | Bonus for long-untried actions | Adapts when the environment changes |
| Prioritized sweeping | Plan backward from large value changes | Much less wasted computation |
| Linear Dyna | Linear models over features | Works beyond small tables |
| Deep model-based RL | Neural world models generate rollouts | Scales to images and continuous control |
Modern algorithms such as model-based policy optimization and the Dreamer family follow the Dyna principle with neural networks: they learn a world model and train a policy on short imagined rollouts. Dyna also resembles experience replay, since replaying stored transitions is equivalent to planning with a nonparametric model that can only reproduce past experience.
Dyna compared with model-free and pure planning methods
Dyna occupies a middle ground between model-free learning and full planning. Unlike Q-learning or SARSA, it reuses experience through a model; unlike value iteration or Monte Carlo tree search, it does not require a complete model in advance and plans incrementally in the background.
| Approach | Needs a model | Sample efficiency | Computation per step |
|---|---|---|---|
| Q-learning | No | Low | Very low |
| Dyna-Q | Learned online | High | Moderate, grows with n |
| Value iteration | Complete model given | Not applicable | High, full sweeps |
| Monte Carlo tree search | Simulator or learned model | High | High at decision time |
The deciding factor is the relative cost of real experience and computation. When interaction is slow or expensive, as in robotics or user-facing systems, Dyna-style planning is attractive; when a fast simulator exists, model-free learning at scale may be simpler.
Limitations and common mistakes
The main limitation of the Dyna architecture is model error. Planning with an inaccurate model can spread wrong values quickly, and the agent may exploit flaws in the model rather than solving the real task.
- Stale models in changing environments mislead planning until Dyna-Q+ style bonuses force re-exploration.
- Deterministic models in stochastic tasks overfit to the last observed outcome; sample or average outcomes instead.
- Long imagined rollouts with neural models compound errors, so modern methods keep rollouts short.
- Uniform sampling wastes planning on irrelevant states; prioritized sweeping fixes this in tabular settings.
- Excessive n can cost more computation than the saved interactions justify.
Practitioners should therefore monitor model accuracy, tune n against wall-clock cost, and treat planning gains as conditional on model quality rather than guaranteed.
Understanding it simply
Think of a person learning a new city. They walk real streets and remember what they saw. Later, at home, they replay those walks in their head. They work out shortcuts without leaving the house.
The Dyna architecture does the same thing. The agent learns from real steps and from imagined steps. The imagined steps come from its own map of the world. More mental practice means fewer real trips, as long as the mental map is accurate.
Applied in practice
A standard teaching case is a grid maze with 47 open cells, a start square and a goal that gives a reward of 1. An agent using plain Q-learning needs many episodes to learn the path, because each episode only moves value information one step back from the goal.
When the same agent uses Dyna-Q with 50 planning steps per real step, each real move triggers dozens of simulated updates across previously visited cells. In the classic textbook version of this experiment, the planning agent finds a near-optimal path within roughly three episodes, while the non-planning agent needs around twenty-five. A robotics team applies the same logic when physical trials are slow: it logs each real trial, fits a dynamics model, and runs short simulated rollouts between trials, which reduces the number of costly hardware runs needed to reach a working controller.