Tool mechanics (teaching_updates evidence, note_explained, grouped quiz
replace/resume, visual sources, option shuffling, repair, skip/defer,
prepare_lesson) now live only in the tool descriptions; the playbook
keeps teaching strategy and when to call which tool. mastery_quiz group
items and the nested revise/profile shapes keep their structure but no
longer repeat every parameter description.
The assessment-result rules added for #2366 move into mastery_assess:
follow a non-passing result's next_step, a coverage_gap result records
nothing and must not trigger unchanged preparation again, and an
incomplete packet is assessed on its covered facets only. The playbook
no longer asks for `passed: true`, which the schema marks as ignored.
An answered pending question is graded from the loop protocol with its
learner_answer and question_id.
The zh playbook is aligned with en line by line: the PDF evidence and
exam practice paragraphs, the multi-turn explanation bullet in its
English position, the registered-assessment wording and the backticked
identifiers. tests/capabilities/test_mastery_prompt_slimming.py checks
the alignment, that each rule is still stated somewhere, and that tool
mechanics are not repeated in the playbook.
Refs #2975
Chat, mastery, question FINISH and notes each carried their own copy of
the dollar-delimiter rule. They now reference {{shared:math_latex}}
(deeptutor/services/prompt/fragments), expanded by PromptManager at load
time; the notes capability expands the marker in its system.md, and
code-built prompts use shared_fragment(). The English notes prompt gains
the rule (and the mermaid line) its Chinese twin already had. The chat
loop no longer repeats the 'concise Markdown' line that runtime_policy
states.
Refs #2975
load_tools appended the loaded schema to the end of tools[]. tools[] is the
first thing in the provider's prompt-cache key, so the next request of the
same turn re-processed the system prompt and the whole history.
When the turn mounts the new call_tool builtin, load_tools now returns the
loaded tools' definitions in its result and leaves tools[] alone; the loop
forwards each call_tool call to the named tool before dispatch, so the tool
runs with its own argument checks, injected kwargs and trace, while the
history keeps the model's own call. Tools loaded this way stay proxied for
the session (loaded_tools.json gains proxied_tools). Runtime loads that must
land in tools[] pass native=True; the TypeScript engine keeps the old
behaviour.
* fix(mastery): grade within the objective's covered and own scope
- Reuse the preserved objective-scoped packet for an objective request
after a focus preparation replaced the live slot, and do not rebuild
an incomplete objective packet whose fingerprints are unchanged (#2363).
- mastery_assess grades a concept/design explanation against the covered
facets of an incomplete objective packet, records that scope, and
returns a structured coverage_gap result instead of a bare refusal.
- Tell the learner when an answer was not recorded or was graded only
against the covered part.
- Give the judge sibling objectives as out of scope and return the
single missing element with a next_step to ask for exactly it (#2364).
* test(mastery): cover the focus-only assessment deadlock from #2905
A complete focus-scoped packet with no assessment slot gets a structured
coverage_gap on every repeated mastery_assess, with no judge call and no
recorded evidence. One objective preparation then grades the retained
explanation together with the next reply.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix(mastery): make the missing-element step the assess instruction
Since dev added a generic instruction to every final mastery_assess
payload, a non-passing verdict carried two competing moves: next_step
asked for exactly the named missing element (#2364) and instruction
asked the learner to explain the objective again. While the gate is not
cleared, the targeted step is now also the instruction, and it says to
record the reply with mastery_assess.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix(mastery): say when an unclear explanation is kept for grading
A non-final verdict in a session keeps the explanation and grades it
together with the follow-up, so the generic "not recorded, progress
unchanged" notice misled the learner into repeating the whole answer.
Add an assessment_needs_clarification notice (en/zh) for that case; an
explanation outside a session keeps the not_recorded notice.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix(mastery): preserve the missing assessment element on replay
---------
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
Co-authored-by: Qiuner <wdst3635@163.com>
* fix(mastery): ignore knowledge-base sources that no longer resolve
Refs #2748
* fix(mastery): filter the caller's mounted knowledge bases too
A study session left open across a deletion keeps sending the base it was
mounted with, and that list is merged verbatim with the topic's sources.
Run both through knowledge_base_ref_available so a stale name cannot reach
the tool bundles and raise AccessError.
* fix(mastery): keep language-course content in its target language
The reply-language directive is the last thing in every system prompt and
tells the model to write quiz stems and options in the reply language and
never switch. For a course whose subject is itself a language, the model
obeyed literally: an "Antonyms" objective in an English course, studied with
Chinese as the reply language, was drafted as 反义词 and taught in a later
session as Chinese antonyms.
- language_directive now says the reply language governs the explanation,
not the subject: a studied language keeps its own words, sentences and
exercise items.
- Route generation and the tutor's outline drafting name the target
language in every module and knowledge point ("English antonyms").
- The tutor playbook keeps an existing language course on its target
language even when an objective name does not repeat it.
Closes#2933
Co-Authored-By: Claude <noreply@anthropic.com>
* test(mastery): check the composed prompts keep a language course's target language
The strict reply-language directive is appended last, after the route and
tutor instructions. Assert the carve-out survives in the prompts the model
actually receives: zh route generation, and the zh tutor playbook rendered
with a fixed reply language.
Related to #2933
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
The fold prompt lets memory entries cite previously retained archive IDs,
but covered_archive_ids had to equal the newly supplied set exactly. A
model that also lists retained IDs as covered failed every fold, so the
watermark never moved and the session stayed on degraded raw history.
Accept covered IDs that are the newly supplied ones plus IDs the prior
memory already covered or cited. Still reject omitted, invented or unseen
IDs, and store only the newly folded IDs as covered.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix: keep sent runtime snapshots in mastery replay
Mastery replay dropped every runtime snapshot from history and the loop
re-appended them after it, so each follow-up request diverged from the
previous one at message 1 and only tools + system hit the prompt cache.
- project_mastery_replay(keep_snapshots=True) for the tutor request and
its token accounting; memory material still drops snapshots
- replay_group no longer blanks a tagged mastery_status_snapshot while
removing the legacy fused suffix
- status snapshot anchors are numbered from the start (occurrence), so a
later snapshot never changes how an earlier turn is projected
Refs #2922
* fix: keep runtime snapshots out of the mastery history budget
Replayed snapshots stay in the request so follow-up turns extend the cached prefix, but counting them made a large mastery_status snapshot push the history over its 20k budget after two turns; the next turn then paid a memory rewrite and a full prefix miss. The budget now measures the learning history only, as before. Refs #2922
* fix: bound the runtime snapshots kept in mastery history
Keeping sent snapshots out of the history budget entirely let many short
exchanges accumulate them without limit (80 quiz-style turns: 5.4k counted,
62k sent). Dialogue still keeps to the plan; dialogue plus snapshots keep to
twice the plan, and only as far as the model's window allows. Refs #2922
* fix: keep only this turn's state in the mastery status snapshot
Every mastery turn sends a fresh mastery_status snapshot and, since the
replay change, keeps earlier ones in history, so whatever a snapshot
carries is paid for once per turn and then kept. A full status read
repeats fixed guidance (open question, question group, working brief,
intake, teaching guidance and focus) and every default value of every
knowledge point.
The snapshot now drops empty and default values and the fixed guidance.
That guidance lives in named constants and is stated once in a new
mastery_status_guide system block, which also explains the omitted
defaults. Snapshots start with a one-line header; history sharing reads
both the header and the longer notice older sessions stored. An explicit
mastery_status call still returns the full payload.
Measured over 54 recorded snapshots: working briefs 1,454 -> 645 tokens
(median), full outline snapshots 6,352 -> 2,954. The guide adds 861
tokens (en) to the cached system prompt.
Refs #2922
* fix: size the exact tail the way the plan does, and share full reads with compact snapshots
Two gaps left by keeping snapshots in mastery replay (review on #2992):
- Recent-history selection counted kept snapshots in full while the plan
discounted them, so a session of short exchanges with large snapshots
archived most of them as soon as selection ran. ContextBuilder now sizes
the candidate tail through _recent_history_tokens(), and the mastery
builder answers with the same _plan_tokens() measure.
- Snapshots carry the compact form of map, learner_profile, learning_stages
and visual_requirements, so a later full mastery_status result never matched
them exactly. Sharing now also compares a full field's compact form and
marks such references with "defaults_omitted": true, which the state
reference notice explains.
Also: rename _next to _compact_next_step, and say in the status guide that
the omitted-default rules cover only what the snapshot includes.
Refs #2922
* fix: keep mastery prompt prefix stable across mode switches
* fix: load the outline tools together when a turn switches to outline
A study turn that switched to outline loaded mastery_build alone through load_tools; the next turn, in outline mode, mounts every outline tool eagerly, so its tools[] carried one schema more than the previous request and missed the whole cached prefix. The mode switch now loads the outline group into the live request at once. Refs #2922
* fix: close loaded tool schemas the same way as mounted ones
Mounted schemas go out with additionalProperties: false; a tool loaded through load_tools did not, so the same tool had two byte forms in tools[]. A tool that moved between mounted and loaded across turns (mastery_build/mastery_revise after an outline->study switch) rewrote the start of the cached prefix. Refs #2922
* fix: keep the outline tools on the deferred loader in outline mode too
Outline mode mounted mastery_build/mastery_revise eagerly and skipped the
loader, while study and review reached them through it. On an install with
no other deferred tool that also dropped load_tools on outline turns, so
tools[] changed in both directions around every switch. Refs #2922
* fix: mount mastery navigation from the first mastery turn
The first mastery turn usually creates the topic; navigation mounted only
once a topic existed, so the second turn's tools[] grew by three schemas and
missed the whole cached prefix. Refs #2922
* fix: send only the current mastery mode's rules, as a runtime snapshot
The system prompt carried all three mode sections so a mode switch would
not rewrite the cached prefix, but that showed the model three conflicting
rule sets and relied on a one-line snapshot to pick one. Keep only a short
frame in the system prompt and send the current mode's own section inside
the mastery_session_mode snapshot, which is appended only when the mode
changes.
Refs #2922
* fix: keep capability tools recorded by another turn in the session's loaded set
A mastery turn records its outline tools (mastery_build, mastery_revise) in
the session's loaded_tools.json so a later study turn keeps the same tools[].
A plain chat turn of the same session builds a provider loader without
capability names; with an unrestricted caller it treated those names as
stale and persisted the set without them, so the next mastery turn mounted
fewer tools and re-paid the cached prefix.
DeferredToolLoader now keeps names it cannot serve (registered tools it does
not own, or names outside its allowlist) as retained: never mounted or
reported, but written back with the session state. Only names whose tool is
gone from the registry are dropped.
Refs #2922
Update the status contract for session_id and prove concurrent retries in a fresh session create only one card while retaining the archived question (139 passed).
The reserved-name filter closed the injection path, but the revision branch
still fell back to the public `answer` parameter when `_learner_message`
was absent. `answer` is model-authored, so a tool call without the trusted
key could replace a committed learner reply and credit mastery for text
the learner never typed.
Reproduced on the previous head: commit a help request, grade it
(`is_correct: null`, `final: false`), then call with only
`answer="photosynthesis"` — `is_correct: true`, mastery 0.5, and
`user_answer` rewritten.
Revision now requires `_learner_message`. Without it the stored answer
stands and the call re-grades as ungraded, which costs no credit and
rewrites nothing. This guard existed earlier on this branch and was lost
when the schema layer was removed; the regression test is restored with
it.
Note this is the same defect the reviewer reported on the first commit,
which means removing the schema work also removed the protection that had
been added to answer it. Worth remembering when cutting scope: verify what
each removed commit was actually guarding.
The fold loop counted only each exchange's archive text and always folded
the oldest exchange, so one exchange over the plan was sent whole, and
prior learner memory could push a fitting exchange over it.
Fold the longest prefix of whole exchanges whose complete request fits:
prior memory, the system instruction and the exchanges as _summarize()
serializes them, plus a reserve for the length line. If even the oldest
exchange doesn't fit, send no memory call; the watermark stays and the
exchange stays in exact recall.
On a free-text mastery question, a learner's "I don't get it, explain"
was judged ungraded and stored as the interaction's user_answer. Every
later mastery_grade call then preferred that stored reply over the
learner's actual answer — the judge rejected the same help request again
as ungraded, and the question could never be cleared. The gate sat at
mastery 0.0 until the tutor called mastery_skip_question itself.
The committed user_answer is authoritative on purpose: the pause/resume
boundary stores the learner's exact words, and a later model round must
not paraphrase them. It stops being authoritative once the learner has
said something else *and* the stored reply was never ruled on. Revise
through the existing record_question_answer path, which rewrites
user_answer and keeps the superseded attempt in the event log as
assessment.revised.
A repeated, empty, or whitespace-identical reply is not a revision, and
a group interaction is excluded: its child questions keep their own
per-leaf revisable logic.
This is the free-text half of #1004, which only covered choice cards.
Closes#2595.
A failed tutoring-memory call keeps the watermark, so the next turn
retried with the same backlog plus the newest exchange, and the call
grew without limit (#2496). Fold in only the oldest whole exchanges
that fit one history plan, at least one, and leave the rest
unsummarized so the watermark moves only past what was covered.
Related to #2496
An endpoint that makes optional properties required forces the model to
send visual even for a text card, with every source left blank.
prepare_visual always rejects an unnamed source, so mastery_quiz failed
on every call and no answer card appeared (#2427).
Treat a visual whose sources name no knowledge base, asset, path, hash
or figure as absent, for single cards and group leaves, as #2170 does
for blank resume ids and empty groups. A visual naming any source still
goes through prepare_visual unchanged.
mastery_assess returned mastered and next but no instruction, unlike
mastery_grade. After a passing explanation the tutor tended to end the
turn on an announcement of the next topic, leaving the learner nothing
to answer.
Add an instruction to the final mastery_assess payload: when mastered,
confirm briefly and continue with next in the same reply (or say the
path is complete); when not mastered, explain the gap and ask again.
The clarification (non-final) result is unchanged. One matching sentence
in the en/zh mastery loop prompt.
Fixes#2323
When mastery_assess asks for clarification, keep the explanation for that
objective in the session. The next assessment grades the earlier explanation
plus the clarification instead of the short reply alone.
Fixes#2249
Keep learner-facing explanations visible across finish checks, persistence, and replay. Remove mastery prose heuristics and prioritize learner objections.
Coordinate service shutdown and descendant cleanup, and preserve video lesson identity and playable results across chat completion and reload.