How AI agents work — tool use, reasoning, planning, and building them.