With the federal government struggling to tackle the nation’s most pressing issues, from crumbling infrastructure to immigration reform, much of the responsibility of governing has fallen to local officials. But how are they supposed to get things done in one of the most partisan environments in years?

The answer, according to Greg Stanton, the Democratic mayor of Phoenix, and William F. Weld, the former Republican governor of Massachusetts, is to build relationships where you can.

“You work with whoever’s going to work with you — sometimes it’s Democrats, sometimes it’s Republicans,” said Mr. Stanton, who discussed the art of compromise with Mr. Weld on Tuesday for a panel during “Cities for Tomorrow,” a two-day event organized by The New York Times that began on Monday.

In some cases, policy makers can find crucial allies outside politics, as was the case when Mr. Stanton decided his city needed a municipal identification card that undocumented immigrants could use.