I´m currently working in a model where the natural product in the Taylor rule is endogenous. This implies that the natural product vary over time and vary with several shocks. This natural product comes from solving the same model without nominal rigidities. My problem is that I don´t know how to solve for the natural product at the same time that I solve the main model. Should I solve for both models in the same mod file?

The output gap x=y-y^f is closed in steady state, but as shocks hit the economy, they will move actual output away from its flexible-price counterpart, thereby creating the output gap that the central bank in your model attempts to stabilize.

What you need to do is to write the equations of the sticky-price economy and append to them, within the same model file or by means of @#include “equations_of_flexecon.mod”, the equations of the flexible-price economy that are needed to pin down the flexible-price output.

A standard reference is always

and especially Appendix A therein.
For an example of an implementation in Dynare, have a look at

and see at line 290 what the central bank responds to.