There are so many advantages to having an agent that I won't have space to list them here. But briefly: more money per contract, better contracts, better foreign and subsidiary rights sales, and someone on your side who will enforce those contracts, etc.
If you're going to approach publishers directly bear in mind that most imprints at the bigger ones won't consider you. So your market will be smaller. Yes, you can sometimes find an agent after you've got a contract but why would you? Better to get the agent first, then let them find you a contract--they have access to more publishers, know the market better than you do, and all that stuff.
Some writers do get a contract offer first then look for an agent: it can work but you have to get an agent very quickly under these circumstances, within a day or two, and that's difficult. It can be easier to find an agent once you have a contract, because they'll have to do less work for their commission, for example. But it might well also put agents off, as they won't necessarily want to work with the publisher you find for yourself. If it's a small publisher, for example, there might not be enough money on offer to make it worth their while working on the contract.
In general, if you want to work with an agent you're better off getting one first, and letting them find you a publisher. If a publisher appears on your doorstep asking to publish you then you can get an agent at that point: but I wouldn't look for a publisher first, with a view to finding an agent later. It doesn't really work that way.