Update ai.js with smarter recursive degrading