An agent is your employee on commission. You hire him or her to sell one or more of your books to a publisher. If it earns nothing, the agent gets nothing. Your agent can not only sell your book to publishers but also sell subsidiary rights, such as audiotape, film rights, electronic distribution and adaptation rights, and foreign rights. All but the largest agencies work with other agencies while selling these rights.
Agencies come in many sizes, from one-person to large.
Smaller agencies tend to specialize in one kind or another of book, for example, trade fiction, mysteries, nonfiction, or children's books. Once upon a time, ten or twenty years ago, the theory went that a novice writer could send a book manuscript to an editor, who would read it, decide it was good, and buy it. The writer could either represent herself in contract negotiations or use the sale to get an agent. No more, because editors' jobs have changed. Your editor has much less time actually to edit your book.