Factor out ai to its own namespace