SummaryDopamine is critical for working memory. However, its effects throughout the large-scale primate cortex are poorly understood. Here we report that dopamine receptor density per neuron, measured by receptor autoradiography in the macaque monkey cortex, displays a macroscopic gradient along the cortical hierarchy. We developed a connectome- and biophysically-based model for distributed working memory that incorporates multiple neuron types and a dopamine gradient. The model captures an inverted U-shaped dependence of working memory on dopamine. The spatial distribution of mnemonic persistent activity matches that observed in over 90 experimental studies. We show that dopamine filters out irrelevant stimuli by enhancing inhibition of pyramidal cell dendrites. The level of cortical dopamine can also determine whether memory encoding is through persistent activity or an internal synaptic state. Taken together, our work represents a cross-level understanding that links molecules, cell types, recurrent circuit dynamics and a core cognitive function distributed across the cortex.