Know who you are.
This is the most important part of finding an agent. Not the book, not the query. You.
Okay, the book is definitely important. You have to have a great book to get an agent. Not a book that's okay or a book that's good enough, but a book that is great. A book that you've read at least twenty times and know—KNOW—is as perfect as you can make it.
And the query is kind of important. Though I'll argue that most writers spend too much time worrying about the query and not enough time worrying about the book. A great book can save a shitty query but a great query can't save a shitty book.
But the most important thing you have to do prior to finding an agent is know who you are. Know who you are as a person, as a client, as a writer, as an entrepreneur.
Can you get an agent if you don't know those things or haven't ever thought about them? Sure! I did. But it can really mess you up later.
I'm not particularly needy, but I do crave some form of validation, especially with my writing. I know what I want to say and I have extremely strong feelings about my ideas and what sorts of books I want to write, but I'm still open to discussing them. At the same time, I will get to a point where I feel strongly enough to stick to my guns about a thing. I'm a principled person. I'm willing to bend, but I'm also willing to put everything on the line for what I believe in. I enjoy writing things that make people laugh, but I also want to write things that make people feel. I feel that writing comedy is a limited career path, especially in YA, and that balls-to-the-wall humor books are the sort of thing that an author can get away with once, maybe twice in a career. My interests vary wildly, so my ideas from books vary wildly too. I am flighty with my ideas, and I will get super-excited about one, telling all my friends that THIS IS THE ONE, until the next day when I come up with something better. It's the ideas that I don't talk about that I generally end up writing. I am self-aware in that I know these things about myself but am not particularly able or willing to change them. I don't take criticism well but I do take it to heart. When criticized, I will either shut down or attempt to come up with a solution that takes my story to an extreme, all the while quietly attempting to figure out a good solution. When I brainstorm with others, I usually don't want to hear their ideas as much as I want them to act as a reflective surface upon which I can see my own ideas. But I will listen to other people's ideas. I respect people who respect me. The best way to get me to do something is to be honest and tell me why I should to it. The worst way is to give me an ultimatum. I am equal parts logical and emotional. Though I frequently respond to things in an emotional way, my logical brain is always behind the scenes, working through the problem. Sometimes my sincerity comes off as insincere because I really want people to like me. I'm really horrible at interacting with people. The more I respect a person, the worse I am at interacting with them.
That mess up there? That's me. It's not particularly flattering. But it's honest.
The right agent for me is someone who can guide me without being patronizing. Someone who can give it to me straight without being threatening. Someone who understands that I may need to hear an idea three or four times before I realize it's the right thing to do. Someone who gets that it often takes me a while to come around, and doesn't hold that against me. Someone patient, but firm. Someone who's willing to bend but isn't a pushover.
See what I mean?
The wrong agent can be a disaster. It can make you miserable. If you're needy and you sign with an agent who hates neediness, then you're always going to feel terrible. If you know that somewhere down the line, you might want to try your hand at writing sci-fi or fantasy, but your current book is contemporary, then make sure you sign with an agent who is open to sci-fi and fantasy down the road. If you know that you're never going to want to change an idea once you've written it, then don't sign with an agent who is more editorial.
My point is this: writers spend too much time focused on the wrong things. We get so focused on finding the agent and selling the book that we don't take the time to find ourselves.
If you can be honest about who you are, then you'll have a better chance of finding the right agent. And you'll be happier too.
But you still have to write a kick-ass book. There's no getting around that.