DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(mastery): stop sending the tutor back to quiz a gate no quiz can clear
Bingxi Zhao (Frank)10f643dafeba
diff --git a/deeptutor/capabilities/mastery/tools.py b/deeptutor/capabilities/mastery/tools.pyindex d6cda54e5..d6477cbec 100644--- a/deeptutor/capabilities/mastery/tools.py+++ b/deeptutor/capabilities/mastery/tools.py@@ -63,6 +63,7 @@ from deeptutor.learning.policy import (QUALITATIVE_TYPES,display_mastery,find_knowledge_point,+ gate_kind,gate_threshold,is_mastered,map_summary,@@ -1069,6 +1070,32 @@ class MasteryGradeTool(BaseTool):section_title=kp.name if kp else "",)mastered = bool(kp and is_mastered(progress, kp))+ gate = gate_kind(kp) if kp else ""+ # What to do after the verdict. A qualitative objective needs its own+ # branch: quiz accuracy lands in ``mastery_levels`` without moving that+ # gate — it can even read a full 1.0 against a 1.0 threshold while+ # ``mastered`` stays false — so telling the model to pose another+ # question here is telling it to loop forever on an objective no+ # question can clear. That loop is invisible from the chat, where the+ # tutor narrates progress it never actually recorded, and visible on+ # the outline rail, which correctly never moves.+ if mastered:+ next_move = "going: this objective is mastered, so continue with mastery_status.next."+ elif gate == "qualitative":+ next_move = (+ "going on the same objective — but this one is gated "+ "qualitatively, so more questions cannot clear it however many "+ "the learner gets right. Teach the gap this attempt exposed, "+ "then ask them to explain the idea in their own words and "+ "record your judgement with mastery_assess. That call is the "+ "only thing that opens this gate."+ )+ else:+ next_move = (+ "going on the same objective — teach the gap this attempt "+ "exposed, and when you pose the next question with "+ "mastery_quiz put that call last, since it ends the turn."+ )payload = {"is_correct": is_correct,"replayed": replayed,@@ -1077,6 +1104,10 @@ class MasteryGradeTool(BaseTool):"question_id": pending.question_id,"mastery": round(display_mastery(progress, kp), 3) if kp else 0.0,"threshold": round(gate_threshold(kp.type), 3) if kp else 0.0,+ # Which gate that number is being read against. Without it a+ # qualitative objective reports mastery 1.0 / threshold 1.0 /+ # mastered false, which is not a reading anyone can act on.+ "gate": gate,"mastered": mastered,"next": next_objective(progress).to_dict(),# The answer key, released to the learner's card now that the gate@@ -1097,13 +1128,7 @@ class MasteryGradeTool(BaseTool):"The card now shows the verdict, the correct option and your ""explanation, so do not restate the answer key. Say what this ""attempt tells you about their grasp of the objective, then keep "- + (- "going: this objective is mastered, so continue with mastery_status.next."- if mastered- else "going on the same objective — teach the gap this "- "attempt exposed, and when you pose the next question with "- "mastery_quiz put that call last, since it ends the turn."- )+ + next_move+ " Never end the turn without saying anything."),}diff --git a/deeptutor/learning/policy.py b/deeptutor/learning/policy.pyindex 67784d725..453953e49 100644--- a/deeptutor/learning/policy.py+++ b/deeptutor/learning/policy.py@@ -199,7 +199,14 @@ def find_knowledge_point(return None, "", ""-def _gate_kind(kp: KnowledgePoint) -> str:+def gate_kind(kp: KnowledgePoint) -> str:+ """Which gate ``kp`` has to clear — ``qualitative`` or ``quantitative``.++ Public because the tutor's tools report it too: a quiz attempt on a+ qualitative objective moves ``mastery_levels`` without moving the gate,+ so every surface that shows a mastery number has to be able to say which+ kind of gate that number is being read against.+ """return "qualitative" if kp.type in QUALITATIVE_TYPES else "quantitative"@@ -228,7 +235,7 @@ def next_objective(knowledge_point_name=kp.name if kp else "",knowledge_point_type=kp.type.value if kp else "",status=objective_status(progress, kp) if kp else "learning",- gate=_gate_kind(kp) if kp else "",+ gate=gate_kind(kp) if kp else "",mastery=display_mastery(progress, kp) if kp else 0.0,threshold=gate_threshold(kp.type) if kp else 0.0,reason="A posed question is awaiting the learner's answer; grade it with mastery_grade.",@@ -249,7 +256,7 @@ def next_objective(knowledge_point_name=kp.name,knowledge_point_type=kp.type.value,status=objective_status(progress, kp),- gate=_gate_kind(kp),+ gate=gate_kind(kp),mastery=display_mastery(progress, kp),threshold=gate_threshold(kp.type),reason="This objective is due for spaced-repetition review.",@@ -260,7 +267,7 @@ def next_objective(if is_mastered(progress, kp):continuestatus = objective_status(progress, kp)- gate = _gate_kind(kp)+ gate = gate_kind(kp)if status == "new":action = "probe"elif gate == "qualitative":@@ -374,7 +381,7 @@ def objective_report(progress: LearningProgress, kp_id: str) -> dict | None:"module_id": module_id,"module_name": module_name,"status": objective_status(progress, kp),- "gate": _gate_kind(kp),+ "gate": gate_kind(kp),"mastered": is_mastered(progress, kp),"assessed_mastered": is_assessed_mastered(progress, kp),"mastery_source": mastery_source(progress, kp),@@ -418,6 +425,7 @@ __all__ = ["QUANTITATIVE_GATE","QUALITATIVE_TYPES","NextStep",+ "gate_kind","gate_threshold","is_assessed_mastered","is_mastered",diff --git a/deeptutor/learning/tests/test_mastery_tools.py b/deeptutor/learning/tests/test_mastery_tools.pyindex fc4d72499..9b36c8b0a 100644--- a/deeptutor/learning/tests/test_mastery_tools.py+++ b/deeptutor/learning/tests/test_mastery_tools.py@@ -233,6 +233,74 @@ async def test_quiz_then_grade_drives_memory_gate(path_id):assert mastered is True+async def test_grade_on_a_qualitative_objective_sends_the_tutor_to_assess(path_id):+ """A concept objective cannot be cleared by questions, and grading says so.++ Quiz accuracy lands in ``mastery_levels`` whatever the objective's type,+ but the qualitative gate reads ``qualitative_mastery`` — which only+ ``mastery_assess`` writes. Grading used to answer a correct attempt here by+ telling the tutor to pose the next question, which is an instruction to+ loop forever on an objective no question can clear: the conversation+ narrates progress while the outline rail, correctly, never moves.+ """+ build = json.loads((await _build_basic(path_id)).content)+ points = build["map"]["modules"][0]["knowledge_points"]+ concept_id = next(p["id"] for p in points if p["type"] == "concept")++ quiz, grade = MasteryQuizTool(), MasteryGradeTool()+ for _ in range(3):+ await quiz.execute(+ _mastery_path_id=path_id,+ knowledge_point_id=concept_id,+ question="Why does XOR matter?",+ expected_answer="it is not linearly separable",+ question_type="short",+ )+ payload = json.loads(+ (+ await grade.execute(_mastery_path_id=path_id, answer="it is not linearly separable")+ ).content+ )+ assert payload["is_correct"] is True++ # Three correct answers and the gate is still shut — by design, not by bug.+ assert payload["mastered"] is False+ assert payload["gate"] == "qualitative"+ # Which is only an interpretable reading next to the gate it is read+ # against: on its own, mastery 1.0 against threshold 1.0 says "cleared".+ assert payload["mastery"] == payload["threshold"] == 1.0+ # ``next`` is the path-wide cursor, not a verdict on the objective just+ # graded — here it still points at the untouched memory objective ahead of+ # this one. Which is exactly why the instruction has to carry the way+ # forward for *this* objective itself.+ assert payload["next"]["knowledge_point_id"] != concept_id+ assert "mastery_assess" in payload["instruction"]+ assert "mastery_quiz" not in payload["instruction"]+++async def test_grade_below_a_quantitative_gate_still_asks_for_another_question(path_id):+ """The quantitative branch is unchanged — there, more questions do clear it."""+ await _build_basic(path_id)+ status = json.loads((await MasteryStatusTool().execute(_mastery_path_id=path_id)).content)+ kp_id = status["next"]["knowledge_point_id"]+ await MasteryQuizTool().execute(+ _mastery_path_id=path_id,+ knowledge_point_id=kp_id,+ question="2+2?",+ expected_answer="4",+ question_type="short",+ )+ payload = json.loads(+ (await MasteryGradeTool().execute(_mastery_path_id=path_id, answer="4")).content+ )+ assert payload["mastered"] is False # 0.5 is below the 0.9 gate+ assert payload["gate"] == "quantitative"+ assert "mastery_quiz" in payload["instruction"]+ assert "mastery_assess" not in payload["instruction"]++@pytest.mark.asyncioasync def test_grade_without_pending_fails(path_id):await _build_basic(path_id)