There's nothing here to stop the agent when it reaches its destination; likely the shaking is because it's constantly trying to move to another position that it never quite reaches, thus continues to make small changes and the cycle continues...
A way to stop this is to add something similar:
var distance_to_next_step = transform.origin.distance_to(dir)
if distance_to_next_step < DISTANCE_THRESHOLD:
return