Cognitive switches and adaptive neural dynamics in cortical circuits