Wal-Mart Stores has agreed to buy Kosmix, a social media start-up focused on e-commerce, as it looks for new ways to tap into customers via social networking sites and smartphones.