Commit Graph
38 Commits
Author SHA1 Message Date
didar d2438b6954 feat: canonical intent taxonomy for AI operator (kb_answer -> intent_code)
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
2026-08-31 00:17:51 +05:00
arystanbek 9d918af12a fix: bring aimaq host-override files (voice.py, persona env) back into git
Both services/ai_orchestrator_service/voice.py and the aimaq persona/DOMAIN
SCOPE prompt were bind-mounted straight from the host on the aimaq stack,
bypassing git and CI entirely since they were first hand-edited in prod.

voice.py: merged the host's live business logic (gas/aimaq domain keyword
list, off-domain Kazakh/Russian replies, disabled re-correction of an already
obtained name) with the timeout_seconds fix from 09bcf74 that never reached
aimaq because the bind mount blocked it.

aimaq.env.production: replaced the AI_OPERATOR_* env values (which were never
interpolated -- {agent_name}/{company_name} would have been read literally)
with the final resolved Zhanna/Kazakgaz Aimaq text including the DOMAIN SCOPE
clause, matching what was actually live on the host.
2026-08-30 07:45:35 +00:00
didar fe9b3f3a80 feat: enhance voice reply logic to prevent duplicate name addressing and improve greeting handling
deploy / deploy (push) Successful in 32s
2026-08-30 11:53:56 +05:00
arys fe8598e09f fix: TTS ack-bank served stale voice after voice-config changes; add website/English pronunciation rules
RuntimeConfiguredTTSProvider (the live 'dynamic' TTS provider, resolves
voice from DB-backed config) never overrode cache_fingerprint(), so it
fell back to the base class's empty string. PrebakedAckBank keys its
on-disk cache on that fingerprint, so short filler phrases like
'Секунду' kept serving audio baked with the previous ElevenLabs voice
even after a voice change, while full LLM replies (cached inside the
resolved provider itself, keyed on its own voice id) already used the
new voice — explaining why callers heard two different voices in the
same call. Fix: delegate cache_fingerprint() to the resolved provider.

