The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(onboarding): greet and ask the name in the user's locale
alt-glitch219a9fb42f31
diff --git a/agent/onboarding_text.py b/agent/onboarding_text.pyindex fae2797f61c..480ec07094e 100644--- a/agent/onboarding_text.py+++ b/agent/onboarding_text.py@@ -20,6 +20,55 @@ from tools.set_theme_tool import ACCENT_SWATCHESCHAT_TITLE = "Getting started"GREETING = "Hi, I'm Hermes. Let's set things up for you. Then we'll get something cool done."+# The scripted opening in each desktop UI language (apps/desktop/src/i18n/languages.ts), played before+# the model speaks; the model writes the rest of the run in the user's language itself. Each greeting+# is the desktop's first-run intro copy (firstRun.intro in apps/desktop/src/i18n/*_first_run.ts), its+# two lines joined: keep the two equal.+_GREETINGS = {+ "en": GREETING,+ "ar": "مرحبًا، أنا Hermes. لنجهّز كل شيء لك، ثم ننجز معًا شيئًا رائعًا.",+ "de": "Hallo, ich bin Hermes. Richten wir alles für Sie ein. Danach machen wir etwas Cooles.",+ "es": "Hola, soy Hermes. Vamos a dejarlo todo listo para ti. Luego haremos algo genial.",+ "fr": "Bonjour, je suis Hermes. Configurons tout pour vous. Ensuite, nous ferons quelque chose de génial.",+ "ja": "こんにちは、Hermes です。まずはあなたに合わせて設定しましょう。そのあと、何かすごいものを作りましょう。",+ "ru": "Привет, я Hermes. Давайте всё настроим под вас. А потом сделаем что-нибудь классное.",+ "zh": "你好,我是 Hermes。我们先帮你把一切设置好,然后一起做点很酷的事。",+ "zh-hant": "你好,我是 Hermes。我們先幫你把一切設定好,然後一起做點很酷的事。",+}++_NAME_QUESTIONS = {+ "ar": "بماذا أناديك؟",+ "de": "Wie darf ich Sie nennen?",+ "es": "¿Cómo quieres que te llame?",+ "fr": "Comment dois-je vous appeler ?",+ "ja": "なんとお呼びすればいいですか?",+ "ru": "Как к вам обращаться?",+ "zh": "我该怎么称呼你?",+ "zh-hant": "我該怎麼稱呼你?",+}++_TRADITIONAL_CHINESE = {"hant", "tw", "hk", "mo"}+++def ui_language(locale: str | None) -> str:+ """A locale (``zh-hant``, ``de-DE``, ``zh_TW``) as the desktop language it reads in; English when+ none fits."""+ tags = (locale or "").strip().lower().replace("_", "-").split("-")+ if tags[0] == "zh":+ return "zh-hant" if _TRADITIONAL_CHINESE.intersection(tags[1:]) else "zh"+ return tags[0] if tags[0] in _GREETINGS else "en"+++def greeting(locale: str | None) -> str:+ return _GREETINGS[ui_language(locale)]+++def question(beat: str, locale: str | None) -> str:+ """The card's own question; the name card asks in the user's language."""+ if beat == "name":+ return _NAME_QUESTIONS.get(ui_language(locale), QUESTIONS["name"])+ return QUESTIONS[beat]+QUESTIONS = {"name": "What should I call you?","theme": "Pick a colour.",diff --git a/tests/tui_gateway/test_onboarding_session.py b/tests/tui_gateway/test_onboarding_session.pyindex 0de3c4905e9..ddf7c1a652f 100644--- a/tests/tui_gateway/test_onboarding_session.py+++ b/tests/tui_gateway/test_onboarding_session.py@@ -144,6 +144,29 @@ def test_the_opening_plays_the_greeting_and_name_card_until_the_name_card_was_shassert server._onboarding_prelude(SimpleNamespace(valid_tool_names={"terminal"}), []) is None[email protected]("locale, opens_with, asks", [+ ("de", "Hallo, ich bin Hermes.", "Wie darf ich Sie nennen?"),+ ("zh_TW", "你好,我是 Hermes。我們", "我該怎麼稱呼你?"),+ ("ja-JP", "こんにちは、Hermes です。", "なんとお呼びすればいいですか?"),+ ("tlh", GREETING, "What should I call you?"),+ (None, GREETING, "What should I call you?"),+])+def test_the_opening_greets_and_asks_the_name_in_the_run_s_locale(root, locale, opens_with, asks):+ from tools.setup_beat_tool import setup_beat_tool++ db = server._get_db()+ db.create_session("onb", "desktop")+ onboarding_record.start(db, "onb", Facts(os="macos", locale=locale))+ agent = _agent(db)++ [(hello, tool, args)] = list(server._onboarding_prelude(agent, []))+ assert hello.startswith(opens_with) and (tool, args) == ("setup_beat", {"beat": "name"})+ assert next(iter(server._onboarding_prelude(agent, [{"role": "assistant", "content": hello}])))[0] == ""+ shown = []+ setup_beat_tool(args, db=db, session_id="onb", callback=lambda payload: shown.append(payload) or None)+ assert shown[0]["question"] == asks++def test_the_turn_note_rides_a_user_turn_only_while_the_run_is_open(root):db = server._get_db()db.create_session("onb", "desktop")diff --git a/tools/setup_beat_tool.py b/tools/setup_beat_tool.pyindex 8b6e21cdbe3..fb5d6976abb 100644--- a/tools/setup_beat_tool.py+++ b/tools/setup_beat_tool.py@@ -14,7 +14,8 @@ from collections.abc import Callable, Mappingfrom typing import Anyfrom agent import onboarding_flow as flow-from agent.onboarding_text import QUESTIONS, finish_reminder, reminder+from agent.onboarding_text import finish_reminder, reminder+from agent.onboarding_text import question as beat_questionfrom tools.registry import registry, tool_errorlogger = logging.getLogger(__name__)@@ -131,7 +132,7 @@ def setup_beat_tool(args: Mapping[str, Any], *, db=None, session_id: str = "", tshown = records.advance(db, session_id, flow.Shown(beat, tool_call_id, args.get("options"), args.get("suggest")))if shown.result: # refused, or a beat this machine skipsreturn _result(shown)- question = str(args.get("question") or "").strip() or QUESTIONS[beat]+ question = str(args.get("question") or "").strip() or beat_question(beat, (record.get("facts") or {}).get("locale"))reply = callback({"beat": beat, "question": question, "card": _card(beat, shown, args),"tool_call_id": tool_call_id or None})after = records.load(db, session_id)diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.pyindex 4463198c1af..ef95db971bd 100644--- a/tui_gateway/methods_onboarding.py+++ b/tui_gateway/methods_onboarding.py@@ -251,16 +251,17 @@ def _onboarding_prelude(agent, history: list):greeting already in the chat (a relaunch) is not said twice."""from agent.onboarding_flow import PENDING, is_activefrom agent.onboarding_record import load- from agent.onboarding_text import GREETING+ from agent.onboarding_text import greetingif not _builds_onboarding(agent):return Nonerecord = load(agent._session_db, agent.session_id)if not is_active(record) or record["beats"]["name"] != PENDING:return None- said = any(m.get("role") == "assistant" and m.get("content") == GREETING for m in history)+ hello = greeting((record.get("facts") or {}).get("locale"))+ said = any(m.get("role") == "assistant" and m.get("content") == hello for m in history)def opening():- yield ("" if said else GREETING), "setup_beat", {"beat": "name"}+ yield ("" if said else hello), "setup_beat", {"beat": "name"}return opening()