WASHINGTON — After 18 years of war, the United States is once again preparing to unveil a plan for peace in Afghanistan.

Months of dialogue between American diplomats and the Taliban have yielded a framework agreement that is expected to be announced in days. That agreement, in turn, seeks to smooth a path for direct talks between elected Afghan leaders and the Taliban — a significant but tenuous step for a government and its former oppressors.

Those negotiations will be rocky at best, and a final cease-fire could be months or even years away. Crucial obstacles remain, according to military and diplomatic officials, including whether American troops will stay in Afghanistan, how to protect women’s rights enshrined in the republic’s constitution and, importantly, if a future government could share power with the Taliban.

The framework will be announced as presidential elections approach, both in Afghanistan and in the United States, and as violence on both sides continues. The Taliban have kept up a steady march of attacks, but a United Nations report found that Afghan forces and their American allies were responsible for more civilian deaths than the extremists during the first six months of the year. The expected agreement will signal whether peace is even possible.