Also extend the voice delivery_hint so the model transliterates website
addresses and English words/abbreviations into spoken Cyrillic instead
of leaving raw Latin text for the TTS engine to mangle (egov.kz was
coming out as 'эговкз').
2026-08-30 11:39:14 +05:00
arys d876a67b3a fix: instruct voice AI to spell out phone numbers and dates in natural spoken Russian
TTS reads raw text digit-by-digit with no number/date normalization layer.
Short numbers like 1414 were read as a single 4-digit number (tysyacha
chetyresta chetyrnadtsat) instead of a spoken code, and dates like '25
chisla' were read in the wrong grammatical case (dvadtsat pyat chislo
instead of dvadtsat pyatogo chisla). Extend the voice delivery_hint with
explicit spell-out rules so the model itself produces already-correct
spoken-form text.
2026-08-30 11:21:42 +05:00
didar a651b9c086 fix: add name correction action in _voice_downstream_name_update function
deploy / deploy (push) Successful in 30s
2026-08-29 01:53:58 +05:00
didar 78007dae38 fix: improve name matching logic in _voice_reply_with_name function
deploy / deploy (push) Successful in 31s
2026-08-29 01:32:08 +05:00
didar 09bcf7457c feat: add AI_VOICE_AI_TIMEOUT_SECONDS for configurable voice timeout
deploy / deploy (push) Successful in 30s
2026-08-29 00:50:08 +05:00
didarandClaude Sonnet 5 c5dd87ee32 feat: make ai_operator_settings config code the source of truth
Add sync_ai_operator_config_from_code() which overwrites the DB-cached
ai_operator_settings row from ai_operator_default_config() on startup
of ai_orchestrator_service and ai_voice_runtime_service. Greeting and
system prompt changes now go through git + deploy instead of manual
psql/API edits to prod. Also adds a root README pointing to existing docs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-21 21:00:34 +05:00
didar c5e11fde3d Add test marker to voice greeting to verify Gitea CI/CD deploy
deploy / deploy (push) Canceled after 25h22m40s
2026-08-20 22:47:34 +05:00
didar 4e1039ab58 Merge pull request 'Play a filler ack during slow voice decisions and cache KB search rows' (#2) from voice-latency-llm-tts-improvements into main
deploy / deploy (push) Canceled after 27h22m42s
Reviewed-on: #2
2026-08-20 09:47:45 +00:00
Didar KozhikovandClaude Sonnet 5 49489f89b5 Play a filler ack during slow voice decisions and cache KB search rows
Two independent latency fixes for the voice-assistant reply pipeline,
both scoped to the parts of the flow that run regardless of whether
voice_v2 is enabled for a queue:

1. media_runtime._process_utterance: the v1/fallback turn path (used by
   any queue not covered by AI_VOICE_V2_QUEUE_CODES) silently awaited the
   full LLM decision with no audio playing at all, unlike the v2 path
   which already has a decision-timeout ack. Give v1 the same behavior:
   wait up to 600ms (_v1_ack_wait_seconds) for the decision, and if it's
   still not ready, play a short "Секунду." filler via the existing
   _emit_early_ack before the real reply, instead of leaving the caller
   in silence for the full LLM+TTS round trip. Reuses the same ack
   selection/playback code path v2 already exercises, so no new failure
   modes - just an added timeout branch mirroring the existing v2 one.

2. ai_orchestrator_service._kb_search: every voice/chat turn re-ran a
   full-table scan of kb_articles (all columns, including body text) and
   rescored every row in Python, even though the KB rarely changes
   mid-conversation. Added an in-process cache keyed by language, gated
   on a cheap content fingerprint (row count + max id + max updated_at +
   summed title/body/tags length, all computed server-side without
   transferring the text columns). A fingerprint mismatch always
   triggers a fresh fetch, so this can never serve stale results after
   an insert/update/delete - unlike a naive TTL cache, which would have
   been be wrong the moment a test (or a real KB edit) changed the table
   within the cache window.

   Note the first fingerprint design (count + max id + max updated_at
   only) was insufficient: utc_now_iso() truncates to whole seconds and
   SQLite reuses primary keys after a full-table delete, so two
   different row sets written in the same wall-clock second could share
   a fingerprint. Caught this via a real test failure
   (test_ai_whatsapp_relaxed_kb_search_answers_phrase_query breaking
   only when run after test_ai_orchestrator_service.py in the same
   process) before it could reach production; the summed content-length
   term closes the gap.

Added test_media_runtime_plays_filler_ack_when_v1_decision_is_slow
(asserts greeting -> ack -> reply delivery order when process_turn is
slow) and verified the KB cache against the full
test_ai_orchestrator_service.py + test_ai_whatsapp_orchestrator_service.py
suite plus a wider kb/orchestrator/whatsapp/telegram/voice-filtered run:
only the same pre-existing, already-documented failures remain (unrelated
sales_service test-isolation ordering, one known persona-prompt
assertion) - no new failures from either change.

Streaming the LLM decision itself (start speaking reply_text before the
full structured JSON response finishes generating) was scoped but
deliberately deferred: it needs incremental JSON parsing on top of SSE
streaming to detect when just the reply_text field is complete, shared
across both voice and text-channel decision paths - a separate,
higher-risk change that deserves its own PR and testing pass rather than
being bundled here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-19 21:54:02 +05:00
Didar KozhikovandClaude Sonnet 5 cdabe61bc2 Add architecture longread and remove dead code found during review
- docs: longread.md — deep architecture/flow review of the whole
  platform (services, event bus reality vs docs, AI/ML stack honesty
  check, tech debt inventory)
- ai_orchestrator_service/voice.py: drop _voice_decision_legacy
  (unreferenced) and the shadowed first _voice_decision definition
  (silently overwritten by the real one, dead code)
- ui/analyst/app.js: drop duplicate dead definitions of
  loadSavedAnalyticsViews/saveAnalyticsView/deleteAnalyticsView and
  the first loadAnalyticsTrend implementation, all shadowed by later
  declarations in the same file; kept the intentional AI-mode
  drilldown wrapper layer (openAnalyticsDrilldown/exportAnalyticsDrilldownCsv/etc.)
  since that duplication is deliberate delegation, not dead code
- ui/operator/vendor/sip-0.21.2.min.js: remove byte-identical orphaned
  duplicate of ui/operator/sip-0.21.2.min.js (unreferenced anywhere)

Verified via full pytest run: identical set of 97 pre-existing
failures before and after (sales_* test-isolation ordering issue and
one known persona-prompt test), no new regressions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-18 22:25:27 +05:00
Magzhan Zhumabayev ce3ba270aa Add configurable AI operator persona 2026-05-11 17:37:26 +05:00
Yera All 224973d840 Revert "fix(voice): race slow streaming asr finalize"
This reverts commit 77df41bce0.
2026-04-19 01:30:26 +05:00
Yera All 93002ab86a Revert "fix(voice): stop repeating failed clarifications"
This reverts commit 294d30a797.
2026-04-19 01:30:26 +05:00
Yera All 294d30a797 fix(voice): stop repeating failed clarifications 2026-04-19 01:19:54 +05:00
Yera All 77df41bce0 fix(voice): race slow streaming asr finalize 2026-04-19 01:06:03 +05:00
Yera All 9cd553bf92 feat(voice): start replies from stable streaming partials 2026-04-19 00:13:58 +05:00
Yera All 34b807e460 feat(voice): add elevenlabs stt and transcript truth fixes 2026-04-18 18:25:07 +05:00
Yera All 39096e114f fix(voice): harden noisy streaming turns 2026-04-17 00:30:41 +05:00
Yera AllandClaude Opus 4.6 6798320209 fix: remove dead code duplicates, add SQL LIMIT across all services
- Remove duplicate function definitions with hardcoded "AI-оператор" strings
  (ai_voice_runtime, ai_orchestrator, voice_name_config, voice.py)
- Remove unreachable dead code after return in ai_voice_runtime
- Add SQL LIMIT to 17 unbounded queries across 12 services to prevent OOM
- Move Python-side filtering to SQL WHERE in reporting_service
- Downgrade 19 logger.warning to logger.info for normal-flow events in media_runtime

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 12:04:26 +05:00
Yera All 6b8f5d069b feat(ai): add rolling conversation summary memory 2026-04-13 11:59:43 +05:00
Yera All 989bf9a0c1 fix(voice): stabilize v2 streaming topic handling 2026-04-12 21:59:32 +05:00
Yera All 57bd5cad4b fix(voice): suppress low-signal turns and false lookup replies 2026-04-12 20:40:25 +05:00
Yera All b75b76fae6 feat(voice): add duplex streaming v2 pipeline 2026-04-11 17:38:21 +05:00
Yera All fc976804e4 feat(voice): add admin-configurable elevenlabs tts 2026-04-11 16:46:43 +05:00
Yera All 5588f99db9 fix(voice): fast fallback for off-domain requests 2026-04-11 01:55:28 +05:00
Yera All c39fad7e2d feat(voice): add phase 1.1 partial asr fast ack 2026-04-11 01:24:21 +05:00
Yera All fa2ea1ef03 fix(voice): preserve llm name corrections in downstream turns 2026-04-08 12:49:14 +05:00
Yera All a4b1eb2818 feat(voice): auto-populate name from known customer on repeat calls
When a new voice session starts and the customer already has a trusted
display_name on file (e.g. from a previous call), automatically set
name_status to 'name_obtained' so the AI greets them by name instead
of asking again.
2026-04-08 01:19:40 +05:00
Yera All a47c09d465 fix(voice): prevent regex heuristic from overwriting LLM-extracted customer name
- Block old _voice_downstream_name_update from overwriting name_obtained status
  unless user explicitly says 'меня зовут X' (explicit_candidate only)
- Move _persist_voice_name_state to run AFTER LLM extraction, not before,
  so LLM always gets a chance to override the regex result
- Fixes bug where phrases like 'можешь назвать их' were incorrectly
  captured as customer name, overwriting the real name
2026-04-08 01:06:08 +05:00
Yera All 6035c5d4d0 feat(ai): shift name extraction to LLM payload piggybacking to improve contextual accuracy 2026-04-07 11:01:17 +05:00
Yera All 1444cf07ab fix(ai): ignore generic phrases and stopwords in voice name extraction 2026-04-07 01:01:06 +05:00
Yera All 0a8f586f97 feat(ai): Append inline name followup to initial greeting to meet IVR expectations 2026-04-07 00:25:56 +05:00
Yera All 1497bb0feb feat(ai): Finalize voice operator persona and voice name flow 2026-04-06 23:19:24 +05:00
Yera All d959c2b2f0 Add voice name flow controls and analytics 2026-04-05 03:26:18 +05:00
Yera All 5374c202d9 Initial import with GitLab CI/CD and registry deploy flow 2026-04-02 17:05:45 +05:00