This was my process of getting an agent, but it's not the definitive way!
1: Finish your manuscript!
To query you need a finished, POLISHED manuscript. And by polished I mean as close to perfect as you can get it. The first time I ever sent out query letters I fell victim to sending my manuscript off too early when it was little more than a second draft. The agents who were kind enough to reply told me that I needed to revise heavily and polish it further. I took their advice and set aside a few months to edit it from top to bottom. I put out a post on Tumblr asking for beta readers and they helped clean up my manuscript and point out errors that my eyes have become used to seeing and skimmed over.
2. Make a list of literary agents!
I researched a list of one hundred agents that represented my genre and age and added them to a spreadsheet. The way I found them was through searching the #MSWL tag on Twitter with a few keywords relating to my book (YA fantasy, witches, magic) and writing them down. It's best to put effort into this and to make sure they aren't fake agents or scams. This is a great video on the topic of agents to avoid.
3. Write your synopsis and query letter!
These too need to be polished to perfection as these are what convince the agent whether they should read your book or pass it. You'll need a synopsis (no more than two pages and including spoilers), a pitch/blurb (a shorter, snappier version of the synopsis; about a paragraph), sample pages (generally 50 pages or first 3 chapters), and your credentials/bio (if you've ever published before, relevant degrees, social media numbers, etc.). Make sure to personalize your query letter for each agent, specifying why you're submitting to them and why you think they'd be a good fit for your book.
4. Test out a batch of five or ten agents!
Send out this query letter to 5-10 agents and wait for the response. If you receive form rejections or no responses then it may be a sign you need to edit your query letter. Add them to your spreadsheet and their response.
5. Send out another batch until you start receiving some requests!
You know your query letter is working when you start receiving requests, either full manuscript or partials. This is incredibly exciting and is a good sign you're on the right path. Send your full or partial to agents who have requested it and now comes the agonizing process of waiting for their answer.
6. Success! An agent has offered you representation!
Freak out a bit! Jump up and down! And then get back to work. Arrange a meeting with them via phone or Zoom to discuss their offer, ask to see their boilerplate (a standard contract), and contact all the other agents who you've submitted to and tell them you've received an offer. It's the polite thing to do as they might withdraw and pass or even offer you a counter offer! If you have more than one offer, you have the task of comparing and contrasting, and deciding which agent fits best with your work and will represent it the best.
7. Make your final decision and celebrate!
When all was settled and I had made my decision, I got to release a public statement on my Twitter that I was now represented. Then I cracked open a small cheap bottle of champagne from the supermarket since I'd never had it before (tbh didn't enjoy it that much but success made it bearable).