I had a similar (but less sophisticated) question recently and the responses to that could be helpful: How to estimate a parameter for use in another model in brms?.
Particularly the Stan code that @andrjohns shared. The key point was considering the two sub-models as part of one hierarchical model and fitting each within the same Markov chain.