A template that works on your ten test cases and falls apart on the eleventh is not done. The point of a template is that it behaves the same way on inputs you have not seen.
Keep the fixed and the variable clearly apart. The instructions and structure are fixed. The retrieved material, the user input, and the running state are variable, and they should slot into named places rather than being glued into the sentence. When the two are tangled, a small change to the instructions quietly breaks how the variable parts render, and you find out in production.
Be explicit about what happens when a slot is empty. No retrieved documents, a first turn with no history, a tool that returned nothing: each of those is a real input, and a template that only reads well when every slot is full will produce something odd when one is not. Decide the empty-slot wording on purpose.
Version the templates and keep the old ones. When a metric moves, the first question is always whether the template changed, and you want to be able to answer it from a diff instead of from memory.