In 2006, after years of battling insurgencies in Iraq and Afghanistan, the US military began to develop a new tool it hoped would turn the tide. The Pentagon had already spent billions on gadgets, mine-detectors, and armored humvees. This new tool would be relatively cheap. It had a fancy name: the Human Terrain System. But the concept was simple. More than machines, the military decided that it needed people — social scientists, to be exact — to help US soldiers understand the bewildering behavior of Iraqis and Afghans.

Grasping the customs and structure of a tribe helps soldiers avoid the dire consequences of offending a leader of thousands. Knowing that celebratory gunfire is a tradition at weddings can ensure that US soldiers don’t make the tragic mistake of shooting back.

Now that the American presence in Afghanistan is winding down, it is worth revisiting the idea of these teams and asking: Are social scientists the silver bullet we need for every invasion?

For Vanessa Gezari, author of “The Tender Soldier,” a new book about the Human Terrain teams, the answer is: Not so much.

“Initially, I was extremely hopeful and optimistic about this effort, largely because I had spent time with soldiers in the early years of the war and saw how little they knew about Afghanistan,” Gezari told me. “I’m talking about infantrymen, 19 years old. Most of the folks who were chatting up villagers didn’t speak the language and knew nothing about the culture. They were making all kinds of mistakes.”

But the effort came too little too late, Gezari said. After five years of violent misunderstandings, it is tough to turn a relationship around.

The Human Terrain System faced another major challenge: Some of the academics it hired knew less about Afghanistan than the soldiers. The Pentagon had trouble recruiting qualified people, in part, because many anthropologists and sociologists felt military work violates their ethical code of “do no harm” to research subjects.

Was the Human Terrain System the unethical weaponization of social science? Or a heroic effort to reduce civilian casualties during war? Gezari spent years wrestling with that question.

“I don’t think it is necessary for anthropologists to go to war, and they probably shouldn’t,” she said. “But a more nuanced way of thinking about the places where we operate, including deep reading and research, is crucial for soldiers.”

That raises the question of how to prepare for future wars. Should we start learning about other cultures now — just in case we ever decide to invade? There have been attempts to do just that, Gezari says. The Bowman Expeditions, an initiative of the American Geographical Society, has proposed sending graduate students to study every country in the world so they could advise the US government if the need ever arose.

Perhaps the most striking thing about Gezari’s book is the humanity of those who tried to make the Human Terrain System succeed. Gezari traces the life and death of Paula Loyd, one of the few Human Terrain researchers with a perfect background for the job. A former soldier, Loyd had a master’s degree and years of experience in Afghanistan. She died tragically in 2009, after a mentally unstable Afghan man set her on fire as she was interviewing him about the price of fuel.

Her death forced the US military to grapple with the dilemma at the heart of the program: If you want to understand the daily lives of Afghans, you have to get dangerously close to them. The things you must do to win the war are exactly the same things that get you killed.

No one talks anymore about the Human Terrain System as a silver bullet. The number of teams in Afghanistan are shrinking, along with the troops. Drones, which kill from a distance, without any conversation first, are the new tool of choice. But perhaps we are un-learning the vital lessons of Afghanistan: that if we really want to change a place, we have to understand the local people, and put ourselves in harm’s way.

“Engagement is costly,’’ she said. “In order to be more successful, we have to take more risks. But there are no silver bullets.’’