You could try using Power Automate to do this, but honestly, it might just be quicker to disable all those agents manually. If there are a ton of agents and HelpDesk sites, it would make sense, but otherwise it won't worth the effort.
The easier option is just to go into the HelpDesk instance, head to the 'Contacts' list, and sort the data by 'Agent' role. From there, go to the grid view and switch the role from Agent to Member for all agents.