In order for a contract to be legally enforceable, there has to be three elements: 1) an offer has to be made by one party and accepted by the other party; 2) the agreement must be in writing (verbal agreements are not enforceable), and 3) something in consideration (which means the parties to the contract must receive something of value in exchange for agreeing to the terms. (That's one of the reasons why you are required to put a deposit down on the house you want to buy). While I'm not an attorney and am not dispensing legal advice, you should check with an attorney to be sure.
Agents do expect to be paid for their services. How a buyer's agent is paid is typically from the seller of the house you want to buy, and that which is made through the listing agent. Most if not all agents will want you to agree to use them to help you find a home in exchange for providing listings, dispensing advice, and shuffling you from listing to listing.
If you decide to make an offer on a house, and it's accepted by the seller, and the house is subsequently sold to you, the agent who first brought you to that house (typically within a limited time) is the one who is entitled to the commission.