The function of T cells and B cells is to recognize foreign antigens. Antigens are surface molecules on a cell. Once they have identified an invader, the cells respond to remove pathogens or pathogen-infected cells.