Well, you know that necklace that Ser Dontos gave to Sansa in the premiere? In the books, it was a hairnet, but in any case, the gemstones were poisonous, It was his job to make sure that she wore it at the wedding. Then, Olenna removed one of them from Sansa's necklace while comforting her and saying how unthinkable it is to kill a man at a wedding. The poison then ultimately ended up in Joffrey's chalice. It isn't explicitly stated in the books who put it there, but based on what i see as foreshadowing in some earlier scenes and the fact that she distracted everyoen with yelling about the pie before taking his chalice, I very heavily speculate that Margaery will be revealed to have put it into the chalice in the show. So, it was a group effor by Olenna, Dontos, and quite possibly Margaery, aswell as one other character, whose responsibility wasn't hinted at in ANY way this episode.