Have you seen these docs?
https://dev.px4.io/en/concept/architecture.html
There is also a library for Flight Tasks which should allow you to add your flight task on a high level. The mode change itself is a bit tricky because it involves communicating that mode via either RC or MAVLink. For now I would suggest, as a hack, that you add your Flight Task and then use a parameter to enable it for you instead of another mode.