In the A Song of Ice and Fire novels, Varys was Master of Whisperers under King Aerys II Targaryen at the time of Robert's Rebellion. He cautioned the king not to let Tywin Lannister's army within the gates, but Grand MaesterPycelle (secretly Tywin's agent) convinced the Mad King that Tywin had come to turn the tide of the war back in his favor, and to let his army inside the gates. As soon as the army entered the Lannisters turned on the Targaryens, in the destructive Sack of King's Landing. After Robert Baratheon was crowned king, he pardoned Varys and kept him in his position as Master of Whisperers, which he would maintain through the rest of Robert's rule. Thus, by the beginning of the narrative, Varys has been the head of the realm's spy network for over twenty years. It is unknown specifically why Robert pardoned Varys, much less kept him in such a sensitive position, though it may simply be because he was very good at his job (though this is revealed to be detrimental to Robert, as Varys secretly remains a Targaryen loyalist, in contact with Illyrio Mopatis in orchestrating the affairs of Prince Viserys Targaryen, and the marriage of his sister Princess Daenerys Targaryen to Khal Drogo).