Sholom,
There are two ways to do a 1031 Exchange. It would be a good idea to read this code section.
First way is the new way: property is sold, Intermediary holds the your proceeds money. You have 45 days to identify your target property or properties. You have 180 days to close on your target property/properties.
Second way is the old way. This is the way many Millerites use. They simply trade deeds.
As to the agent getting paid: The seller has a contract with the realtor. The seller is responsible for paying the realtor’s commission. With a 1031, more than likely an amount will need to be discussed and agreed to ahead of time.
Hope this helps.
Bill Cook