The French consulting company Capgemini SE has agreed to buy IT outsourcing firm WNS Holdings Ltd. for $3.3 billion in cash in a push to expand its presence in artificial intelligence, a technology investors fear could undermine the group’s business.