Dopamine is required for working memory, but how it modulates the large-scale cortex is unknown. Here, we report that dopamine receptor density per neuron, measured by autoradiography, displays a macroscopic gradient along the macaque cortical hierarchy. This gradient is incorporated in a connectome-based large-scale cortex model endowed with multiple neuron types. The model captures an inverted U-shaped dependence of working memory on dopamine and spatial patterns of persistent activity observed in over 90 experimental studies. Moreover, we show that dopamine is crucial for filtering out irrelevant stimuli by enhancing inhibition from dendrite-targeting interneurons. Our model revealed that an activity-silent memory trace can be realized by facilitation of inter-areal connections and that adjusting cortical dopamine induces a switch from this internal memory state to distributed persistent activity. Our work represents a cross-level understanding from molecules and cell types to recurrent circuit dynamics underlying a core cognitive function distributed across the primate cortex.