Last October, the Bush administration arranged a briefing for aides to Barack Obama and John McCain on the deteriorating situation in Afghanistan. Among the expert advisers was David Kilcullen, an Australian counterinsurgency guru who had been one of the architects of the U.S. troop surge in Iraq.

"We said the situation was extremely difficult in Afghanistan, with a security crisis and a political crisis occurring at the same time," Kilcullen remembers. Obama had been talking on the campaign trail as if Afghanistan's problems could be fixed by adding more U.S. troops. The briefing was a wake-up call that the next president would face some agonizing policy decisions.

Now President Obama is in the final stages of his strategy review for Afghanistan and Pakistan. And Kilcullen, meanwhile, has just published a book that distills the advice he has been offering to the White House (Bush and Obama, both) and to Gen. David Petraeus, the Centcom commander. The book, "The Accidental Guerrilla," offers the clearest road map I've seen for moving ahead in Afghanistan.

Obama's policy choices for Afghanistan are usually presented in stark terms: Either he authorizes a major new escalation, well beyond the 17,000 additional troops he has already approved, or he scales back the mission to a narrower counterterrorism effort aimed at preventing al-Qaeda from mounting attacks.

Kilcullen argues that either of these extreme options would be a mistake. "It would be the height of folly to commit to a large-scale escalation now," when the political climate in both Afghanistan and neighboring Pakistan is so uncertain. We should use the extra 17,000 troops to stabilize the situation but delay the big decision about escalation until after Afghanistan's presidential election in August.

Kilcullen understands the mix of political and military factors that drives the wars in Iraq and Afghanistan. And although he made his name as the strategist of Petraeus's troop surge, Kilcullen is actually quite cautious about using military power to combat Islamic militants. He argues in the book that Bush's 2003 invasion of Iraq was "an extremely serious strategic error" and that the United States "should avoid such interventions wherever possible, simply because the costs are so high and the benefits so doubtful." But once we're in, there's no easy exit.

The problem in these small wars is that U.S. military power creates a backlash that fuels even more violence. This conundrum is expressed in Kilcullen's title, "The Accidental Guerrilla." Most of the people we ended up fighting in Iraq and Afghanistan didn't start with any major grievance against the United States. They were drawn into the fight almost by accident, as they reacted to American efforts to destroy al-Qaeda and other Muslim foes.

Kilcullen offers a four-stage model to explain the radicalization of the typical Taliban supporter in Afghanistan. The process begins with "infection," as al-Qaeda establishes a presence; next comes "contagion," as al-Qaeda uses its haven to mount attacks; then follows "intervention" by the United States to destroy al-Qaeda's sanctuary and its Taliban protectors; and that produces "rejection," as the local population allies with al-Qaeda and the Taliban against the foreign invaders.

For America, it's a costly and self-defeating exercise -- which is precisely what al-Qaeda intends. Kilcullen quotes a haunting 2004 statement by Osama bin Laden: "All we have to do is send two mujaheddin to the furthest point east to raise a cloth on which is written al-Qaeda, in order to make the [U.S.] generals race there to cause America to suffer human, economic and political losses . . . so we are continuing this policy of bleeding America to the point of bankruptcy."

Kilcullen argues that the Obama administration can gradually stabilize Afghanistan using the same combination of political and military power that Petraeus used in Iraq. The right strategy is to remove the "accidental" combatants from the battlefield -- by negotiating with them, buying them off, sharing power with them or just ignoring them. At the same time, the United States must ruthlessly pursue its deadly adversaries in al-Qaeda and separate them from the Afghan population. Above all, Obama must avoid creating a backlash in neighboring Pakistan by heavy-handed U.S. military intervention there.

Obama inherits a messy war in Afghanistan. Kilcullen's advice, as I read him, consists of three "don'ts." Don't do it again; don't make it worse by overescalation; don't think you can pull out now without damaging U.S. interests. For Obama, that means a measured commitment, somewhere between a major escalation and a minimal force.