I read this in a fairly recent sci-fi anthology (probably from the 2000s-2010s). The story was set in the future, on another planet. A young boy finds an intelligent pistol with the ability to talk and manufacture special bullets by means of an internal nanofactory.
The boy starts using the pistol to defend himself, but gradually, the pistol influences him to start forming a criminal gang (I think? I remember the boy started/assumed control of some sort of powerful organization).
The boy implants "loyalty bullets" into the members of the organization--if they ever betray him, the bullets will explode.
I think the boy was a street urchin at the beginning of the story, but I'm not sure. I also don't know how it ends.
Googling for stories about talking pistols turns up nothing useful, unfortunately.