Skip to content

fix(whatsapp): forward reply context from bridge to agent - #44681

Closed
anand-agastya wants to merge 1 commit into
NousResearch:mainfrom
anand-agastya:whatsapp-reply-context
Closed

fix(whatsapp): forward reply context from bridge to agent#44681
anand-agastya wants to merge 1 commit into
NousResearch:mainfrom
anand-agastya:whatsapp-reply-context

Conversation

@anand-agastya

Copy link
Copy Markdown

Problem

When a user replies to a WhatsApp message (using WhatsApp's built-in reply feature), the agent receives only the new message text with no information about which prior message the user is referencing. The agent has to guess the context.

Solution

The WhatsApp bridge (bridge.js) already captures quotedMessageId, quotedMessageText, hasQuotedMessage, quotedParticipant, and quotedRemoteJid from Baileys contextInfo and includes them in every event. However, _build_message_event() in whatsapp.py never forwarded these to the MessageEvent.

The core MessageEvent class (base.py lines 1318-1319) already defines reply_to_message_id and reply_to_text fields, and the message handler in run.py (lines 8286-8294) already injects reply context into the agent prompt when these fields are set.

This PR adds the two missing lines to wire the bridge data into the existing infrastructure.

Changes

gateway/platforms/whatsapp.py — +2 lines in _build_message_event():

  • reply_to_message_id=data.get("quotedMessageId")
  • reply_to_text=data.get("quotedMessageText")

Impact

When a user replies to a message on WhatsApp, the agent now sees:
[Replying to: "the quoted text"]
prepended to their message. No other platform is affected — Telegram/Discord already populate these fields through their own adapters.

The WhatsApp bridge already captures quotedMessageId, quotedMessageText,
hasQuotedMessage, quotedParticipant, and quotedRemoteJid from Baileys
contextInfo. However, _build_message_event() never forwarded these to
the MessageEvent.

The core MessageEvent class already defines reply_to_message_id and
reply_to_text fields (gateway/platforms/base.py:1318-1319), and the
message handler in gateway/run.py already injects reply context into
the agent prompt when these fields are set (line 8286-8294).

This is a 2-line change that wires up the existing bridge data to the
existing infrastructure. When a user replies to a message on WhatsApp,
the agent now sees: [Replying to: "the quoted text"]
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/whatsapp WhatsApp Business adapter duplicate This issue or pull request already exists labels Jun 12, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #16552 (earliest open PR for the same fix). Both populate MessageEvent.reply_to_message_id/reply_to_text from the bridge's quotedMessageId/quotedMessageText in whatsapp.py. Same quoted-reply gap as #44614/#28878/#28823. Linking for reviewer consolidation.

@sukritgoyal

Copy link
Copy Markdown

Hey @alt-glitch and maintainers, can I be assigned on this issue?

@anand-agastya

Copy link
Copy Markdown
Author

Closing in favor of #16552 which already covers both bridge.js and whatsapp.py changes plus tests. We've confirmed the approach works in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants