Nico Bailon (author of many extensions for Mario's Pi coding agent) has something that might be a good starting point for this:
https://x.com/i/status/2043054831947198640
https://github.com/nicobailon/pi-model-switch