fix(telegram): tell models to use <tg-math> for rich-text formulas (#97197)

* fix(telegram): tell models to use <tg-math> 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 <tg-math> (inline) and
<tg-math-block> (block) tags with raw LaTeX inside. Spell that out in the
hint, matching the existing HTML-tag style used for <sup>/<mark>/<details>.

* test(telegram): assert math rich-text prompt hint

---------

Co-authored-by: wangwllu <wangwllu@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
Lu Wang
2026-06-29 02:33:38 +08:00
committed by GitHub
parent 881ec2f93f
commit 168299fc7d
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -1023,6 +1023,9 @@ describe("buildAgentSystemPrompt", () => {
expect(telegramPrompt).toContain("pull quotes");
expect(telegramPrompt).toContain('task lists via `<input type="checkbox"/>` inside `<li>`');
expect(telegramPrompt).toContain("anchors/in-message links");
expect(telegramPrompt).toContain(
"formulas (inline `<tg-math>LaTeX</tg-math>`, block `<tg-math-block>LaTeX</tg-math-block>`; not `$...$` or `\\(...\\)`)",
);
expect(telegramPrompt).toContain("maps/collages/slideshows");
expect(telegramPrompt).toContain("use `<details>`, not legacy `<blockquote expandable>`");
expect(telegramPrompt).toContain("use `<ul><li>...</li></ul>`, not literal bullet characters");
+1 -1
View File
@@ -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, `<details><summary>...</summary>...</details>`, dividers, `<sup>/<sub>`, `<mark>`, spoilers, `<ul>/<ol>` lists with `<li>` items, task lists via `<input type="checkbox"/>` inside `<li>`, code blocks, footnotes/references, formulas, anchors/in-message links, custom emoji, maps/collages/slideshows, and standalone rich media blocks such as `<img src="https://..."/>`. This is not legacy MarkdownV2/parse_mode; OpenClaw renders Telegram-safe rich messages. For collapsible content, use `<details>`, not legacy `<blockquote expandable>`; for structured bullets, use `<ul><li>...</li></ul>`, 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, `<details><summary>...</summary>...</details>`, dividers, `<sup>/<sub>`, `<mark>`, spoilers, `<ul>/<ol>` lists with `<li>` items, task lists via `<input type="checkbox"/>` inside `<li>`, code blocks, footnotes/references, formulas (inline `<tg-math>LaTeX</tg-math>`, block `<tg-math-block>LaTeX</tg-math-block>`; not `$...$` or `\\(...\\)`), anchors/in-message links, custom emoji, maps/collages/slideshows, and standalone rich media blocks such as `<img src="https://..."/>`. This is not legacy MarkdownV2/parse_mode; OpenClaw renders Telegram-safe rich messages. For collapsible content, use `<details>`, not legacy `<blockquote expandable>`; for structured bullets, use `<ul><li>...</li></ul>`, 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)",