feat(voice): specialize prompt for Isfahan Industrial Parks, emit source excerpts, and bound generation

- Specialize voice assistant identity and agent system prompt for «شرکت شهرک‌های صنعتی اصفهان» (English instructions with Persian proper names)
- Emit bounded chunk text excerpts (up to 2000 chars) and identify primary_source in realtime sources events
- Bound OpenAI output generation via OPENAI_REALTIME_MAX_OUTPUT_TOKENS and add answer_limited event
- Handle old-turn search cancellation safely on turn supersession
- Add end-to-end search tracing pipeline and diagnostic CLI
- Add database organization title and settings update script
This commit is contained in:
amirhosein mazaheri
2026-10-12 17:35:28 +03:30
parent f14166a89f
commit 117fda7cc9
29 changed files with 1476 additions and 67 deletions
+25
View File
@@ -5,6 +5,9 @@ import math
from threading import RLock
from uuid import UUID, uuid4
import time
from typing import Any
from app.modules.knowledge.lexical import LEXICAL_POLICY
MAX_BRANCH_CANDIDATES = 50
@@ -56,11 +59,33 @@ class SearchExecution:
"""Created by the trusted caller, never populated from model arguments."""
user_id: UUID
request_id: str = field(default_factory=lambda: str(uuid4()))
trace_callback: Any = None
trace_events: list = field(default_factory=list)
_start_monotonic: float = field(default_factory=time.monotonic, init=False, repr=False)
_authority: dict | None = field(default=None, init=False, repr=False)
_epoch: int | None = field(default=None, init=False, repr=False)
_refs: dict = field(default_factory=dict, init=False, repr=False)
_lock: RLock = field(default_factory=RLock, init=False, repr=False)
def record_trace(self, stage: str, **details):
with self._lock:
now_mono = time.monotonic()
elapsed_ms = round((now_mono - self._start_monotonic) * 1000, 2)
event = {
"stage": stage,
"elapsed_ms": elapsed_ms,
"timestamp_utc": time.time(),
"request_id": self.request_id,
**details,
}
self.trace_events.append(event)
if self.trace_callback is not None:
try:
self.trace_callback(event)
except Exception:
pass
return event
def capture(self, current, epoch):
with self._lock:
if self._authority is None: