import re from agents.variants.base import TeacherVariant _BOX = re.compile(r"\\boxed\{(.+?)\}", re.S) class P4(TeacherVariant): """Answer-only extreme (lower bracket): the reference slot is a single answer line built from the reference's boxed answer. Maker-free (no endpoint), no thinking, no accept gate. P4 vs P2 prices whether branch-(b) localization pays.""" name = "p4_answer_only" description = "reference slot = one answer line; maker-free, no thinking" thinking = False uses_maker = False def _answer(self, solution): found = _BOX.findall(solution or "") return found[-1].strip() if found else (solution or "").strip() def resolve_prefix(self, problem, solution, rollout, maker_client): tmpl = self.prompts.get("answer_only_template", "The correct final answer is \\boxed{}.") return tmpl.replace("", self._answer(solution)) def accepts(self, prefix, reference): return True # a maker-free line; nothing to gate VARIANT = P4