CONCORD, N.H. — It is a backhanded compliment Andrew Yang has received before, and one that a New Hampshire voter paid him again on Friday as Mr. Yang was campaigning and trying to raise his profile in the 21-candidate Democratic field.

“You’re too nice,” a man told Mr. Yang. “You need to be meaner.”

As his better-known rivals like Senator Kamala Harris of California and former Vice President Joseph R. Biden Jr. have ratcheted up their attacks of President Trump, Mr. Yang, the former tech executive promising to give Americans $12,000 a year, has portrayed himself as a math-obsessed, solution-focused nerd who would be an ideal foil to the president.

But, in part because Mr. Yang is nice — he peppers his stump speech with jokes and the occasional self-deprecating remark — voters have sometimes questioned his pleasant demeanor and whether he can effectively spar with Mr. Trump or even political firebrands on the left like Senator Bernie Sanders of Vermont.

“I’m very passionate about how we can improve Americans’ day-to-day lives, and that’s where I’m focused,” Mr. Yang told dozens of voters inside a packed New Hampshire coffee shop on Friday. “But to the extent anyone has a vicious agenda that tries to keep that from happening — I’ll fight.”