Anders Fredrik Reuterswärd (1756-1828), arméofficer, diplomat