Sorry this is a bit late. I answered a similar question here. The tl;dr version is Nepal reach an agreement with the British where Nepal retained general autonomy over domestic affairs while ceding control of foreign policy to the British and permitting British recruitment of Gurkha soldiers.