Antimicrobial peptides act as a host defense mechanism and regulate the commensal microbiome. To obtain a comprehensive view of genes contributing to long-term memory we performed mRNA sequencing from single Drosophila heads following behavioral training that produces long-lasting memory. Surprisingly, we found that Diptericin B, an immune peptide with antimicrobial activity, is upregulated following behavioral training. Deletion and knock down experiments revealed that Diptericin B and another immune peptide, Gram-Negative Bacteria Binding Protein like 3, regulate long-term but not short-term memory or instinctive behavior in Drosophila. Interestingly, removal of DptB in the head fat body and GNBP-like3 in neurons results in memory deficit. That putative antimicrobial peptides influence memory provides an example of how some immune peptides may have been repurposed to influence the function of nervous system.