DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
Block 5+6: DELETE/redo endpoints, change_module WS, LLM progress hints
whffb7787b089c6
diff --git a/deeptutor/api/routers/guided_learning.py b/deeptutor/api/routers/guided_learning.pyindex e33b0f9cb..165ffde53 100644--- a/deeptutor/api/routers/guided_learning.py+++ b/deeptutor/api/routers/guided_learning.py@@ -6,7 +6,13 @@ from fastapi import APIRouter, HTTPExceptionfrom pydantic import BaseModelfrom pydantic import ValidationError as PydanticValidationError-from deeptutor.learning.models import ErrorType, KnowledgePoint, LearningModule, QuizAttempt+from deeptutor.learning.models import (+ ErrorType,+ KnowledgePoint,+ LearningModule,+ LearningStage,+ QuizAttempt,+)from deeptutor.learning.scheduler import SpacedRepetitionSchedulerfrom deeptutor.learning.service import LearningServicefrom deeptutor.learning.storage import LearningStore@@ -182,3 +188,39 @@ async def init_modules(book_id: str, body: InitModulesRequest):# use the merge logic in LearningService.init_modules() which preserves position.service.save(progress)return {"status": "ok", "module_count": len(modules)}++[email protected]("/progress/{book_id}")+async def delete_progress(book_id: str):+ if not book_id or ".." in book_id or "/" in book_id or "\\" in book_id or ":" in book_id:+ raise HTTPException(status_code=400, detail="Invalid book_id")+ store = LearningStore()+ if not store.exists(book_id):+ raise HTTPException(status_code=404, detail="Progress not found")+ store.delete(book_id)+ return {"status": "ok"}++[email protected]("/progress/{book_id}/redo")+async def redo_progress(book_id: str):+ if not book_id or ".." in book_id or "/" in book_id or "\\" in book_id or ":" in book_id:+ raise HTTPException(status_code=400, detail="Invalid book_id")+ store = LearningStore()+ progress = store.load(book_id)+ if progress is None:+ raise HTTPException(status_code=404, detail="Progress not found")+ progress.current_stage = LearningStage.DIAGNOSTIC_PHASE1+ progress.mastery_levels = {}+ progress.quiz_attempts = []+ progress.error_records = []+ progress.repetition_states = {}+ progress.review_queue = []+ progress.diagnostic = None+ progress.current_kp_index = 0+ progress.current_module_id = progress.modules[0].id if progress.modules else ""+ store.save(progress)+ # Clear stored question answers so fresh questions are generated on redo+ qpath = store._questions_path(book_id)+ if qpath.exists():+ qpath.unlink()+ return {"status": "ok"}diff --git a/deeptutor/api/routers/unified_ws.py b/deeptutor/api/routers/unified_ws.pyindex 77fa3a91a..524fb82c6 100644--- a/deeptutor/api/routers/unified_ws.py+++ b/deeptutor/api/routers/unified_ws.py@@ -238,6 +238,26 @@ async def unified_websocket(ws: WebSocket) -> None:bus.submit_input(str(msg.get("content") or ""))continue+ if msg_type == "change_module":+ session_id = str(msg.get("session_id") or "").strip()+ module_id = str(msg.get("module_id") or "").strip()+ if not session_id or not module_id:+ await safe_send({"type": "error", "content": "Missing session_id or module_id for change_module."})+ continue+ from deeptutor.learning.service import LearningService+ from deeptutor.learning.storage import LearningStore++ store = LearningStore()+ service = LearningService(store)+ progress = service.get_or_create(session_id)+ found = any(m.id == module_id for m in progress.modules)+ if found:+ progress.current_module_id = module_id+ progress.current_kp_index = 0+ service.save(progress)+ await safe_send({"type": "module_changed", "module_id": module_id, "success": found})+ continue+await safe_send({"type": "error", "content": f"Unknown type: {msg_type}"})except WebSocketDisconnect:diff --git a/deeptutor/capabilities/guided_learning.py b/deeptutor/capabilities/guided_learning.pyindex 9cb27ca67..4e0899b8a 100644--- a/deeptutor/capabilities/guided_learning.py+++ b/deeptutor/capabilities/guided_learning.py@@ -230,6 +230,7 @@ class GuidedLearningCapability(BaseCapability):self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus) -> None:async with stream.stage("diagnostic_phase1", source=self.manifest.name):+ await stream.content("正在生成诊断题...", source=self.manifest.name)response = await self._call_llm(DIAGNOSTIC_PHASE1_SYSTEM, DIAGNOSTIC_PHASE1_USER)data = self._safe_json_parse(response, default={"questions": [], "answers": []})book_id = self._resolve_book_id(context)@@ -274,6 +275,7 @@ class GuidedLearningCapability(BaseCapability):self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus) -> None:async with stream.stage("diagnostic_phase2", source=self.manifest.name):+ await stream.content("正在生成深度诊断题...", source=self.manifest.name)response = await self._call_llm(DIAGNOSTIC_PHASE2_SYSTEM, DIAGNOSTIC_PHASE2_USER)data = self._safe_json_parse(response, default={})book_id = self._resolve_book_id(context)@@ -316,6 +318,7 @@ class GuidedLearningCapability(BaseCapability):self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus) -> None:async with stream.stage("metacognitive_intro", source=self.manifest.name):+ await stream.content("正在生成元认知介绍...", source=self.manifest.name)response = await self._call_llm(METACOGNITIVE_SYSTEM, METACOGNITIVE_USER)await stream.content(response)self._service.advance_stage(progress, LearningStage.PLAN)@@ -336,6 +339,7 @@ class GuidedLearningCapability(BaseCapability):# knowledge-point lists via the "_current_kp_name" fallback.self._service.advance_stage(progress, LearningStage.PRETEST)return+ await stream.content("正在生成学习计划...", source=self.manifest.name)response = await self._call_llm(PLAN_SYSTEM, PLAN_USER)await stream.content(response)self._service.advance_stage(progress, LearningStage.PRETEST)@@ -357,6 +361,7 @@ class GuidedLearningCapability(BaseCapability):self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus) -> None:async with stream.stage("pretest", source=self.manifest.name):+ await stream.content("正在生成预测试题...", source=self.manifest.name)response = await self._call_llm(PRETEST_SYSTEM, PRETEST_USER.format(knowledge_point=self._current_kp_name(progress)))@@ -367,6 +372,7 @@ class GuidedLearningCapability(BaseCapability):self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus) -> None:async with stream.stage("explain", source=self.manifest.name):+ await stream.content("正在生成讲解内容...", source=self.manifest.name)response = await self._call_llm(EXPLAIN_SYSTEM, EXPLAIN_USER.format(knowledge_point=self._current_kp_name(progress)))@@ -393,6 +399,7 @@ class GuidedLearningCapability(BaseCapability):self._service.advance_stage(progress, LearningStage.PRACTICE_QUIZ)return+ await stream.content("正在评估你的解释...", source=self.manifest.name)response = await self._call_llm(FEYNMAN_SYSTEM,FEYNMAN_USER.format(knowledge_point=kp_name) + f"\n学生解释:{user_explanation}",@@ -444,6 +451,7 @@ class GuidedLearningCapability(BaseCapability):kp_names = ", ".join(kp.name for kp in kps)prefix = f"{progress.current_module_id}_pquiz" if progress.current_module_id else "pquiz"+ await stream.content("正在生成练习测验...", source=self.manifest.name)response = await self._call_llm(PRACTICE_QUIZ_SYSTEM,PRACTICE_QUIZ_USER.format(knowledge_points=kp_names),@@ -502,6 +510,7 @@ class GuidedLearningCapability(BaseCapability):) -> None:async with stream.stage("practice", source=self.manifest.name):prefix = f"{progress.current_module_id}_practice" if progress.current_module_id else "practice"+ await stream.content("正在生成练习题...", source=self.manifest.name)response = await self._call_llm(PRACTICE_SYSTEM, PRACTICE_USER.format(module_name=self._current_module_name(progress)))@@ -543,6 +552,7 @@ class GuidedLearningCapability(BaseCapability):self, progress: LearningProgress, context: UnifiedContext, stream: StreamBus) -> None:async with stream.stage("error_diagnosis", source=self.manifest.name):+ await stream.content("正在生成错误诊断...", source=self.manifest.name)response = await self._call_llm(ERROR_DIAGNOSIS_SYSTEM, ERROR_DIAGNOSIS_USER)await stream.content(response)self._service.advance_stage(progress, LearningStage.MODULE_TEST)@@ -552,6 +562,7 @@ class GuidedLearningCapability(BaseCapability):) -> None:async with stream.stage("module_test", source=self.manifest.name):prefix = f"{progress.current_module_id}_modtest" if progress.current_module_id else "modtest"+ await stream.content("正在生成模块测试...", source=self.manifest.name)response = await self._call_llm(MODULE_TEST_SYSTEM, MODULE_TEST_USER.format(module_name=self._current_module_name(progress)))@@ -598,6 +609,7 @@ class GuidedLearningCapability(BaseCapability):async with stream.stage("review", source=self.manifest.name):self._init_repetition_states(progress)self._schedule_reviews(progress)+ await stream.content("正在生成复习内容...", source=self.manifest.name)response = await self._call_llm(REVIEW_SYSTEM, REVIEW_USER)await stream.content(response)if self._advance_to_next_module(progress):diff --git a/deeptutor/learning/storage.py b/deeptutor/learning/storage.pyindex 559057fce..9c56eeef5 100644--- a/deeptutor/learning/storage.py+++ b/deeptutor/learning/storage.py@@ -46,6 +46,9 @@ class LearningStore:path = self._path(book_id)if path.exists():path.unlink()+ qpath = self._questions_path(book_id)+ if qpath.exists():+ qpath.unlink()def exists(self, book_id: str) -> bool:return self._path(book_id).exists()diff --git a/web/app/(workspace)/learning/[bookId]/page.tsx b/web/app/(workspace)/learning/[bookId]/page.tsxindex 5113861fc..cb59174d6 100644--- a/web/app/(workspace)/learning/[bookId]/page.tsx+++ b/web/app/(workspace)/learning/[bookId]/page.tsx@@ -59,9 +59,9 @@ export default function LearningBookPage() {if (wsRef.current?.readyState === WebSocket.OPEN) {wsRef.current.send(JSON.stringify({type: "change_module",+ session_id: params.bookId,module_id: moduleId,}));- setCurrentModuleId(moduleId);}}, [currentModuleId]);@@ -140,6 +140,13 @@ export default function LearningBookPage() {setInputPrompt(evt.content || "Please enter your answer");return;}+ if (evt.type === "module_changed") {+ const e = evt as Record<string, unknown>;+ if (e.success !== false) {+ setCurrentModuleId(typeof e.module_id === "string" ? e.module_id : "");+ }+ return;+ }if (evt.type === "stage_start") {currentStageRef.current = evt.stage;setCurrentStage(evt.stage);