A firm appears when it's cheaper to coordinate in the market than internally.
This is of course the Coasian theory of the firm.
A firm distills out of the background noise, a shelling point sublimating out of the chaos into a coherent, bounded entity to allow a particular thing to be done.