Good old method always work.
Thank you AHAHAH
apparently using a 2d collider on the canvas where you want to limit the click solves the problem with !EventSystem.current.IsPointerOverGameObject()
Here is the code:
public void OnGUI()
{
if (onlyOnClick && cam != null && Mouse.current.leftButton.wasPressedThisFrame)
{
if(EventSystem.current.IsPointerOverGameObject())
{
// UpdateTargetPosition();
Debug.Log("1");
}
else if(!EventSystem.current.IsPointerOverGameObject())
{
UpdateTargetPosition();
Debug.Log("2");
}
}
}
log “1” only showed if I clicked on the agent location so I suspected it interacted with the rigidbody.
And that’s it.
Thank you for your time. 
I hope the explanation will be useful for other users in the future as well!
Update:
Little solution for people that have the same problem and want to not click outside the screensize:
public void OnGUI()
{
Rect boderlimit = new Rect(0, 0, Screen.width, Screen.height);
if (onlyOnClick && Mouse.current.leftButton.wasPressedThisFrame && boderlimit.Contains(Mouse.current.position.ReadValue()))
{
if(!EventSystem.current.IsPointerOverGameObject())
{
UpdateTargetPosition();
}
}
}
Of course change to your project input, I’m using new Unity input system (UnityEngine.InputSystem)