WASHINGTON — President Donald Trump’s impatience with the 17-year-old war in Afghanistan has prompted U.S. diplomats and commanders to gamble on a bid to kick-start peace negotiations, including holding direct talks with the Taliban, current and former U.S. officials told NBC News.

The Taliban has so far welcomed the American overtures and plan to meet again soon with U.S. officials after the latest session about a week ago in Qatar, where the insurgents operate a political office, former U.S. diplomats and Taliban sources said. The indirect U.S.-Taliban talks were first reported by NBC News on July 20.

The outreach represents the most serious diplomatic effort to end the war in five years but comes at a time when the Taliban is in a position of relative strength on the battlefield, firmly entrenched in rural districts with U.S.-backed Afghan forces unable to turn the tide despite ramped-up American bombing.

Afghan government officials remain concerned that the U.S. could appear desperate for a peace settlement, allowing the Taliban to squeeze concessions from a superpower fatigued with a grinding war that has settled into a stalemate.

“There’s a danger that the Taliban will smell weakness,” one foreign diplomat told NBC News.

Trump’s impulsive nature, along with his openly expressed doubts about the U.S. military mission in Afghanistan, has injected a sense of urgency among senior officials and military officers. The last diplomatic attempt to end the war ended in abject failure in 2013, amid acrimony between Afghanistan’s then-President Hamid Karzai and U.S. officials.

Although Trump reluctantly approved the deployment of several thousand additional U.S. troops to Afghanistan last year, he remains skeptical about keeping the 15,000-strong force in place. With no clear military victory in sight, U.S. officials are worried the president could abruptly pull the plug on the mission without advance warning.

“Just because he signed on to this policy in August, most of the people who work for him have no trust and confidence that he’ll stick to his policies,” said a former senior U.S. official familiar with administration discussions, who spoke on condition of anonymity.

As a result, the administration is now focused on a high-risk diplomatic wager to end the conflict. Spearheaded by Alice Wells, the senior State Department official overseeing South Asia, the diplomacy has featured a series of conversations with major powers in the region as well as contacts with Taliban representatives at venues outside of Afghanistan.

Although the U.S. has maintained a channel to the Taliban over the years, the discussions have become more frequent, more high-level and more ambitious, former U.S. officials and foreign diplomats said. However, the talks are still portrayed as preliminary, designed to set the conditions for an eventual negotiation between the Afghan government and the Taliban.

A senior Afghan Taliban official offered a similar description, saying the meetings are not formal negotiations but are meant to find a way to hold “fruitful and results-oriented peace talks in the future.”

The most recent meeting took place within the past week in the Qatari capital of Doha, with Wells leading the U.S. delegation, foreign diplomats said. Taliban sources say meetings have also taken place in the United Arab Emirates.

“We have held a number of meetings with U.S. officials in the past, but never found them this serious for peace talks with us,” the Taliban source said. “They conveyed to us a 100 percent green light for peace talks and we decided to meet again very soon.”

The former number three-ranking official at the State Department, Thomas Shannon, who helped shape U.S. policy for the region in Trump’s first year in office, acknowledged the U.S. dialogue with the Taliban and suggested that the insurgents appear more open to peace talks than in the past.

“Our own engagement with the Taliban has indicated an interest and willingness on their part,” Shannon said at the Aspen Security Forum on July 21.

Shannon also credited Afghan President Ashraf Ghani with creating the conditions for possible peace talks and for rallying other governments — including Islamic countries — to the cause.

He said he was not ready to say he was optimistic, but cited positive signs, like a three-day cease-fire last month, that could eventually produce momentum toward peace or at least a winding down of the war.

“I think we are in a position in which there are possibilities and potential out there for political resolutions,” said Shannon, who retired from the diplomatic service in February.