SRD said:
If uncommanded, a golem usually follows its last instruction to the best of its ability, though if attacked it returns the attack. The creator can give the golem a simple command to govern its actions in his or her absence.
According to the SRD the creator can give the golem only ONE command, and it must be SIMPLE as well. So, giving golems complicated pre-programming, while feasible, does not seem covered by the rules.
I do feel something for Lord Pendragon's argument that Golem's are at least created possessing some basic knowledge of the world, otherwise they could not even follow Piratecat's instructions "Do not attack any creature that appears in this room without entering through the doorway", because the golem would not understand the exact meaning of creature, entering, doorway etc.
All creatures, doorways, rooms are different, and the golem has to have some basic mental schemata of what constitutes a dooway, a room or a creature.
I think giving it the ability to differentiate between summoned and real creatures or spellcasters and non-spellcasters is a bit too much for the golem's preprogrammed instruction set, however. I suppose it is best to treat it as if it had the knowledge of something with animal intelligence. Able to recognize most creatures and objects, but not built to decide if that painting really is a Rembrandt, even if its creator is a master of arts.