Problem:
A vaccine typically contains an agent that resembles a disease-causing microorganism, and is often made from weakened or killed forms of the microbe, its toxins or one of its surface proteins. The agent stimulates the body's immune system to recognize the agent as foreign, destroy it, and "remember" it, so that the immune system can more easily recognize and destroy any of these microorganisms that it later encounters.
Question: How does the immune system ""remember"" a foreign agent introduced via a vaccine? And how does it learn how to deal with subsequent encounters? Please answer the question and describe it.