Retail giants are laying off workers or keeping headcount flat as they pledge to become leaner businesses where artificial intelligence does more of the work.