PALO ALTO, Calif.—At a shopping mall here one recent Friday, six-year-old Ruby Dowling made friends with a friendly egg-shaped robot. Her sister Layla, five, even patted the robot on its glossy white tummy. “This robot is nice,” said Ruby, as a group of children encircled it.

It wasn’t surprising that the bot, named K5, inspired this response—it had been designed to look approachable. When it was surrounded and needed to return to work as the mall’s security guard, though, the K5 did something its small admirers never expected....