The primary function of Langerhans cells is to act as antigen-presenting cells (APCs). They capture and process microbial antigens, then migrate to lymph nodes where they present these antigens to T cells, initiating an adaptive immune response. This makes them essential in the body's defense against pathogens.