Like most things in life, knowledge is key. Not in the 'who you know' sense, but in the 'solid research' sense.
While we've already discussed the benefit of an agent, it should be stressed that these are the benefits of a good agent. Which can also be phrased as the right agent. An agent with fabulous contacts and experience in the field of legal non-fiction, for example, might not be the best person to sell your sci-fi/romance.
Equally, an agent who has a different idea of your career than you, may also be a bad fit, or if their levels of editorial support or communication don't suit your particular needs.
Often, these kinds of problems can be solved with communication, but sometimes they lead to the dissolution of the business relationship. If this happens, don't panic. It's really not uncommon and is no reflection on either you or the agent involved. Just make sure you're formally out of any contract with your ex-agent before looking for a new one and be open and honest about your previous experience with potential new agents.
So. Here are some ways to find your perfect literary agent:
A directory such as the Writers' & Artists' Yearbook or AgentQuery. The latter is particularly good for US agencies.
I would recommend cross-checking your facts even when using a reputable directory, as things can change quickly. For example, if there is a big notice on an agency's submission page which reads 'currently closed for subs', you're going to save yourself heartache (and postage).
There is also an Association of Authors' Agents, a voluntary body which upholds a code of conduct and good practice for its members. Many (but not all) of the reputable UK agencies are members and they are listed on the Association's website.
Look in the acknowledgements of your favourite (recently published) books, or books of the same genre as your own. Grateful authors often thank their agents by name.
Twitter. I am NOT advising that you try to query or submit or catch the eye of literary agents via Twitter, but it is a public space and there is nothing wrong with following a handful of your 'dream' agents. The #MSWL Twitter hashtag, which stands for Manuscript Wishlist, is used by agents and publishers to let people know what they're looking for in submissions and is another useful tool.
It was via Twitter that I learned that my agent was 'building her list' (the magic phrase, which means the agent is actively looking for new clients). Agents may mention the genres or type of book they are particularly interested in receiving, updates to submission guidelines, or stuff they are personally interested in. If an agent says they love horses and memoir on social media and your book is called My Life in the Saddle, then you may have just found your perfect match.
Follow book and writer blogs, which offer information and advice (such as this one!) to keep up with industry news. Last week, for example, Novelicious published a handful of literary agents’ wishlists to aid your search for representation.
Next time, I'm going to tackle the nitty gritty of the submission process. Do let me know in the comments if you have any specific questions.