From 168299fc7d9ee141fa5fde694119ef9ed855a359 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Mon, 29 Jun 2026 02:33:38 +0800 Subject: [PATCH] fix(telegram): tell models to use for rich-text formulas (#97197) * fix(telegram): tell models to use for rich-text formulas The Telegram rich-text capability hint advertised 'formulas' without specifying syntax. Models (especially fallback models) default to $...$ or \(...\) LaTeX delimiters, which Telegram Bot API 10.1 rich messages do not render as math, so formulas appear as literal text. Telegram Bot API 10.1 renders formulas only via (inline) and (block) tags with raw LaTeX inside. Spell that out in the hint, matching the existing HTML-tag style used for //
. * test(telegram): assert math rich-text prompt hint --------- Co-authored-by: wangwllu Co-authored-by: Vincent Koc --- src/agents/system-prompt.test.ts | 3 +++ src/agents/system-prompt.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/agents/system-prompt.test.ts b/src/agents/system-prompt.test.ts index 5e7f3c6016e7..63f146f25d96 100644 --- a/src/agents/system-prompt.test.ts +++ b/src/agents/system-prompt.test.ts @@ -1023,6 +1023,9 @@ describe("buildAgentSystemPrompt", () => { expect(telegramPrompt).toContain("pull quotes"); expect(telegramPrompt).toContain('task lists via `` inside `
  • `'); expect(telegramPrompt).toContain("anchors/in-message links"); + expect(telegramPrompt).toContain( + "formulas (inline `LaTeX`, block `LaTeX`; not `$...$` or `\\(...\\)`)", + ); expect(telegramPrompt).toContain("maps/collages/slideshows"); expect(telegramPrompt).toContain("use `
    `, not legacy `
    `"); expect(telegramPrompt).toContain("use `
    • ...
    `, not literal bullet characters"); diff --git a/src/agents/system-prompt.ts b/src/agents/system-prompt.ts index 6667120ba4f6..337dcc56cd6c 100644 --- a/src/agents/system-prompt.ts +++ b/src/agents/system-prompt.ts @@ -527,7 +527,7 @@ function buildMessagingSection(params: { : "- Reply in current session → automatically routes to the source channel (Signal, Telegram, etc.)", telegramRuntime ? telegramRichTextEnabled - ? '- Telegram rich text is available. Use Bot API 10.1 rich formatting in visible message text when it improves clarity: headings, tables with alignment/captions/spans, blockquotes, pull quotes, `
    ......
    `, dividers, `/`, ``, spoilers, `
      /
        ` lists with `
      1. ` items, task lists via `` inside `
      2. `, code blocks, footnotes/references, formulas, anchors/in-message links, custom emoji, maps/collages/slideshows, and standalone rich media blocks such as ``. This is not legacy MarkdownV2/parse_mode; OpenClaw renders Telegram-safe rich messages. For collapsible content, use `
        `, not legacy `
        `; for structured bullets, use `
        • ...
        `, not literal bullet characters. Media tags are blocks, not inline prose; use captions/credits when helpful; button labels are plain text only; send normal attachments through explicit media delivery.' + ? '- Telegram rich text is available. Use Bot API 10.1 rich formatting in visible message text when it improves clarity: headings, tables with alignment/captions/spans, blockquotes, pull quotes, `
        ......
        `, dividers, `/`, ``, spoilers, `
          /
            ` lists with `
          1. ` items, task lists via `` inside `
          2. `, code blocks, footnotes/references, formulas (inline `LaTeX`, block `LaTeX`; not `$...$` or `\\(...\\)`), anchors/in-message links, custom emoji, maps/collages/slideshows, and standalone rich media blocks such as ``. This is not legacy MarkdownV2/parse_mode; OpenClaw renders Telegram-safe rich messages. For collapsible content, use `
            `, not legacy `
            `; for structured bullets, use `
            • ...
            `, not literal bullet characters. Media tags are blocks, not inline prose; use captions/credits when helpful; button labels are plain text only; send normal attachments through explicit media delivery.' : "- Telegram rich messages are disabled for this bot/account. Do not claim Bot API 10.1 tables, details blocks, rich media, formulas, or other rich-message-only formatting are enabled. Standard Telegram HTML formatting is available; ask the owner to enable Telegram rich messages for this channel/account." : "", "- Cross-session messaging → use sessions_send(sessionKey, message)",