Companion Management Issue

For example, I spawned an NPC. Another player was nearby and started fighting my NPC. Then the player stopped fighting. I tried clearing the NPC’s tasks so it would stop fighting and start following me.
It begins running toward me, but suddenly stops and just stands still without moving. I have to call it again, and then it starts running to me once more. This time it follows me properly.
I don’t know how to fix this anymore.