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:
@@ -2,6 +2,7 @@
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import dataclass, field
|
||||
import logging
|
||||
import math
|
||||
from threading import Condition, Event
|
||||
import time
|
||||
@@ -12,6 +13,18 @@ from app.modules.knowledge.service import (
|
||||
KnowledgeError, SearchInput, authority, sql_error, transaction,
|
||||
)
|
||||
|
||||
import sys
|
||||
|
||||
tool_logger = logging.getLogger("app.search.tool")
|
||||
tool_logger.setLevel(logging.INFO)
|
||||
|
||||
if not tool_logger.handlers and not any(h for h in logging.getLogger("app").handlers):
|
||||
_tool_h = logging.StreamHandler(sys.stderr)
|
||||
_tool_h.setFormatter(
|
||||
logging.Formatter("%(asctime)s [%(levelname)s] [%(name)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
|
||||
)
|
||||
tool_logger.addHandler(_tool_h)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ToolContext:
|
||||
@@ -90,6 +103,8 @@ class SearchToolRunner:
|
||||
stopped = self._stop(ctx, deadline, cancelled)
|
||||
if stopped:
|
||||
return stopped
|
||||
tool_logger.info("[TOOL:SEARCH_KNOWLEDGE:START] User=%s query=%r context=%r",
|
||||
ctx.execution.user_id, query, context)
|
||||
# Persisted authority is captured outside model input, on a worker.
|
||||
with transaction(service.engine) as conn:
|
||||
current, settings = authority(conn, ctx.execution.user_id)
|
||||
@@ -99,6 +114,8 @@ class SearchToolRunner:
|
||||
if stopped:
|
||||
return stopped
|
||||
result = service.search(ctx.execution, query, context)
|
||||
tool_logger.info("[TOOL:SEARCH_KNOWLEDGE:COMPLETE] User=%s status=%s sources=%d",
|
||||
ctx.execution.user_id, result.get("status"), len(result.get("sources", [])))
|
||||
if result["status"] != "error":
|
||||
# Recheck this delivery boundary after the service handoff.
|
||||
with transaction(service.engine) as conn:
|
||||
|
||||
Reference in New Issue
Block a user