Agassi was from Sampras's generation and played until his mid-30s at a competitive level. It was possible to play longer, it's his fault if he was struggling against the newer generation of Hewitt, Federer, Safin, etc.
OTOH, all of Federer's contemporaries retired way earlier than him. Roddick, Hewitt, Safin, Nalbandian, Davydenko, Coria, Ferrero, etc. The only exception was Feliciano Lopez but he's a second-tier level player at best. Federer was an anomaly playing until that age. Even players AFTER him declined considerably earlier like Berdych, Tsonga, Wawrinka, etc.
If Sampras had had Federer's longevity, he wouldn't have been the best of his era (according to this logic) as he would have been still active during Federer's dominance.
Both Federer and Sampras were the best of their era, however, it's a pointless argument. One of Nadal/Djokovic is not the best of his era and they're far better than others that were. This is just a lame argument fans of one player use to justify their player being inferior to another one. "Well, he achieved much more, but there was another one during this time that achieved more.".
Cristiano Ronaldo is the 2nd best footballer of his era, and he is much better than others that were the best during their era.