Skip to content

fix(telegram): surface message.quote (selected fragment) in agent context - #70631

Closed
stefrogovskyi wants to merge 1 commit into
NousResearch:mainfrom
stefrogovskyi:feat/telegram-quote-injected-to-agent-context
Closed

fix(telegram): surface message.quote (selected fragment) in agent context#70631
stefrogovskyi wants to merge 1 commit into
NousResearch:mainfrom
stefrogovskyi:feat/telegram-quote-injected-to-agent-context

Conversation

@stefrogovskyi

Copy link
Copy Markdown

What

Telegram delivers a native partial quote in message.quote when a user replies to a selected substring of a prior message. Hermes previously only surfaced this in reply metadata (reply_to_text), so the agent could not see which fragment the user was responding to — it only saw the whole replied-to message or nothing.

This injects the quoted fragment into event.text (with a clear marker) so the agent answers on the substance of the quoted text.

Where

plugins/platforms/telegram/adapter.py_handle_text_message, right after event.text = self._clean_bot_trigger_text(event.text).

Why minimal

  • Scoped to text messages only (no change to command/reply paths beyond visibility).
  • Does not mutate prompt caching or role alternation — it only enriches the inbound user text, which is already rebuilt per message.
  • Preserves existing reply_to_text extraction (used elsewhere for attribution); this is additive.

Behavior

When a user quotes a fragment and asks a question, the agent now receives:

<user text>
[ПОЛЬЗОВАТЕЛЬ ПРОЦИТИРОВАЛ ФРАГМЕНТ:
«<quoted text>»
— отвечай ПО СУТИ этого фрагмента.]

(The marker is operator-localized; happy to make it configurable / English if preferred.)

Test

  • Reply to a selected substring of a prior message in Telegram → agent sees the quoted fragment and answers on it.
  • Plain reply without a quote → unchanged.
  • Command message → unchanged.

Fixes a reported operator bug: agent was blind to quoted/selected text in Telegram.

…gent context

Telegram delivers a native partial quote in message.quote when a user replies
to a selected substring of a prior message. Hermes previously only surfaced
this in reply metadata (reply_to_text), so the agent could not see what
fragment the user was responding to. Inject the quote text into event.text
with a clear marker so the agent answers on the quoted fragment's substance.

- _handle_text_message: after _clean_bot_trigger_text, read msg.quote.text
  and prepend a [ПОЛЬЗОВАТЕЛЬ ПРОЦИТИРОВАЛ ФРАГМЕНТ: ...] marker to event.text
- minimal, scoped to text messages only; does not affect replies/commands path
  beyond making the quoted fragment visible to the agent

Fixes: agent blind to quoted/selected text in Telegram (reported by operator).
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter labels Jul 24, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused Telegram report and implementation.

Automated hermes-sweeper review found that current main already provides this behavior:

  • plugins/platforms/telegram/adapter.py:9623-9637 prefers message.quote.text for a native selected-substring reply instead of using the full replied-to message. This shipped in 854c2ce309 (fix(telegram): honor message.quote for partial-quote reply context).
  • gateway/run.py:15286-15300 injects that reply_to_text into the agent-visible inbound user message as [Replying to: "..."]; this behavior was added in e889332c99.
  • Existing regression coverage is present in tests/gateway/test_telegram_reply_quote.py:78-94 and tests/gateway/test_reply_to_injection.py:39-60.

The proposed addition would surface the same selected fragment a second time with an extra localized marker, so this PR is superseded by main.

@teknium1 teknium1 closed this Jul 30, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants