Look at how the melee AI is constructed. You basically need to make sure the build requirements flag is enabled and then order them to stock at least the desired number of that unit periodically. Unit stock orders have to be refreshed periodically (every 30-60 seconds) as well since the AI may forget them. If some units have particularly complex requirements it may not be possible for the AI to infer what must be done so one will either have to order they be stocked explicitly, or even design custom AI logic to help them meet the requirements.
For a simple AI a good idea is to design your stocking logic into different tiers. Tiers are advanced once certain requirements are met, such as building availability or game time. One can separate the base stocking and army stocking logic as usually a common base allows for many different army compositions that should be chosen dynamically based on the enemy composition, but this is a more advanced AI feature.