If you gain control of a permanent "until end of turn," that effect will wear off during the cleanup step, after the end step. You'll control that permanent while considering Agent of Treachery's last ability.