See how AI agents work: the think, act, observe loop, memory, planning, and where agents go wrong. With a worked example.