mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
fix(telegram): honor message.quote for partial-quote reply context
When a Telegram user replies using the native quote feature to select only part of a prior message, _build_message_event was injecting the ENTIRE replied-to message into reply_to_text via message.reply_to_message.text/caption. python-telegram-bot exposes the user-selected substring as message.quote (TextQuote.text); we now prefer that and fall back to the full replied-to text only when no native quote is present. The agent-visible "[Replying to: \"...\"]" prefix can otherwise expand the user's narrow quote into the full prior message, causing the agent to act on unrelated actionable-looking text the user did not select (e.g. multi-item briefings where the user quotes one bullet but the prefix injects every bullet). Falls back cleanly when message.quote is absent (PTB <21 or replies that don't quote a substring). Fixes #22619 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
78b8155ecb
commit
854c2ce309
2 changed files with 162 additions and 2 deletions
|
|
@ -4026,12 +4026,28 @@ class TelegramAdapter(BasePlatformAdapter):
|
|||
chat_topic=chat_topic,
|
||||
)
|
||||
|
||||
# Extract reply context if this message is a reply
|
||||
# Extract reply context if this message is a reply.
|
||||
# Prefer Telegram's native partial quote (message.quote, TextQuote)
|
||||
# so a user replying to a single selected substring of a prior
|
||||
# multi-section message doesn't get the whole replied-to message
|
||||
# injected into the agent's context — which can cause the agent
|
||||
# to act on unrelated actionable-looking text the user didn't
|
||||
# quote (#22619). Fall back to the full replied-to message text
|
||||
# / caption when no native quote is present.
|
||||
reply_to_id = None
|
||||
reply_to_text = None
|
||||
if message.reply_to_message:
|
||||
reply_to_id = str(message.reply_to_message.message_id)
|
||||
reply_to_text = message.reply_to_message.text or message.reply_to_message.caption or None
|
||||
quote = getattr(message, "quote", None)
|
||||
quote_text = getattr(quote, "text", None) if quote is not None else None
|
||||
if quote_text:
|
||||
reply_to_text = quote_text
|
||||
else:
|
||||
reply_to_text = (
|
||||
message.reply_to_message.text
|
||||
or message.reply_to_message.caption
|
||||
or None
|
||||
)
|
||||
|
||||
# Per-channel/topic ephemeral prompt
|
||||
from gateway.platforms.base import resolve_channel_prompt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue