From b8d893e6993c9da56f853740b5c446263356afc9 Mon Sep 17 00:00:00 2001 From: rootflo-hardik Date: Tue, 10 Mar 2026 12:03:46 +0530 Subject: [PATCH 1/3] functionfilter -> filtering system frame also - solved the issue of having all supported languages transcription in a single user message --- .../call_processing/services/pipecat_service.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py b/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py index b1b6798b..80b31dfe 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py +++ b/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py @@ -83,7 +83,9 @@ def __init__( for lang_code in supported_languages: filter_func = self._create_language_filter(lang_code) stt_service = stt_services[lang_code] - routes.append([FunctionFilter(filter_func), stt_service]) + routes.append( + [FunctionFilter(filter_func, filter_system_frames=True), stt_service] + ) super().__init__(*routes) @@ -130,7 +132,9 @@ def __init__( for lang_code in supported_languages: filter_func = self._create_language_filter(lang_code) tts_service = tts_services[lang_code] - routes.append([FunctionFilter(filter_func), tts_service]) + routes.append( + [FunctionFilter(filter_func, filter_system_frames=True), tts_service] + ) super().__init__(*routes) From 79359f35d98b6d3409911efded72857cd505ed93 Mon Sep 17 00:00:00 2001 From: rootflo-hardik Date: Tue, 10 Mar 2026 12:11:33 +0530 Subject: [PATCH 2/3] modified lang_switch_rules, lang_switch tool desc --- .../constants/language_config.py | 5 ++ .../services/pipecat_service.py | 62 +++++++++++++++---- .../call_processing/services/stt_service.py | 1 + 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/wavefront/server/apps/call_processing/call_processing/constants/language_config.py b/wavefront/server/apps/call_processing/call_processing/constants/language_config.py index 563d3200..ce44a34f 100644 --- a/wavefront/server/apps/call_processing/call_processing/constants/language_config.py +++ b/wavefront/server/apps/call_processing/call_processing/constants/language_config.py @@ -53,6 +53,11 @@ 'vi': ['vietnamese', 'tiếng việt', 'tieng viet'], } +# Human-readable language display names (first keyword, capitalized) +LANGUAGE_DISPLAY_NAMES: Dict[str, str] = { + code: keywords[0].capitalize() for code, keywords in LANGUAGE_KEYWORDS.items() +} + # Language-specific LLM instructions LANGUAGE_INSTRUCTIONS: Dict[str, str] = { 'en': 'Respond in English.', diff --git a/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py b/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py index 80b31dfe..2978c7de 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py +++ b/wavefront/server/apps/call_processing/call_processing/services/pipecat_service.py @@ -58,6 +58,7 @@ # ) from call_processing.constants.language_config import ( LANGUAGE_INSTRUCTIONS, + LANGUAGE_DISPLAY_NAMES, ) from call_processing.constants.filler_phrases import FILLER_PHRASES @@ -317,13 +318,45 @@ async def run_conversation( initial_language_instruction = LANGUAGE_INSTRUCTIONS.get( default_language, LANGUAGE_INSTRUCTIONS.get('en', 'Respond in English.') ) + supported_language_names = [ + LANGUAGE_DISPLAY_NAMES.get(code, code) for code in supported_languages + ] language_switching_rules = ( - f'\n\nLANGUAGE SWITCHING RULES:\n' - f'- You support these languages only: {", ".join(supported_languages)}.\n' - f'- Call detect_and_switch_language only when the user clearly intends to choose or change language. ' - f'A single word is a valid choice if it directly answers a language preference question.\n' - f'- Do NOT switch based on a greeting (e.g. "Namaste") or incidental use of another language.\n' - f'- If the user requests a language not in the supported list, apologise and tell them which languages are available. Do not call the switch tool.' + f'\n\nLANGUAGE SWITCHING RULES (follow exactly, no exceptions):\n' + f'Supported languages: {", ".join(supported_language_names)}.\n' + f'Current language: {LANGUAGE_DISPLAY_NAMES.get(default_language, default_language)}.\n\n' + f'CASE 1 — USER WANTS THE ASSISTANT TO USE A DIFFERENT LANGUAGE:\n' + f'The user is asking or implying that they want the conversation to happen in a specific supported language. Triggers include:\n' + f' - Saying a supported language name alone (e.g. "Hindi", "English", "Tamil")\n' + f' - Asking if you can speak/use a language (e.g. "Can you speak in English?", "क्या आप हिंदी में बात कर सकते हैं?")\n' + f' - Requesting a switch (e.g. "switch to Hindi", "speak in Tamil", "Hindi mein baat karo", "change language")\n' + f' - Saying "speaking [language]" implying they want the assistant to speak it (e.g. "Speaking Hindi")\n' + f' - Responding with a language name after being asked which language they want\n' + f' - A word that phonetically resembles a supported language name — STT often mishears language names ' + f'(e.g. "Hindi" → "Indy" or "Indie", "Kannada" → "Canada", "Telugu" → "Tell you"). ' + f'Use phonetic judgment: if the word sounds like a supported language name in context, treat it as CASE 1.\n' + f'BIAS RULE: When in doubt between CASE 1 and CASE 2, if a supported language name (or phonetic match) ' + f'appears in the message, default to CASE 1.\n' + f'ACTION: Call detect_and_switch_language immediately. Do NOT ask for confirmation. Do NOT say anything before calling the tool.\n\n' + f'CASE 2 — USER SPEAKS IN A DIFFERENT LANGUAGE (no language name mentioned, no switch request):\n' + f'The user sends a full message in a language different from the current language, ' + f'with NO mention of a language name and NO request to switch. They are just talking.\n' + f'NOTE: STT may transcribe foreign speech phonetically in the current language script — ' + f'e.g. if current language is English and the user speaks Hindi, STT may output romanized Hindi ' + f'like "Ha muje naye loan ke baare mai batao". Recognize this as Hindi input, not English.\n' + f'ACTION: Do NOT call detect_and_switch_language. Do NOT answer their query. ' + f'Respond in the CURRENT language (the language you are currently configured to speak) with this meaning: ' + f'"Are you trying to switch the language? If yes, please say one of: {", ".join(supported_language_names)}"\n\n' + f'CASE 3 — UNSUPPORTED LANGUAGE REQUESTED:\n' + f'The user requests a language not in the supported list.\n' + f'ACTION: Do NOT call detect_and_switch_language. Inform the user that only these languages are supported: ' + f'{", ".join(supported_language_names)}.\n\n' + f'CRITICAL RULES:\n' + f'- Never call detect_and_switch_language for Case 2 or Case 3.\n' + f'- Never answer a query in the wrong language before switching.\n' + f'- Never ask for confirmation before switching in Case 1.\n' + f'- Never respond with your own words before or instead of calling the tool in Case 1.\n' + f'- Never invent responses outside these three cases.' ) system_content = f'{initial_language_instruction}\n\n{base_system_prompt}{language_switching_rules}' # Store base prompt without language instruction for switching (rules persist across switches) @@ -430,13 +463,16 @@ async def run_conversation( language_detection_schema = FunctionSchema( name='detect_and_switch_language', description=( - f"Switch the conversation language when the user clearly intends to choose or change language. " - f"Use conversational context to judge intent — a single word like 'Hindi' or 'Tamil' counts as an " - f"explicit choice when it directly answers a question about language preference. " - f"Also trigger on explicit requests like 'switch to Hindi', 'speak in Tamil', 'Hindi mein baat karo'. " - f"Do NOT trigger on greetings in another language (e.g. 'Namaste') without a clear intent to switch. " - f"Only switch to languages in the supported list: {', '.join(supported_languages)}. " - f"If the user asks for an unsupported language, do NOT call this tool — inform them directly in the current language. " + f"Switch the conversation language. " + f"Call this when the user wants the assistant to use a specific language — " + f"this includes: saying a language name directly ('Hindi', 'Tamil'), " + f"asking 'can you speak in X?', saying 'speaking [language]', " + f"or phrases like 'switch to Hindi', 'speak in Tamil', 'Hindi mein baat karo'. " + f"STT may mishear language names (e.g. 'Hindi' → 'Indy', 'Kannada' → 'Canada') — use phonetic judgment. " + f"When in doubt and a language name is present, call this tool. " + f"Do NOT call this tool when the user simply starts speaking in another language with no language name and no switch request — " + f"in that case respond in the current language asking if they want to switch. " + f"Only switch to supported languages: {', '.join(supported_language_names)}. " f"Current language: {language_state['current_language']}." ), properties={ diff --git a/wavefront/server/apps/call_processing/call_processing/services/stt_service.py b/wavefront/server/apps/call_processing/call_processing/services/stt_service.py index e1d77623..e43e7dc2 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/stt_service.py +++ b/wavefront/server/apps/call_processing/call_processing/services/stt_service.py @@ -149,6 +149,7 @@ def _create_sarvam_stt(api_key: str, parameters: Dict[str, Any]): if 'high_vad_sensitivity' in parameters: params_dict['high_vad_sensitivity'] = parameters['high_vad_sensitivity'] + params_dict['mode'] = 'transcribe' model = parameters.get('model', 'saarika:v2.5') sample_rate = parameters.get('sample_rate', 8000) From b71eb86a8f8060637838eeed1a3e6397e45576c2 Mon Sep 17 00:00:00 2001 From: rootflo-hardik Date: Tue, 10 Mar 2026 15:26:36 +0530 Subject: [PATCH 3/3] removed unnecessary mode parameter from sarvam stt --- .../apps/call_processing/call_processing/services/stt_service.py | 1 - 1 file changed, 1 deletion(-) diff --git a/wavefront/server/apps/call_processing/call_processing/services/stt_service.py b/wavefront/server/apps/call_processing/call_processing/services/stt_service.py index e43e7dc2..e1d77623 100644 --- a/wavefront/server/apps/call_processing/call_processing/services/stt_service.py +++ b/wavefront/server/apps/call_processing/call_processing/services/stt_service.py @@ -149,7 +149,6 @@ def _create_sarvam_stt(api_key: str, parameters: Dict[str, Any]): if 'high_vad_sensitivity' in parameters: params_dict['high_vad_sensitivity'] = parameters['high_vad_sensitivity'] - params_dict['mode'] = 'transcribe' model = parameters.get('model', 'saarika:v2.5') sample_rate = parameters.get('sample_rate', 8000)