Neural circuits perform a diverse range of functions, from encoding sensory signals to storing memories and controlling muscle movements. A long-standing challenge is to work out which functions are performed by different circuits, and how. I will argue that a well-established framework (inverse reinforcement learning) for estimating an agent's goals, such as an animal looking for food or a person driving to work, could be used to infer the function performed by a recorded neural circuit. This framework could help reveal the various computations neural circuits have evolved to perform. Further, it could predict how neural responses should adapt to perform the same function under varying conditions (e.g.~different stimuli/cell death).