The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): read Telegram rich_messages config from correct path
bex9f582aca1d15
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex aee2670be62..5309c725521 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -954,7 +954,8 @@ PLATFORM_HINTS = {}# Telegram rich-messages extension — only injected when the user has opted in-# to ``platforms.telegram.extra.rich_messages: true``. The base+# to ``gateway.platforms.telegram.extra.rich_messages: true`` (or the+# top-level ``platforms.telegram.extra.rich_messages``). The base# PLATFORM_HINTS["telegram"] covers MarkdownV2-compatible constructs; this# extension adds the Bot API 10.1 rich-Markdown guidance (tables, task lists,# collapsible details, math, etc.).diff --git a/agent/system_prompt.py b/agent/system_prompt.pyindex 8407a896893..e89760b8a64 100644--- a/agent/system_prompt.py+++ b/agent/system_prompt.py@@ -445,18 +445,22 @@ def build_system_prompt_parts(agent: Any, system_message: Optional[str] = None)pass# For Telegram: append the rich-messages extension only when the user has- # opted in to ``platforms.telegram.extra.rich_messages: true``. The base- # hint covers MarkdownV2-compatible constructs; the extension adds Bot API- # 10.1 guidance (tables, task lists, math, collapsible details, etc.).+ # opted in to ``gateway.platforms.telegram.extra.rich_messages: true``+ # (the canonical location the adapter reads from). Merge with the+ # top-level ``platforms.telegram.extra`` so config-wizard writes and+ # dashboard-setup keys are also visible — same precedence the adapter+ # uses: top-level platform overrides gateway.platforms at the leaf.if platform_key == "telegram" and _default_hint:try:from hermes_cli.config import load_config_readonly_cfg = load_config_readonly()- _tg_extra = ((_cfg.get("platforms") or {}).get("telegram") or {}).get("extra") or {}+ _gw_tg_extra = (((_cfg.get("gateway") or {}).get("platforms") or {}).get("telegram") or {}).get("extra") or {}+ _top_tg_extra = ((_cfg.get("platforms") or {}).get("telegram") or {}).get("extra") or {}+ _tg_extra = {**_gw_tg_extra, **_top_tg_extra}if _tg_extra.get("rich_messages"):_default_hint = _default_hint.rstrip() + " " + TELEGRAM_RICH_MESSAGES_HINT- except Exception:- pass # Config read failure — fall back to base hint only+ except ImportError:+ pass # Config module not available — fall back to base hint only_effective_hint = _resolve_platform_hint(agent, platform_key, _default_hint)if platform_key == "tui" and _effective_hint:diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.pyindex 2f0a4271764..11f1030e663 100644--- a/tests/agent/test_system_prompt.py+++ b/tests/agent/test_system_prompt.py@@ -189,35 +189,66 @@ class TestTelegramRichMessagesHint:"""Verify that TELEGRAM_RICH_MESSAGES_HINT is conditionally included."""def test_base_hint_without_rich_messages(self, monkeypatch):- """When rich_messages is False (default), only the base hint is used."""+ """When rich_messages is False, only the base hint is used."""agent = _make_agent(platform="telegram")- # Mock config to return rich_messages: false (default)with patch("hermes_cli.config.load_config_readonly") as mock_cfg:mock_cfg.return_value = {- "platforms": {"telegram": {"extra": {"rich_messages": False}}}+ "gateway": {"platforms": {"telegram": {"extra": {"rich_messages": False}}}}}stable = _stable_prompt(agent)- # Base hint should be presentassert "Standard Markdown is automatically converted" in stable- # Rich-messages extension should NOT be presentassert "lean into it" not in stableassert "task lists" not in stabledef test_rich_hint_with_rich_messages_enabled(self, monkeypatch):- """When rich_messages is True, the rich-messages extension is appended."""+ """When rich_messages is True in gateway.platforms, the extension+ is appended (the canonical/primary location)."""agent = _make_agent(platform="telegram")with patch("hermes_cli.config.load_config_readonly") as mock_cfg:mock_cfg.return_value = {- "platforms": {"telegram": {"extra": {"rich_messages": True}}}+ "gateway": {"platforms": {"telegram": {"extra": {"rich_messages": True}}}}}stable = _stable_prompt(agent)- # Base hint should be present- assert "Standard Markdown is automatically converted" in stable- # Rich-messages extension should be presentassert "lean into it" in stableassert "task lists" in stableassert "math/formulas" in stable+ def test_rich_hint_from_top_level_platforms(self):+ """Top-level ``platforms.telegram.extra.rich_messages`` is merged+ alongside gateway.platforms, so it works on its own."""+ agent = _make_agent(platform="telegram")+ with patch("hermes_cli.config.load_config_readonly") as mock_cfg:+ mock_cfg.return_value = {+ "platforms": {"telegram": {"extra": {"rich_messages": True}}}+ }+ stable = _stable_prompt(agent)+ assert "lean into it" in stable+ assert "task lists" in stable++ def test_top_level_overrides_gateway_rich_messages(self):+ """Top-level ``platforms.telegram.extra`` wins over gateway.platforms+ at the leaf, matching the adapter's merge precedence."""+ agent = _make_agent(platform="telegram")+ with patch("hermes_cli.config.load_config_readonly") as mock_cfg:+ mock_cfg.return_value = {+ "gateway": {"platforms": {"telegram": {"extra": {"rich_messages": False}}}},+ "platforms": {"telegram": {"extra": {"rich_messages": True}}},+ }+ stable = _stable_prompt(agent)+ assert "lean into it" in stable++ def test_gateway_extra_other_keys_does_not_block_top_level_rich_messages(self):+ """When gateway.platforms.telegram.extra has other keys but not+ rich_messages, the top-level rich_messages still activates."""+ agent = _make_agent(platform="telegram")+ with patch("hermes_cli.config.load_config_readonly") as mock_cfg:+ mock_cfg.return_value = {+ "gateway": {"platforms": {"telegram": {"extra": {"disable_link_previews": True}}}},+ "platforms": {"telegram": {"extra": {"rich_messages": True}}},+ }+ stable = _stable_prompt(agent)+ assert "lean into it" in stable+def test_base_hint_without_config(self, monkeypatch):"""When config has no telegram section, only base hint is used."""agent = _make_agent(platform="telegram")