How AI Agents Work: Perception, Reasoning & Action Loop