The first step is to realize that bees are not miniature people. They are not capable of complex human emotions like being angry or happy with you. Rather, they respond to specific stimuli in very predictable ways. When beekeepers understand the triggers for defensive behavior, they can work their colonies without switching on the sequences of behavior associated with colony defense. The dynamics of the defensive response include guarding, attacking, and pursuit, each of which is often mediated by alarm pheromones.
Defensive behavior is a part of the overall division of labor in the colony.
Bees initiate guarding about 15 days from birth - slightly before beginning to forage. Guard bees typically spend about 1.5 days guarding before assuming other duties. We do not know why certain bees become guards while others do not. A colony's defensive response is initiated by guard bees. Guard bees assume a typical posture, forelegs off the ground, antennae held forward, and mandibles closed.