Metformin is the first-line therapy for treating type 2 diabetes and a promising anti-aging drug. We set out to address the fundamental question of how gut microbes and nutrition, key regulators of host physiology, affect the effects of metformin. Combining two tractable genetic models, the bacterium E. coli and the nematode C. elegans, we developed a high-throughput four-way screen to define the underlying host-microbe-drug-nutrient interactions. We show that microbes integrate cues from metformin and the diet through the phosphotransferase signaling pathway that converges on the transcriptional regulator Crp. A detailed experimental characterization of metformin effects downstream of Crp in combination with metabolic modeling of the microbiota in metformin-treated type 2 diabetic patients predicts the production of microbial agmatine, a regulator of metformin effects on host lipid metabolism and lifespan. Our high-throughput screening platform paves the way for identifying exploitable drug-nutrient-microbiome interactions to improve host health and longevity through targeted microbiome therapies.