When robot Nao laughs, he does so with his whole body: slapping his knees, shaking his head. But the adorable android, made by SoftBank Robotics, is not merely good at expressing mirth; he can correctly identify as much as 65 percent of happy laughter outbursts in humans, according to a study presented in 2015 at a nonverbal language workshop in the Netherlands. Once robots like Nao master human laughter, they will make far more likable and realistic companions.

Nao's creators and other scientists are studying the minutiae of human laughter—acoustics, breath, body movements and vibrations—to translate them into algorithms that robots and avatars can learn. And that includes learning how to be funny. In 2016 researchers in South Korea and Singapore showed that Nao is already quite good at telling jokes. When he did a stand-up routine alongside an experienced actor, his taped performance was later consistently rated just half a point below the human on a scale of 1 to 7. Moreover, people were less disgusted by disparaging jokes if the robot told them. Nao “exceeded my expectations,” says Taezoon Park, an industrial engineer then at Singapore's Nanyang Technological University and the study's lead author. Park says that in the future, scientists will optimize the robot's tone of voice, facial expressions and subtle gestures to fine-tune his comedy.

Robots still have a long way to go to fully understand human laughter, which can signify anything from happiness and amusement to sexual interest, embarrassment or anger. Also baffling to machines is the fact that laughter can vary: there is the classic ha-ha-ha laughter, speech laughter (when you speak while laughing) and smile speech (talking while smiling). Distinguishing among these types will be vital for better human-robot interactions. “Because laughter is such a crucial part of what it means to be human, we won't have convincing artificial intelligence until our machines can laugh along with us,” says Gary McKeown, a psychologist at Queen's University Belfast who also works with Nao but was not involved with the new research.

Further, for robots to laugh convincingly with humans, they must be able to tell when a person wants such an interaction. “The inviting laugh is longer and louder and has a higher pitch than an isolated laugh,” says Khiet Truong, a computer scientist at the University of Twente in the Netherlands who studies how people interact with virtual agents and robots. “Humans respond to an inviting laugh within half a second on average,” Truong says. “We hypothesize that robots should do the same—otherwise it is no longer natural.”

If these efforts succeed, we may soon have humorous robots and avatars that can assist the elderly, cheer up hospital patients, play with kids and help keep us amused.