MIAMISBURG, Ohio—A humanoid robot greets visitors to the Dayton-area offices of Yaskawa Motoman, a Japanese company that produces the machines being installed at thousands of factories around the globe. Its right arm is holding a screen, which playfully challenges visitors to compete with the robot in a manual task: tracing the word YASKAWA as quickly as possible.

It’s a trick, of course: The robot always wins. On the multiple times I tried, I never beat the robot, and lost in both accuracy and speed by large margins. The robot could complete, in just a few seconds, a task that took me eight seconds at my fastest, and much more at my slowest (and most accurate). After it beats the visitor, the robot twirls the screen between its two arms, showing off yet another task that a human can’t do nearly as well. And then, a message pops up on the screen, in bright red: “YOU LOSE. ROBOTS WILL ALWAYS WIN ... ALWAYS!!”

Though the message is tongue-in-cheek, its gist appears to be increasingly true. Robots and algorithms are proving themselves better than humans at a number of tasks, both physical and mental. A Google computer program, AlphaGo, is beating top masters around the world at Go, which is considered one of the world’s most difficult games. San Francisco-based Momentum Machines has unveiled a robot that can make 400 hamburgers in an hour, a much faster rate than humans can. Foxconn, the company that builds electronic devices for companies including Apple and Samsung, is reportedly replacing tens of thousands of factory workers with more-efficient robots.

The news about these developments often has an air of panic about it, as economists worry about how humans will make a living if the machines are doing all the work. The numbers are certainly concerning: Evidence suggests that industrial robots like the ones made in the Yaskawa factory have cost thousands of American jobs. The number of industrial robots, which are automatically controlled, multipurpose, reprogrammable machines, increased fourfold between 1993 and 2007, according to a recent study by MIT economists Daron Acemoglu and Pascual Restrepo. The authors found that one such industrial robot in a metropolitan area reduced employment by about six workers, costing the U.S. economy 670,000 jobs between 1990 and 2007.

But there are positives too. The MIT economist David Autor has emphasized that automation also complements labor, making workers more productive. There are certain tasks that robots can’t do, he writes, and humans will always be needed for those. Working along with robots, humans can also create new, better jobs. Indeed, another study, out of the Information Technology and Innovation Foundation, shows that between 2010 and 2015, six technology-related jobs were created for every 10 jobs lost. And despite the deployment of thousands of robots across the country, the unemployment rate is at a 10-year-low, and worries of widespread joblessness have yet to materialize.

My visit to the Yaskawa factory illustrated these positives. I talked to a 25-year-old process engineer named Greg Smith, who has a bachelor’s degree in mechanical engineering and is finishing up his master’s in electrical engineering. He showed me an automated vehicle that communicated with a humanoid robot to move parts around a factory floor, as the robots checked the parts to make sure they were made correctly, and retooled those that were not. We walked by a Yaskawa robot that could stack objects on top of one another, and one that took items off an assembly line and packed them in a box. Another robot—one of Yaskawa’s most popular products—welds metal parts together faster and more accurately than humans can.

All of those robots are going to replace humans who do the same work, but on the other hand, Smith has a job because of the success of companies like Yaskawa. Increasingly, he told me, he is designing robots that work with humans collaboratively. Smith’s grandmother doesn’t like that he works with robots—she thinks he’s putting people out of work—but his career, at least, is secure. “My job will never go away,” he told me.

Yaskawa robots picks boxes off an assembly line (Alana Semuels / The Atlantic)

Smith said his approach to automation is a simple one: If American companies don’t automate, they won’t be able to compete with foreign companies that do. Besides, he said, robots conduct work that humans probably don’t want to do, work that is dirty, dangerous, and dull.

Still, it can be awkward, senior process engineer Jack Moore told me, to visit a company whose CEO is talking about replacing people with machines. The CEO will show Moore a line of men welding, and say he wants to replace at least one of them with the product Moore is trying to sell.

What’s the difference between workers like Smith and Moore, and the people who might be automated out of a job? The answer is simple: education. Workers with advanced degrees are going to be designing and making the robots—what Elon Musk refers to as the process of making the machines that make the machines.“The people empowered to educate themselves,” Moore said, “are still going to be here.”

That’s not to say that the job of every person with a college education is going to be safe. In a 2013 Oxford study that predicted the jobs that would be most susceptible to automation, Carl Frey and Michael Osborne put insurance underwriters and tax preparers at the top of the list. But jobs that require creativity and critical thinking—jobs like the ones Smith and Moore have—should be secure. The jobs least likely to be automated on Frey and Osborne’s list included surgeons, curators, and mechanical engineers.

Ensuring that the American workforce is adept at versatile thinking and has a job that allows them to employ the skill is an intimidating endeavor, one that goes far beyond workforce training. It’s about improving K-12 education and helping more people get on a path to college or some sort of advanced degree. According to a recent study out of the Institute for Spatial Analysis at the University of Redlands, workers without a high-school degree face an almost six times higher risk of their jobs being automated than those with a doctorate. Minorities could be especially hard hit by the coming wave of automation because of their education patterns: Hispanics are 25 percent more likely than whites to lose their jobs to automation, while African Americans are 13 percent more likely.

Places like Yaskawa are leading the American workforce into a new future, where certain jobs that were once done by humans are going to be done by machines. That seems like a scary proposition, but it doesn’t have to be. Automation can also creates job, and good ones, for the people whose jobs machines can’t replace. The question will be how to make sure more Americans are in that lucky group.