How to use tooling api to inject a function?

I’m working with an Android project for a custom CI solution and used tooling api to gather tasks and execute builds. Next I tried using gradle api library to register so I may be able to use the ModelBuilder and get the AndroidModel for build flavors. But doesn’t look like this is the tooling api’s objective. Is there another way I can achieve this?

Thank you.