Put student-first detect learning ahead of the teacher call.
Identity-only senses no longer lock a new cue. Learning stages, journal-generate review, and additive docs follow the closed section 6. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a65ea98b0c
commit
011cc9dd81
26 files changed
+1893
-89
No files matched your search
+37
-31
@@ -8,22 +8,18 @@ from context_builder import assemble_text, build_internal_context, is_closing_tu
|
||||
from conversation_signals import infer_signals
|
||||
from debug_store import persist_engine_error, persist_step
|
||||
from detect_learning import (
|
||||
MODE_LEARNING,
|
||||
apply_learned_decisions,
|
||||
apply_review_decisions,
|
||||
auto_resolve_ambiguous,
|
||||
build_candidates,
|
||||
confirm_known_identity_spans,
|
||||
drop_pending,
|
||||
get_detect_operating_mode,
|
||||
is_bypass_mode,
|
||||
load_pending,
|
||||
save_pending,
|
||||
supplement_kinship_candidates,
|
||||
suppress_known_non_identity,
|
||||
)
|
||||
from detect_pipeline import KIND_CONFIRM_REMOTE, prepare_detect_pipeline
|
||||
from dialogue_store import append_message, get_conversation, list_messages, update_conversation_signals
|
||||
from engine import EngineError, execute_prompt, load_active_prompt, preview_prompt
|
||||
from entity_detect import DETECT_DIALOGUE_FALLBACK_CODES, DetectError, detect_personal_egress
|
||||
from entity_detect import DETECT_DIALOGUE_FALLBACK_CODES, DetectError
|
||||
from writing_profile_store import remember_dialogue_style
|
||||
from profile_review import consider_dialogue
|
||||
|
||||
@@ -331,6 +327,7 @@ def _finish_turn(
|
||||
decision: dict = {"operation": "unparsed", "label": "nicht erkannt", "parsed": False}
|
||||
call_traces: list[dict] = []
|
||||
working = dict(assembled)
|
||||
working["user_body"] = user.get("body") or working.get("user_body") or ""
|
||||
try:
|
||||
while calls < 2:
|
||||
result = execute_prompt(
|
||||
@@ -431,24 +428,22 @@ def _finish_turn(
|
||||
}
|
||||
|
||||
|
||||
def _review_pause_payload(review_id: str, candidates: list[dict], kind: str, purpose: str = "dialogue_turn") -> dict:
|
||||
return {
|
||||
"id": review_id,
|
||||
"candidates": candidates,
|
||||
"kind": kind,
|
||||
"purpose": purpose,
|
||||
}
|
||||
|
||||
|
||||
def _learning_pause(profile_id: str, conversation_id: str, user: dict, assembled: dict, prompt: dict) -> dict | None:
|
||||
preview = preview_prompt(prompt, assembled)
|
||||
rendered = preview.get("rendered") or ""
|
||||
try:
|
||||
outcome = detect_personal_egress(profile_id, rendered)
|
||||
except DetectError:
|
||||
return None
|
||||
user_body = user.get("body") or ""
|
||||
mappings = list(outcome.mappings or [])
|
||||
candidates = build_candidates(profile_id, mappings, user_body, rendered)
|
||||
candidates, mappings = supplement_kinship_candidates(
|
||||
profile_id, candidates, mappings, user_body, rendered
|
||||
)
|
||||
candidates, mappings = apply_learned_decisions(
|
||||
profile_id, candidates, mappings, user_body, rendered
|
||||
)
|
||||
candidates, mappings = auto_resolve_ambiguous(profile_id, candidates, mappings)
|
||||
if not candidates:
|
||||
result = prepare_detect_pipeline(profile_id, user_body, rendered)
|
||||
mappings = list(result.mappings or [])
|
||||
if not result.need_review and not result.candidates:
|
||||
confirm_known_identity_spans(profile_id, mappings, user_body)
|
||||
mappings = suppress_known_non_identity(profile_id, mappings, user_body)
|
||||
return _finish_turn(
|
||||
@@ -465,8 +460,11 @@ def _learning_pause(profile_id: str, conversation_id: str, user: dict, assembled
|
||||
user.get("id") or "",
|
||||
{
|
||||
"mappings": mappings,
|
||||
"candidates": candidates,
|
||||
"candidates": result.candidates,
|
||||
"user_body": user_body,
|
||||
"kind": result.kind,
|
||||
"counters": result.counters,
|
||||
"purpose": "dialogue_turn",
|
||||
},
|
||||
)
|
||||
return {
|
||||
@@ -475,10 +473,7 @@ def _learning_pause(profile_id: str, conversation_id: str, user: dict, assembled
|
||||
"assistant": None,
|
||||
"calls": 0,
|
||||
"messages": list_messages(profile_id, conversation_id),
|
||||
"pending_mask_review": {
|
||||
"id": review_id,
|
||||
"candidates": candidates,
|
||||
},
|
||||
"pending_mask_review": _review_pause_payload(review_id, result.candidates, result.kind),
|
||||
}
|
||||
|
||||
|
||||
@@ -494,10 +489,11 @@ def run_turn(profile_id: str, conversation_id: str, body: str, message_id: str |
|
||||
)
|
||||
assembled = assemble_text(context)
|
||||
prompt = load_active_prompt("mvp.dialogue_turn")
|
||||
if get_detect_operating_mode() == MODE_LEARNING:
|
||||
paused = _learning_pause(profile_id, conversation_id, user, assembled, prompt)
|
||||
if paused is not None:
|
||||
return paused
|
||||
if is_bypass_mode():
|
||||
return _finish_turn(profile_id, conversation_id, user, assembled, prompt)
|
||||
paused = _learning_pause(profile_id, conversation_id, user, assembled, prompt)
|
||||
if paused is not None:
|
||||
return paused
|
||||
return _finish_turn(profile_id, conversation_id, user, assembled, prompt)
|
||||
|
||||
|
||||
@@ -505,7 +501,17 @@ def continue_turn(profile_id: str, conversation_id: str, review_id: str, decisio
|
||||
pending = load_pending(profile_id, review_id)
|
||||
if not pending or pending.get("conversation_id") != conversation_id:
|
||||
raise EngineError("mask_review_missing", "Die Maskierungsprüfung ist nicht mehr gültig.", 404)
|
||||
mappings = apply_review_decisions(profile_id, pending, decisions)
|
||||
if pending.get("purpose") == "journal_generate":
|
||||
raise EngineError("mask_review_missing", "Diese Prüfung gehört zum Journalentwurf.", 409)
|
||||
if pending.get("kind") == KIND_CONFIRM_REMOTE:
|
||||
try:
|
||||
from detect_pipeline import apply_remote_confirm
|
||||
|
||||
mappings = apply_remote_confirm(profile_id, pending, decisions)
|
||||
except DetectError as exc:
|
||||
raise EngineError(exc.code, exc.message, getattr(exc, "status_code", 403)) from exc
|
||||
else:
|
||||
mappings = apply_review_decisions(profile_id, pending, decisions)
|
||||
drop_pending(profile_id, review_id)
|
||||
conversation = get_conversation(profile_id, conversation_id)
|
||||
context = build_internal_context(
|
||||
|
||||
Reference in new issue
Block a user