feat: canonical intent taxonomy for AI operator (kb_answer -> intent_code)
deploy / deploy (push) Successful in 30s
deploy / deploy (push) Successful in 30s
Centralizes fixed control intents and adds a data-driven intent_code field on kb_articles so many phrasings of the same FAQ question resolve to one stable code (e.g. VOUCHER_ACTIVATION) instead of a free-form, unvalidated string the LLM invented on the fly. - services/shared/intents.py: CONTROL_INTENTS + normalize_intent() - kb_articles.intent_code column (ORM + dev/sqlite runtime compat + migrations/sql/0034_* for postgres/sqlite) - kb_service CRUD exposes intent_code - orchestrator surfaces intent_code to the LLM and validates its intent output against control intents + the KB codes shown that turn - voice.py: _voice_early_intent_bucket renamed to _voice_ack_topic_bucket to stop it being conflated with the canonical FAQ intent
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
from services.shared.intents import CONTROL_INTENTS, UNKNOWN_INTENT, normalize_intent
|
||||
|
||||
|
||||
def test_control_intent_passes_through_unchanged():
|
||||
assert normalize_intent("handoff_request") == "handoff_request"
|
||||
assert normalize_intent("kb_answer", known_topic_codes=["VOUCHER_ACTIVATION"]) == "kb_answer"
|
||||
|
||||
|
||||
def test_matching_topic_code_passes_through_case_insensitively():
|
||||
assert normalize_intent("voucher_activation", known_topic_codes=["VOUCHER_ACTIVATION"]) == "VOUCHER_ACTIVATION"
|
||||
assert normalize_intent(" Voucher_Activation ", known_topic_codes=["voucher_activation"]) == "VOUCHER_ACTIVATION"
|
||||
|
||||
|
||||
def test_unknown_topic_code_falls_back_to_unknown():
|
||||
assert normalize_intent("made_up_intent", known_topic_codes=["VOUCHER_ACTIVATION"]) == UNKNOWN_INTENT
|
||||
assert normalize_intent("voucher_activation", known_topic_codes=[]) == UNKNOWN_INTENT
|
||||
|
||||
|
||||
def test_empty_or_missing_intent_falls_back_to_unknown():
|
||||
assert normalize_intent(None) == UNKNOWN_INTENT
|
||||
assert normalize_intent("") == UNKNOWN_INTENT
|
||||
assert normalize_intent(" ") == UNKNOWN_INTENT
|
||||
|
||||
|
||||
def test_control_intents_frozenset_matches_documented_values():
|
||||
assert CONTROL_INTENTS == {
|
||||
"identity_question",
|
||||
"handoff_request",
|
||||
"sensitive_request",
|
||||
"resolution_confirmed",
|
||||
"clarification",
|
||||
"kb_answer",
|
||||
"unknown",
|
||||
}
|
||||
Reference in New Issue
Block a user