feat(voice_worker): the v2 brain answers in Korean unless asked for another language
The brain passes default_language (worker --reply-language, default Korean) to the reply engine; unlike the output_language lock it gives way when the user explicitly asks for a language. Tools get the ko code (--tool-language). Eval evals/test_reply_language_default.py (Qwen3.6 on Strata): 6/6, English questions answered in Korean, an explicit English request in English, and the control without the default answers English in English. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -981,7 +981,8 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
text: str, dialogue_memory: "DialogueMemory",
|
||||
language: Optional[str] = None,
|
||||
history: Optional[Any] = None,
|
||||
legacy_memory: bool = True) -> Optional[str]:
|
||||
legacy_memory: bool = True,
|
||||
default_language: Optional[str] = None) -> Optional[str]:
|
||||
"""
|
||||
Main entry point for reply generation.
|
||||
|
||||
@@ -1004,6 +1005,9 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
enrichment) belongs to a single user. False skips all of it, for
|
||||
the v2 brain where several people share one assistant and only
|
||||
the scoped ``history`` may reach the prompt.
|
||||
default_language: v2 only. The language to reply in unless the user
|
||||
explicitly asks for another one (e.g. "Korean"). An
|
||||
``output_language`` lock still wins. None: the user's language.
|
||||
|
||||
Returns:
|
||||
Generated reply text or None
|
||||
@@ -1713,7 +1717,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
# _resolve_output_language). Building the persona from the raw env var while
|
||||
# the directive used the config value made the two contradict each other.
|
||||
_output_language = _resolve_output_language()
|
||||
_persona_prompt = build_system_prompt(_assistant_name, _output_language)
|
||||
_persona_prompt = build_system_prompt(_assistant_name, _output_language, default_language)
|
||||
# File-based operator instructions: every *.md in AGENTS_DIR (default
|
||||
# /app/agents, bind-mounted from ./agents). Read once per turn so edits in
|
||||
# the folder apply on the next reply without a restart; fail-open to "".
|
||||
@@ -1738,6 +1742,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
_lang_directive = reply_language_directive(
|
||||
_output_language,
|
||||
getattr(cfg, "tts_engine", "piper"),
|
||||
default_language,
|
||||
)
|
||||
if _lang_directive:
|
||||
guidance.insert(1, _lang_directive)
|
||||
|
||||
@@ -180,7 +180,8 @@ def tool_honesty_reminder(tool_names) -> str:
|
||||
|
||||
|
||||
def build_system_prompt(
|
||||
assistant_name: str = "Jarvis", output_language: Optional[str] = None
|
||||
assistant_name: str = "Jarvis", output_language: Optional[str] = None,
|
||||
default_language: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Render the persona prompt with the configured assistant name.
|
||||
|
||||
@@ -198,6 +199,9 @@ def build_system_prompt(
|
||||
lang = (output_language or "").strip()
|
||||
if lang:
|
||||
prompt = prompt.replace("in the user's language", f"in {lang}")
|
||||
elif (default_language or "").strip():
|
||||
# The reply-language directive decides (default, or what the user asked for).
|
||||
prompt = prompt.replace("in the user's language", "in the reply language")
|
||||
return prompt
|
||||
|
||||
|
||||
@@ -240,8 +244,30 @@ ENGLISH_ONLY_DIRECTIVE = (
|
||||
)
|
||||
|
||||
|
||||
def default_language_directive(language: Optional[str]) -> Optional[str]:
|
||||
"""Return a 'reply in <language> unless asked otherwise' instruction, or None when unset.
|
||||
|
||||
Unlike the ``output_language`` lock, a default gives way when the user explicitly asks for
|
||||
another language ("answer in English"). The v2 brain uses it so replies come in the
|
||||
deployment's language (Korean) whatever language the question was heard or written in.
|
||||
Names whatever language it is given, so it works for any default.
|
||||
"""
|
||||
lang = (language or "").strip()
|
||||
if not lang:
|
||||
return None
|
||||
return (
|
||||
f"REPLY LANGUAGE: write your reply in {lang}, whatever language the user's message or "
|
||||
f"any reference text is in. Use another language only when the user explicitly asks you "
|
||||
f"to answer or speak in it; then follow what they asked (just this reply, or from now "
|
||||
f"on in this conversation). Do not mix in other scripts: no Chinese/Hanja characters, "
|
||||
f"Japanese kana or Cyrillic letters inside a {lang} reply. (Numerals and unavoidable "
|
||||
f"proper-noun brand names are fine.)"
|
||||
)
|
||||
|
||||
|
||||
def reply_language_directive(
|
||||
output_language: Optional[str], tts_engine: Optional[str]
|
||||
output_language: Optional[str], tts_engine: Optional[str],
|
||||
default_language: Optional[str] = None,
|
||||
) -> Optional[str]:
|
||||
"""Resolve the reply-language instruction for the chat loop, or None.
|
||||
|
||||
@@ -249,14 +275,19 @@ def reply_language_directive(
|
||||
1. An explicit ``output_language`` lock wins — the deployment serves a
|
||||
single language and owns a TTS voice that can speak it (e.g. Korean
|
||||
MeloTTS). This intentionally overrides the English-only fallback.
|
||||
2. Otherwise, a Piper/Chatterbox TTS engine can only synthesise English,
|
||||
2. Otherwise, a ``default_language`` (the v2 brain: Korean) is used unless
|
||||
the user explicitly asks for another language.
|
||||
3. Otherwise, a Piper/Chatterbox TTS engine can only synthesise English,
|
||||
so force English to avoid garbled audio.
|
||||
3. Otherwise (multilingual TTS, no lock) → None: the assistant replies in
|
||||
4. Otherwise (multilingual TTS, no lock) → None: the assistant replies in
|
||||
the user's own language.
|
||||
"""
|
||||
forced = output_language_directive(output_language)
|
||||
if forced:
|
||||
return forced
|
||||
default = default_language_directive(default_language)
|
||||
if default:
|
||||
return default
|
||||
if (tts_engine or "piper").strip().lower() in _TTS_ENGLISH_ONLY:
|
||||
return ENGLISH_ONLY_DIRECTIVE
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user