Build AI Agents from First Principles