Dev isn’t my strong suit, but there are often examples of how to do things in existing plugins. I think the Automation plugin has a script to add tags based on AI triage. Perhaps looking at that could be helpful?
In general, I’d also recommend including some more detail about what you’ve tried so far/how far you’ve got when asking for dev help. This can help provide context for any answers you might be hoping for.