At the start of the story in Genesis 18, Abraham does not seem to know who the three men are:
Looking up, he saw three men standing near him. As soon as he saw them, he ran from the entrance of the tent to greet them and, bowing to the ground, he said, “My lords, if it please you, do not go on past your servant. Let a little water be brought; bathe your feet and recline under the tree. And let me fetch a morsel of bread that you may refresh yourselves; then go on—seeing that you have come your servant’s way.” They replied, “Do as you have said.”—Genesis 18:2-5 (NJPS)
(Abraham seems to recognize the men as important somehow as he treats them as honored guests, but it's not clear he considers any of them as God Himself.)
When the two angels have left for Sodom, Abraham seems to have identified the third as the Lord:
Abraham came forward and said, “Will You sweep away the innocent along with the guilty? What if there should be fifty innocent within the city; will You then wipe out the place and not forgive it for the sake of the innocent fifty who are in it? Far be it from You to do such a thing, to bring death upon the innocent as well as the guilty, so that innocent and guilty fare alike. Far be it from You! Shall not the Judge of all the earth deal justly?”—Genesis 18:23-25 (NJPS)
What tipped Abraham off?