This commit is contained in:
Lars committed 2026-08-29 11:04:34 +02:00
1 parent 4f37991ad1
commit be11f82f84
39 files changed
+2490 -239

No files matched your search

+38 -1
View File
@@ -6,6 +6,7 @@ import re
from context_builder import assemble_text, build_internal_context, is_closing_turn
from conversation_signals import infer_signals
from debug_store import persist_engine_error, persist_step
from dialogue_store import append_message, get_conversation, list_messages, update_conversation_signals
from engine import EngineError, execute_prompt, load_active_prompt
from entity_detect import DETECT_DIALOGUE_FALLBACK_CODES
@@ -317,6 +318,7 @@ def run_turn(profile_id: str, conversation_id: str, body: str, message_id: str |
result = None
impulse = ""
decision: dict = {"operation": "unparsed", "label": "nicht erkannt", "parsed": False}
call_traces: list[dict] = []
try:
while calls < 2:
result = execute_prompt(
@@ -327,6 +329,8 @@ def run_turn(profile_id: str, conversation_id: str, body: str, message_id: str |
context=assembled,
)
calls += 1
if result.get("trace"):
call_traces.append(result.get("trace"))
content = (result.get("content") or "").strip()
if not content:
raise EngineError("empty_provider_response", "Der Provider lieferte keine Antwort.")
@@ -348,7 +352,22 @@ def run_turn(profile_id: str, conversation_id: str, body: str, message_id: str |
"guard": "local_fallback",
}
except EngineError as exc:
if result and result.get("trace") and result.get("trace") not in call_traces:
call_traces.append(result.get("trace"))
if exc.code != "response_validation_failed" and exc.code not in DETECT_DIALOGUE_FALLBACK_CODES:
persist_engine_error(
profile_id,
purpose="dialogue_turn",
exc=exc,
subject_type="conversation",
subject_id=conversation_id,
conversation_id=conversation_id,
extra={
"calls": calls,
"call_traces": call_traces,
"user": {"id": user.get("id"), "body": user.get("body")},
},
)
raise
impulse = local_hold(last_user_text(assembled))
decision = {
@@ -370,6 +389,24 @@ def run_turn(profile_id: str, conversation_id: str, body: str, message_id: str |
)
remember_dialogue_style(profile_id)
consider_dialogue(profile_id, body)
trace = result.get("trace") if result else None
persist_step(
profile_id,
purpose="dialogue_turn",
status="ok",
subject_type="conversation",
subject_id=conversation_id,
conversation_id=conversation_id,
message_id=assistant.get("id"),
decision=decision,
trace=trace,
extra={
"calls": calls,
"call_traces": call_traces,
"user": {"id": user.get("id"), "body": user.get("body")},
"assistant": {"id": assistant.get("id"), "body": assistant.get("body")},
},
)
return {
"conversation": get_conversation(profile_id, conversation_id),
"user": user,
@@ -377,5 +414,5 @@ def run_turn(profile_id: str, conversation_id: str, body: str, message_id: str |
"calls": calls,
"messages": list_messages(profile_id, conversation_id),
"decision": decision,
"trace": result.get("trace") if result else None,
"trace": trace,
}