Why does a military exist? Is it to protect the land and the culture of the people who's children compose it? Perhaps. Is it to step into a conflict and restore order? Is it for helping the population cope during disasters? Is it for protecting private interests around the world? Is it for robbing resources from other nations? Is it for oppressing a populace with malicious high tech weaponry to turn a profit? The real answer is closer to the first guess. The modern description of purpose would be closer to the last guess.
In practice, the reason it exists, is to be the real boot of fictitious corporate persons. If all the generals of all the world signed a treaty to not use lethal force against any civilian under any circumstances and particularly made a refusal to serve private interests, the corporate menace destroying the planet would be reduced to what it really is...paper. Thus gelded, the corporate persons could then be rewritten to be limited in scope, cooperatively or privately owned, limited to real estate ownership directly related to the purpose of the charter and responsible to people and the environment.
Holding companies could be abolished and the idea erased entirely from the economic lexicon. Wanton polluting and environmental destruction, oppressing or annihilating people and their cultures, and runaway economic imbalances would all be placed in check by a simple agreement. The remaining members of a greatly reduced global military presence could then serve all the more proudly having been given a noble and honorable purpose; public service.
If such an agreement comes to pass it will be remembered as the time the certain destruction of the human race was averted with a pen. If it doesn't happen the reduction of an earthly living paradise into hell will be inevitable and H. sapiens will have failed entirely as a species.