How can we build theoretically satisfying and practically useful models of human cognition? One approach is to characterize cognitive systems as optimal solutions to problems posed by the environment. This approach can explain why people behave the way they do, and it can make generalizable predictions about how they will behave in different contexts. However, it often fails to explain how the mind produces that behavior, and it fails to account for the many cases in which people are not perfectly rational. In this talk, I propose that we can have our cake and eat it too by redefining the "environment" to which cognition adapts. Specifically, cognitive processes are adapted not only to the external environment (the world), but also to the internal environment (the brain). In this view, cognition is cast as a sequential decision problem in which an agent executes cognitive actions to navigate between mental states and achieve a goal. In three domains—attention, memory, and planning—I use a combination of computational modeling and process-tracing experiments to show how this approach can produce explanations of both why and how, and predictions that are both generalizable and accurate.