In the PCC macros folder of the OPL, there is contextForm.pl:
https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/macros/PCC/contextForm.pl
You could try this. After loading this macro library file, then try:
Context("Form");
Context()->variables->are(x=>'Real',y=>'Real');
$answer = Formula("3x^2+xy+x");
If that does not behave as desired, let me know the details, and I may be able to suggest one or two more lines to make it work.