fix(mastery): stream localized lesson preparation progress (#1902)

This commit is contained in:
Bingxi Zhao (Frank)
2026-10-19 03:29:21 +08:00
parent df7621d3ac
commit c49d130d5c
6 changed files with 65 additions and 15 deletions

View File

@@ -398,6 +398,7 @@ class MasteryLoopCapability:
# request, not a model-supplied claim about their intention.
updated["_learner_message"] = context.user_message or ""
if tool_name == "mastery_prepare_lesson":
updated["_language"] = context.language
from deeptutor.learning.policy import next_objective
from deeptutor.learning.storage import LearningStore

View File

@@ -7,6 +7,12 @@
# inherited from chat's pack (see MasteryLoopPipeline.prompt_base_module);
# only what genuinely belongs to the tutor is overridden here.
preparation:
checking_sources: Checking selected lesson sources and page references
finding_sources: Finding sources for this teaching step
checking_pages: Checking original pages and figures
repairing: Resolving a missing or unreadable detail with one targeted retry
general: |-
You are the learner's one-on-one mastery tutor.
They work through an outline of objectives, each behind a HARD mastery gate: an objective counts as mastered once its gate clears, and you do not move on until it does.

View File

@@ -6,6 +6,12 @@
# 提示词包兜底(见 MasteryLoopPipeline.prompt_base_module),这里只覆盖真正
# 属于导师的部分。
preparation:
checking_sources: 正在检查已选课程资料和页码
finding_sources: 正在为本次教学查找资料
checking_pages: 正在检查原始页面和图表
repairing: 正在对缺失或难以辨认的细节进行一次针对性重试
general: |-
你是学习者的一对一掌握式导师。
他沿着一份精通大纲前进,大纲里每个知识点后面都有一道硬性掌握门槛:门槛过了,这个知识点才算掌握;没过,就不推进到下一个。

View File

@@ -3790,11 +3790,15 @@ class MasteryPrepareLessonTool(BaseTool):
if not path_id:
return _no_path_result()
try:
from deeptutor.runtime.stream_bus import get_bus
evidence = await prepare_lesson(
service.store,
path_id,
str(kwargs.get("knowledge_point_id") or ""),
get_llm_config(),
stream=get_bus(_resolve_turn_id(kwargs)),
language=kwargs.get("_language") or "en",
focus=kwargs.get("focus") or "",
learner_request=str(kwargs.get("_learner_message") or "")[:1500],
refresh=kwargs.get("refresh", False),

View File

@@ -579,15 +579,28 @@ async def prepare_lesson(
config: Any,
stream: Any = None,
*,
language: str = "en",
focus: str = "",
learner_request: str = "",
refresh: bool = False,
) -> dict[str, Any]:
"""No write transaction is held across retrieval or model calls."""
from deeptutor.services.llm.capabilities import supports_vision
from deeptutor.services.prompt import get_prompt_manager
from deeptutor.services.prompt.lookup import prompt_text
from deeptutor.services.rag.pipelines.llamaindex.pipeline import LlamaIndexPipeline
from deeptutor.services.workspace.knowledge import learning_source_access
prompts = get_prompt_manager().load_prompts("mastery", "mastery_loop", language)
async def status(key: str) -> None:
if stream is not None:
await stream.progress(
prompt_text(prompts, ("preparation", key)),
source="mastery_path",
stage="responding",
)
if (
not isinstance(focus, str)
or len(focus) > 800
@@ -614,12 +627,7 @@ async def prepare_lesson(
obj_key = objective_fingerprint(progress, kp_id)
course_intent = _course_intent(topic, progress)
intent_key = _fingerprint(course_intent)
if stream is not None:
await stream.progress(
"A lecke forrásait és oldalhivatkozásait ellenőrzöm",
source="mastery_path",
stage="responding",
)
await status("checking_sources")
scope_key, indices = await asyncio.to_thread(
scope_snapshot, topic, progress, kp_id, prepare_legacy=True
)
@@ -658,11 +666,7 @@ async def prepare_lesson(
"learner_request": learner_request,
}
async def status(text: str) -> None:
if stream is not None:
await stream.progress(text, source="mastery_path", stage="responding")
await status("Forrásokat keresek ehhez a témához")
await status("finding_sources")
query_result = await _ask(
config,
'Return JSON {"queries":[...]} with up to 3 concise retrieval queries for this learning objective. '
@@ -950,7 +954,7 @@ async def prepare_lesson(
feedback = None
start = 0
if sources:
await status("Az eredeti oldalakat és ábrákat ellenőrzöm")
await status("checking_pages")
observations, feedback, start = await inspect(sources)
retain_inspected(sources, observations)
if feedback is None and ranking.get("sufficient") is True:
@@ -982,9 +986,7 @@ async def prepare_lesson(
"reason": repair["reason"],
"status": "not_applied",
}
await status(
"Hiányzó vagy nehezen olvasható részletet pótolok (egyszeri célzott javítás)"
)
await status("repairing")
if repair["action"] == "search":
repair_queries = repair.get("queries", [repair.get("query")])
if (

View File

@@ -87,6 +87,37 @@ async def test_successful_explicit_preparation_supersedes_same_turn_failure(mate
assert not material.store.load("path").mastery_levels
@pytest.mark.asyncio
@pytest.mark.parametrize("language, expected", [("en", "Finding sources"), ("zh", "查找资料")])
async def test_explicit_preparation_reports_localized_stages_on_the_owned_stream(
material, monkeypatch, language, expected
):
from deeptutor.capabilities.mastery.tools import MasteryPrepareLessonTool
from deeptutor.runtime.stream_bus import StreamBus, register_bus, unregister_bus
_install_preparation(material, monkeypatch)
monkeypatch.setattr(
"deeptutor.capabilities.mastery.tools._new_service", lambda: LearningService(material.store)
)
monkeypatch.setattr("deeptutor.services.llm.config.get_llm_config", lambda: material.config)
stream = StreamBus()
register_bus("preparing", stream)
try:
result = await MasteryPrepareLessonTool().execute(
_mastery_path_id="path",
knowledge_point_id="kp",
_turn_id="preparing",
_language=language,
)
await stream.close()
events = [event async for event in stream.subscribe()]
assert result.success, result.content
assert any(expected in event.content for event in events)
assert not any(event.type.value == "content" for event in events)
finally:
unregister_bus("preparing")
@pytest.fixture
def material(tmp_path, monkeypatch):
raw = tmp_path / "kb" / "raw"