Literary agents are a relatively new invention. In the beginning there were just publishers, and authors submitted directly to them.
But then people set themselves up as negotiators on behalf of authors when dealing with publishers. This was a really good idea because all that needs different skills from writing, and it meant the authors could just get on with the next novel.
Also publishers tended to look more kindly upon manuscripts which came via literary agents, as those manuscripts had been through a filtering process (i.e., the agent wouldn't have taken it on if it wasn't any good) and that saved time for the publisher. (Publishers dread ploughing their way through the slush pile as much as authors hate their manuscripts languishing there.)
It's my understanding that in the dark distant depths of time, literary agents acted as mentors to authors. They minded them, and nurtured them, and befriended them, and encouraged them and so on. But that might only be a rumour.
Nowadays the relationship between authors and their agents is much more defined and professional. In a highly competitive market, with more and more people submitting manuscripts every year, the authors need the literary agents more than the literary agents need the authors. So there's a totally different dynamic.
Also, some publishers will not accept unagented work or unsolicited manuscripts (their websites will advise). So in that case you absolutely need an agent.
However ... just to make things interesting, the competition for literary agents is so strong - that sometimes they won't take on a new author until and unless she already has an offer from a publisher! If that sounds like Catch-22, it's because it is!
Not every agent is like this. But some, especially the bigger names, do prefer this to be the case.
Certainly if you were to approach an agent with an offer from a publisher in your pocket, they would (not surprisingly) be much more interested in talking to you.
Why might you need an agent then, you might be wondering. That's a decision for you to make, of course, but consider that an agent will no doubt get you a better contract with better terms than you would have got yourself. Your agent will also be able to sell your manuscript overseas, and maybe even sell its film rights. A good agent should always get you more money than her commission costs you.
So my advice is to submit to both agents and publishers at the same time - as much as is possible given their terms. Don't go against their requirements, it'll get you nowhere.
It's important to get an agent you feel comfortable with. You don't have to be best friends, but you will be working together. Also, some agents will still offer editorial advice on work; others won't. It depends on their background and interests. It would certainly be one of the questions you'd need to ask a potential agent.
Literary agents are paid on commission. These commission rates should be around the 15% range for domestic, 20%-25% for overseas and translation.
But - and this is so, so important - you never, ever, ever pay an agent any money whatsoever. There are unscrupulous people out there, many of them, who try to prey on writers by offering to take their manuscript on board for a fee. Maybe that fee is dressed up as editorial services* or whatever, but it's still a fee.
Don't pay it!
These unethical people won't even have the contacts needed to get you a contract. It's a total losing proposition - don't do it!
(Now, be aware that some agents can charge some of their out-of-pocket expenses such as postage and photocopying, on top of their commission. I think this is a bit unfair myself, but it is ethical and industry standard. However, the difference is that even those costs will only be taken out of income earned for you - you will not be required to pay them up-front. If the manuscript doesn't sell, then the ethical literary agent wouldn't charge you even those costs.)
*Editorial Services - it's fine to pay for genuine editorial services of course. But the difference is that a genuine editor doesn't make you any promises beyond a quality editing service. They don't say, "I'm an agent and if you pay me/my staff to edit your work, I'll take you on."