Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10369,20 +10369,25 @@ async def _prepare_inbound_message_text(
)

if getattr(event, "reply_to_text", None) and event.reply_to_message_id:
# Always inject the reply-to pointer — even when the quoted text
# already appears in history. The prefix isn't deduplication, it's
# disambiguation: it tells the agent *which* prior message the user
# is referencing. History can contain the same or similar text
# multiple times, and without an explicit pointer the agent has to
# guess (or answer for both subjects). Token overhead is minimal.
# Inject reply context as a structured system-level note rather than
# a plain text prefix. The model is much more likely to respect a
# directive block with explicit framing than a bare "[Replying to:]"
# prefix buried in the user message.
reply_snippet = event.reply_to_text[:500]
if getattr(event, "reply_to_is_own_message", False):
message_text = (
f'[Replying to your previous message: "{reply_snippet}"]\n\n'
f'[System Note: You are being prompted about your own previous message]\n'
f'[Your previous message: "{reply_snippet}"]\n'
f'[Prioritize this message as the primary context for your response.]\n\n'
f"{message_text}"
)
else:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still text prepended to message_text, not a separate system-role note: current main passes the prepared value as the normal message to _run_agent (gateway/run.py:11759). Please either describe this accurately as stronger user-message framing or implement the intended structured mechanism.

message_text = f'[Replying to: "{reply_snippet}"]\n\n{message_text}'
message_text = (
f'[System Note: The user is replying to the following message from the conversation]\n'
f'[Replied message: "{reply_snippet}"]\n'
f'[Prioritize this message as the primary context for your response.]\n\n'
f'{message_text}'
)

if "@" in message_text:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shared inbound-preparation branch has no Telegram guard. Signal, WhatsApp Cloud, and Yuanbao also set reply_to_text, so this wording changes their reply-context semantics as well. Scope it explicitly or update the PR scope and coverage.

try:
Expand Down
Loading