feat: add text debounce batching for WhatsApp and WeChat platforms - #35302
Closed
redpiggy-cyber wants to merge 1 commit into
Closed
feat: add text debounce batching for WhatsApp and WeChat platforms#35302redpiggy-cyber wants to merge 1 commit into
redpiggy-cyber wants to merge 1 commit into
Conversation
WhatsApp and WeChat (Weixin/iLink) both deliver messages individually without any client-side batching, so rapid multi-message bursts (forwarded batches, paste-splits, etc.) each trigger a separate agent invocation. This wastes tokens (redundant system prompts / context for each fragment) and degrades UX (the user receives reply fragments instead of a single coherent response). Both adapters now mirror the Telegram adapter's proven text-debounce pattern: - _text_batch_delay_seconds / _text_batch_split_delay_seconds (configurable via env vars) - _pending_text_batches dict for per-session aggregation - _enqueue_text_event() concatenates successive TEXT messages and resets the flush timer - _flush_text_batch() dispatches after the quiet period expires Configurable via env vars: HERMES_WHATSAPP_TEXT_BATCH_DELAY_SECONDS (default 5.0) HERMES_WHATSAPP_TEXT_BATCH_SPLIT_DELAY_SECONDS (default 10.0) HERMES_WEIXIN_TEXT_BATCH_DELAY_SECONDS (default 3.0) HERMES_WEIXIN_TEXT_BATCH_SPLIT_DELAY_SECONDS (default 5.0)
Collaborator
Contributor
|
Merged via PR #35391 (commit cddb728). Your debounce commit was cherry-picked onto current main with your authorship preserved in git log (b0ce47d). One change on top of your work: per our " |
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #35301
Summary
WhatsApp and WeChat (Weixin/iLink) deliver messages individually without client-side batching. Rapid multi-message bursts each trigger a separate agent invocation, wasting tokens and degrading UX.
This PR adds text-debounce batching to both adapters, mirroring the pattern already used by the Telegram, WeCom, and Feishu adapters.
Changes
gateway/platforms/whatsapp.py(+78 / -1)_text_batch_delay_seconds,_text_batch_split_delay_seconds,_pending_text_batches,_pending_text_batch_tasksto__init___poll_messages()to route TEXT messages through_enqueue_text_event()instead of directly callinghandle_message()_text_batch_key(),_enqueue_text_event(),_flush_text_batch()methodsgateway/platforms/weixin.py(+87 / -8)__init__disconnect()_process_message()to route TEXT messages through debounce_text_batch_key(),_enqueue_text_event(),_flush_text_batch()methodsConfiguration (env vars)
HERMES_WHATSAPP_TEXT_BATCH_DELAY_SECONDSHERMES_WHATSAPP_TEXT_BATCH_SPLIT_DELAY_SECONDSHERMES_WEIXIN_TEXT_BATCH_DELAY_SECONDSHERMES_WEIXIN_TEXT_BATCH_SPLIT_DELAY_SECONDSBehavior