Almost all monsters will retaliate when attacked, except if a player is unreachable as in safespotting. For instance, when a player attacks a monster from greater distance than the distance a monster can perform attacks, then the monster may retreat. Usually, a monster has a distance check of a specific amount of tiles, thus its roam range. That means if a player walks that amount of tiles away (starting at the tile the monster spawns), it would rather retreat when being attacked from that distance or just stop attacking a player if so is being done vice versa.
Safe-spotting can limit or prevent monster retaliation in some cases. Since monsters lack the awareness to react to safe-spotting, players can utilise a safe spot to safely attack certain monsters with Ranged, Magic, or a halberd. When implementing this tactic, however, players should be wary of hostility and wander radius.
A player has an option in the Combat tab to select whether or not they want to retaliate automatically or not. If Auto Retaliate has been enabled, and the entity attacking starts to walk or run away, the procedure would be introduced where the player follows that entity and attack in the meantime (while walking or running).