Rules and mechanisms for efficient two-stage learning in neural circuits