NU-KIOSK-API / backend /tools /staff_support.py
Monish BV
Add kiosk-api: stripped backend for speech integration
c2b7a7b
"""Blueprint mapping administrative topics to the right staff contacts."""
from __future__ import annotations
import re
from typing import Any, List
from .base import AnalysisContext, Blueprint, BlueprintResult, Fact
class StaffSupportBlueprint(Blueprint):
"""Suggest staff contacts for administrative questions."""
name = "staff_support"
def run(self, context: AnalysisContext, **kwargs: Any) -> BlueprintResult:
query = (kwargs.get("topic") or kwargs.get("need") or kwargs.get("keyword") or "").strip()
if not query:
return BlueprintResult(self.name, kwargs, facts=[], notes=["Let me know what kind of help you need (e.g., reimbursements, travel, advising)."])
staff = context.catalog.try_get("staff")
if not staff:
return BlueprintResult(self.name, kwargs, facts=[], notes=["Staff directory is unavailable right now."])
query_terms = [term for term in re.split(r"[^a-z0-9]+", query.lower()) if term]
matches = []
for row in staff.records:
haystack = " ".join(str(row.get(field, "")).lower() for field in ("Role", "Title"))
if all(term in haystack for term in query_terms):
matches.append(row)
facts: List[Fact] = []
origin = staff.origin
for row in matches:
facts.append(
Fact(
subject=row.get("Name", "Unknown"),
predicate="staff_support",
value={
"title": row.get("Title"),
"role": row.get("Role"),
"location": row.get("Room Location"),
},
source=origin,
confidence=0.85,
)
)
notes: List[str] = []
if not facts:
notes.append(f"I couldn't find a staff contact that mentions '{query}'.")
return BlueprintResult(self.name, kwargs, facts=facts, notes=notes)