The microbiota produces thousands of potentially bioactive small molecules1–3. High-throughput bioactivity screens of in vitro commensal cultures have exposed microbiota metabolites that shape host physiology by activating diverse G-protein-coupled receptors (GPCRs)4–7. However, owing to technical limitations, the GPCRome-wide bioactivities of in vivo metabolomes, which result from complex diet–microorganism–host interactions, remain unclear. Here we used a multiplexed GPCR screening technology to assess GPCRome-wide bioactivities of 100 commensal strains grown in vivo in monoassociated germ-free mice or in vitro in bacterial culture medium. In vivo and in vitro commensal metabolomes exhibited distinct GPCR activation patterns due to (1) host-mediated metabolite degradation; (2) in vivo microbial metabolic reprogramming; and (3) biotransformation of dietary substrates. Notably, we found that multiple commensal strains produced acetylcholine (ACh) in vivo through the conversion of dietary choline, including select Bifidobacterium strains that dominate the microbiome in early life and a probiotic Pediococcus strain. Mechanistically, we identified and characterized the bacterial enzymes that mediate this biotransformation in Bifidobacterium breve and Pediococcus pentosaceus, and generated an isogenic mutant B. breve strain lacking ACh production. Mice colonized with ACh-producing B. breve exhibited enhanced intestinal immunoglobulin A (IgA) production, altered microbiota composition and increased resistance to enteric infection. These findings underscore the profound impacts of the in vivo environment on microbiota metabolism and reveal a diet–microbiome–host axis that strengthens mucosal immune defences and reinforces host–microbiota mutualism.