How do i make Pathfinding NPC run away and hide from the player when he looks at it?

Hello everyone! I’m trying to do a thing like bracken from lethal company: he sneaks up to the player to kill him, and tries to get out of visibility of the player when player looks at him (runs away and trying to hide behind the objects, but then waiting when player stops looking at him and he will keep following the player). If player looks at him for too long he becomes aggresive and he tries to kill player, even if player looks at him. But there’s problem: i never have done smart npcs, just thing i have done is simple pathfinding npc, but not more. (and i still very bad at it). How do i make it?