The Heavenly Guard is one of the Agatean Empire's military forces. This army does not seem to get involved in the massive civil wars that break out upon the death of an emperor. Rather, they defend the borders of the Agatean Empire against barbarian invasion... at least, they claim to.
For their main duty is to patrol the Great Wall, at least during Mort. By Interesting Times, the Silver Horde just climb right over the wall with no trouble at all. Then again, it makes sense that the Guard was no trouble at all to people like Cohen the Barbarian, especially since their main function is to tread heavily on the fingers of anyone who thinks it might be nice to step outside the Wall for five minutes for a breath of fresh air, not protecting against barbarian invaders. As Cohen notes to Rincewind, the Wall's purpose is to keep people in, not keep other people out.
However, they also serve the emperor in other things. At a feast in Bes Pelargic, the Boy Emperor summoned four Heavenly Guards brandishing cando swords (well, three- one was hurriedly trying to swallow a lighted dog-end) to ensure that the Grand Vizier still had enough of an appetite to eat the bladder and spleen of a deepwater puff eel in Mort. Possibly, then, they also act as the Emperor's personal guards?