Less mechanically and more generally, with Spy you generally want to leave your opponent's cards on the top of their decks if they're low-value-in-play cards (so, for example normal Victory cards (that is, besides Nobles, Harem, or Great Hall), or Coppers, or cards that have outlived their usefulness like a Cursing attack when the Curse supply has been depleted), and discard them if they're high-value-in-play cards (so, usually Treasures besides Copper (though sometimes Silver becomes a "bad" card too), or most Actions (besides ones that have been made obsolete like the aforementioned bad Cursing attacks).
The concept of the card is that you cycle past your own "bad" cards, and thus get to your "good" cards faster, while for your opponents, you make them have to go through a whole deck before they get to their "good" cards by discarding their "good" cards. As you become more experienced, you'll have a much stronger intuitive sense of when a card is "bad" or "good."
Spy is notably... not a terribly strong attack, especially if you just have one of them. Militia and Witch are much, much more debilitating to your opponents. It's slightly rare, in my opinion, for Spy to be a really strong buy, though because it's a "cantrip" (ie, +1 Card, +1 Action), it's very rarely a truly weak buy. There are good Spy plays, but they're much more complicated than the more straightforward powerful attacks.