In most real estate transactions and there are two agents or brokerages involved. A broker is the overseeing head broker that may have several agents underneath that broker but all of those agents are doing business as that broker, technically signing their name as a representative of that broker. You can have multiple agents on one transaction from the same broker, but more often than not, you'll have two agents from two different brokers on a single real estate transaction.
These two agents are typically the listing agent hired by the seller or homeowner and the buyers agent hired by the homebuyer.
When a homeowner or real estate seller enlists the help of a real estate agent or brokerage to sell their house they negotiate the terms of the contract. Typically, listing agents are given six months to sell a particular property. They discuss the terms of negotiations, marketing, and communication and also how much commission the agent or agents will receive once the house sells. The commission is based on the selling price, not the asking price so if the property sells for $10,000 less, the commission is based on the lower amount rather than the original asking price. If the asking price drops substantially after months on the market, the agent will still get paid once the home sells as long as it still within the contracts timeframe but the commission will be based on the sale price not the original asking price.
The listing agent contract will specify a percentage of that sale price, typically 6%. It's common to split this commission percentage in half between the buyers agent and the listing agent. The listing agent is responsible for listing the property on the MLS, paying for marketing materials, and providing open houses at the seller's request. A buyers agent brings the buyer and helps facilitate the negotiations between the seller and the buyer and will receive half the commission upon the closing of the property.
Technically, the seller pays the buyers agent and the listing agent out of the proceeds of the profits once the sale is complete. One can consider it almost a wash because the buyer is paying the seller for the property and then the seller in turn is paying that money towards both agents involved in the transaction for their work. But, the buyer doesn't need to come up with an additional 3% to pay their agent for helping them close the deal. A buyers agent works only for the buyer and not the seller of anyone particular property until the buyer chooses that home. The buyer representation should not steer the buyer toward one home or another but help facilitate the transaction, negotiate on behalf of the buyer, and look out for the buyers best interest throughout which ever home purchase the buyer decides on.
"Occasionally, the listing agent can also act as the buyers agent but this gets a little tricky and can muddy the waters. The listing agent's first priority and responsibility is to the seller, not the buyer so it can cause a conflict of interest if the same agent is handling both sides of the transaction. This is called dual agency and as you guessed it, the listing agent will receive all 6% of the commission. It's a fun position to be in for the listing agent but can also be tricky since the listing agent worked for the seller first and the buyer second. The buyer will probably not be represented accurately because the listing agent's sole responsibility and goal is to sell that property." - Sydney Buyers Agent
But, in the end, it's the responsibility of the seller to pay the commission to the buyer's agent once the deal closes as long as the buyers agent has brought a willing and able buyer to the table and the deal has closed.