Tuberculosis is a major public health concern worldwide, and it is a serious threat to human health for a long period. Macrophage phagocytosis of Mycobacterium tuberculosis ( M. tuberculosis ) is a crucial process for granuloma formation, which shelters the bacteria and gives them an opportunity for re-activation and spread. Herein, we report an intelligent anti-microbial peptide that can recognize and trap the M. tuberculosis , inhibiting the macrophage phagocytosis process. The peptide (Bis-Pyrene-KLVFF-WHSGTPH, in abbreviation as BFH) first self-assembles into nanoparticles, and then forms nanofibers upon recognizing and binding M. tuberculosis . Subsequently, BFH traps M. tuberculosis by the in situ formed nanofibrous networks and the trapped M. tuberculosis are unable to invade host cells (macrophages). The intelligent anti-microbial peptide can significantly inhibit the phagocytosis of M. tuberculosis by macrophages, thereby providing a favorable theoretical basis for inhibiting the formation of tuberculosis granulomas.