What is the function of cognition? On one influential account, cognition evolved to co-ordinate behaviour with environmental change or complexity. Liberal interpretations of this view ascribe cognition to an extraordinarily broad set of biological systems—even bacteria, which modulate their activity in response to salient external cues, would seem to qualify as cognitive agents. However, equating cognition with adaptive flexibility per se glosses over important distinctions in the way biological organisms deal with environmental complexity. Drawing on contemporary advances in theoretical biology and computational neuroscience, we cash these distinctions out in terms of different kinds of generative models, and the representational and uncertainty-resolving capacities they afford. This analysis leads us to propose a formal criterion for delineating cognition from other, more pervasive forms of adaptive plasticity. On this view, biological cognition is rooted in a particular kind of functional organisation; namely, that which enables the agent to detach from the present and engage in counterfactual inference.