DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(mastery): require explicit choice answer intent
Bingxi Zhao (Frank)852552783644
diff --git a/deeptutor/capabilities/mastery/choices.py b/deeptutor/capabilities/mastery/choices.pyindex a5273ab16..8b76086b5 100644--- a/deeptutor/capabilities/mastery/choices.py+++ b/deeptutor/capabilities/mastery/choices.py@@ -30,6 +30,7 @@ from deeptutor.learning.pending import (canonical_labels,format_options,has_option_bodies,+ is_readable_choice_answer,option_label_intent,parse_options,resolve_answer,@@ -91,6 +92,7 @@ __all__ = ["canonical_labels","format_options","has_option_bodies",+ "is_readable_choice_answer","option_label_intent","parse_options","recover_options_from_turn",diff --git a/deeptutor/learning/pending.py b/deeptutor/learning/pending.pyindex 68f0583fb..e4244cd84 100644--- a/deeptutor/learning/pending.py+++ b/deeptutor/learning/pending.py@@ -178,7 +178,41 @@ def is_readable_choice_answer(answer: str, options: list[str] | dict[str, str])option_map = parse_options(options) if isinstance(options, list) else optionsif not option_map:return False- return bool(resolve_choice_submission(answer, option_map))+ candidate = str(answer or "").strip()+ resolved = resolve_choice_submission(candidate, option_map)+ if not resolved:+ return False++ # Exact labels (optionally followed by declarative punctuation), labelled+ # answers, and exact option bodies are unambiguous without extra wording.+ if re.fullmatch(rf"{re.escape(resolved)}[。.!!]?", candidate, re.IGNORECASE):+ return True+ prefix_match = OPTION_PREFIX_RE.match(candidate)+ if prefix_match and prefix_match.group(1).upper() == resolved:+ return True+ if _squeezed(candidate) == _squeezed(option_map[resolved]):+ return True++ # Merely mentioning one label is not an answer. In particular, questions+ # such as "why is B wrong?" used to resolve to B and freeze the gate.+ if re.search(+ r"[??]|\b(?:why|what|how|can|could|would|explain)\b|"+ r"(?:为什么|为何|怎么|如何|什么|解释一下|请解释)",+ candidate,+ re.IGNORECASE,+ ):+ return False++ label = re.escape(resolved)+ return bool(+ re.search(+ rf"(?:\b(?:answer(?:\s+is)?|choose|pick|select|"+ rf"think(?:\s+it(?:'s|\s+is))?|go\s+with)\s*(?:option\s*)?{label}\b|"+ rf"(?:答案(?:是|为)?|我?选(?:择)?|应该是|我觉得是)\s*{label})",+ candidate,+ re.IGNORECASE,+ )+ )@dataclass(frozen=True, slots=True)diff --git a/deeptutor/learning/service.py b/deeptutor/learning/service.pyindex 09bfb43c8..ee4f57080 100644--- a/deeptutor/learning/service.py+++ b/deeptutor/learning/service.py@@ -478,10 +478,9 @@ class LearningService:stored = str(interaction.user_answer or "")incoming = str(answer or "")- if (- not is_readable_choice_answer(stored, interaction.question.options)- and is_readable_choice_answer(incoming, interaction.question.options)- ):+ if not is_readable_choice_answer(+ stored, interaction.question.options+ ) and is_readable_choice_answer(incoming, interaction.question.options):interaction.user_answer = incominginteraction.session_id = session_id or interaction.session_idinteraction.turn_id = turn_id or interaction.turn_iddiff --git a/deeptutor/learning/tests/test_mastery_choices.py b/deeptutor/learning/tests/test_mastery_choices.pyindex 27876dbff..3e869e66b 100644--- a/deeptutor/learning/tests/test_mastery_choices.py+++ b/deeptutor/learning/tests/test_mastery_choices.py@@ -13,6 +13,7 @@ from deeptutor.capabilities.mastery.choices import (canonical_labels,format_options,has_option_bodies,+ is_readable_choice_answer,option_label_intent,parse_options,recover_options_from_turn,@@ -178,6 +179,18 @@ def test_resolve_choice_submission_refuses_an_ambiguous_answer():assert resolve_choice_submission("", options) == ""+def test_readable_choice_answer_requires_selection_intent_not_a_label_mention():+ options = {"A": "first", "B": "second", "C": "third"}+ assert is_readable_choice_answer("B", options)+ assert is_readable_choice_answer("选B", options)+ assert is_readable_choice_answer("答案是 C", options)+ assert is_readable_choice_answer("I think it's A", options)+ assert is_readable_choice_answer("second", options)+ assert not is_readable_choice_answer("为什么 B 不对?", options)+ assert not is_readable_choice_answer("Can you explain B", options)+ assert not is_readable_choice_answer("B or C", options)++# ── recover_options_from_turn ────────────────────────────────────────────────diff --git a/tests/capabilities/test_mastery_capability.py b/tests/capabilities/test_mastery_capability.pyindex e01e08bfa..0bdd120b1 100644--- a/tests/capabilities/test_mastery_capability.py+++ b/tests/capabilities/test_mastery_capability.py@@ -193,7 +193,7 @@ async def test_choice_clarifying_composer_text_does_not_commit_answer(tmp_path,await capability.on_user_resume(_context(),ask_user,- reply_text="先告诉我三角恒等式是什么?",+ reply_text="为什么 B 不是正确答案?",answers=None,)@@ -226,9 +226,7 @@ async def test_choice_composer_option_label_still_commits(tmp_path, monkeypatch)capability = MasteryLoopCapability()await capability.on_user_pause(_context(), ask_user)- await capability.on_user_resume(- _context(), ask_user, reply_text="选B", answers=None- )+ await capability.on_user_resume(_context(), ask_user, reply_text="选B", answers=None)answered = LearningStore().get_interaction("path-1", "stable-question")assert answered is not None