Whole-brain, cellular-resolution imaging reveals a hierarchical thalamus–brainstem attractor network that encodes recent history and shapes behavioural bias in zebrafish.