It must be in writing (as opposed to being an oral agreement), and be authorised by court. You must both attend the court hearing to authorise the agreement. The judge will only authorise the agreement and grant a judgment giving it full legal validity if he is satisfied that both of you signed it of your own free will, without any pressure/blackmail,and that you are aware of its contents,meaning and implications. He may question you about the agreement and will not authorise it unless he is completely satisfied about these issues.
An agreement between a married couple that is not authorised by court is not fully binding.