Skip to content

The agent that grows with you

fix(whatsapp,weixin): text-batch delays default to Telegram cadence

kshitijk4poor130b596f6f2f
diff --git a/gateway/platforms/weixin.py b/gateway/platforms/weixin.py
index c338b14d0de..540da6f4981 100644
--- a/gateway/platforms/weixin.py
+++ b/gateway/platforms/weixin.py
@@ -725,23 +725,26 @@ class WeixinAdapter(OwnAccessPolicyMixin, BasePlatformAdapter):
self._group_allow_from = self._coerce_list(_wx_secret("WEIXIN_GROUP_ALLOWED_USERS", "") if group_allow_from is None else group_allow_from)
self._split_multiline_messages = _coerce_bool(_extra_or_secret(extra, "split_multiline_messages", ""), default=False)
# Text debounce batching (Telegram pattern): iLink delivers messages individually, so rapid bursts would each
- # trigger a separate agent run. 3s / 5s (after a ~2048-char split chunk) suit iLink's cadence.
- self._text_batch_delay_seconds = self._coerce_float_extra("text_batch_delay_seconds", 3.0)
- self._text_batch_split_delay_seconds = self._coerce_float_extra("text_batch_split_delay_seconds", 5.0)
+ # trigger a separate agent run. Telegram cadence and ceilings (#44883); ``0`` dispatches immediately.
+ self._text_batch_delay_seconds = self._coerce_float_extra("text_batch_delay_seconds", 0.3, max_value=2.0)
+ self._text_batch_split_delay_seconds = self._coerce_float_extra(
+ "text_batch_split_delay_seconds", 1.0, min_value=self._text_batch_delay_seconds, max_value=4.0)
persisted = load_weixin_account(hermes_home, self._account_id) if self._account_id and not self._token else None
if persisted:
self._token = str(persisted.get("token") or "").strip()
self._base_url = str(persisted.get("base_url") or self._base_url).strip().rstrip("/")
- def _coerce_float_extra(self, key: str, default: float) -> float:
- """Float from ``config.extra``; fed to ``asyncio.sleep()``, so NaN/Inf/negative/unparseable → default."""
+ def _coerce_float_extra(self, key: str, default: float, *, min_value: float = 0.0, max_value: Optional[float] = None) -> float:
+ """Float from ``config.extra``; fed to ``asyncio.sleep()``, so NaN/Inf/negative/unparseable → default; clamped."""
import math
value = (self.config.extra or {}).get(key)
try:
parsed = float(value) if value is not None else float(default)
except (TypeError, ValueError):
- return float(default)
- return parsed if math.isfinite(parsed) and parsed >= 0 else float(default)
+ parsed = float(default)
+ if not math.isfinite(parsed) or parsed < 0:
+ parsed = float(default)
+ return min(max(parsed, min_value), max_value) if max_value is not None else max(parsed, min_value)
@staticmethod
def _coerce_list(value: Any) -> List[str]:
diff --git a/plugins/platforms/whatsapp/adapter.py b/plugins/platforms/whatsapp/adapter.py
index 2e729fd29ba..9a8faa6fa24 100644
--- a/plugins/platforms/whatsapp/adapter.py
+++ b/plugins/platforms/whatsapp/adapter.py
@@ -288,17 +288,21 @@ class WhatsAppAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):
# Set by disconnect() before SIGTERMing so _check_managed_bridge_exit() can tell an intentional exit (-15/-2/0) from a crash.
self._shutting_down = False
# Text debounce batching: rapid bursts (forwards, paste-splits) would otherwise each trigger a separate agent turn.
- self._text_batch_delay_seconds = self._coerce_float_extra("text_batch_delay_seconds", 5.0)
- self._text_batch_split_delay_seconds = self._coerce_float_extra("text_batch_split_delay_seconds", 10.0)
+ # Telegram cadence and ceilings (#44883); ``0`` dispatches each message immediately.
+ self._text_batch_delay_seconds = self._coerce_float_extra("text_batch_delay_seconds", 0.3, max_value=2.0)
+ self._text_batch_split_delay_seconds = self._coerce_float_extra(
+ "text_batch_split_delay_seconds", 1.0, min_value=self._text_batch_delay_seconds, max_value=4.0)
- def _coerce_float_extra(self, key: str, default: float) -> float:
- """Read a float from ``config.extra``; NaN/Inf/negative/unparseable → ``default`` (fed to asyncio.sleep)."""
+ def _coerce_float_extra(self, key: str, default: float, *, min_value: float = 0.0, max_value: Optional[float] = None) -> float:
+ """Read a float from ``config.extra``; NaN/Inf/negative/unparseable → ``default``; clamped (fed to asyncio.sleep)."""
import math
try: # float(None) → TypeError → default
parsed = float(self.config.extra.get(key) if getattr(self.config, "extra", None) else None)
except (TypeError, ValueError):
- return float(default)
- return parsed if math.isfinite(parsed) and parsed >= 0 else float(default)
+ parsed = float(default)
+ if not math.isfinite(parsed) or parsed < 0:
+ parsed = float(default)
+ return min(max(parsed, min_value), max_value) if max_value is not None else max(parsed, min_value)
def _bridge_url(self, path: str) -> str:
return f"http://127.0.0.1:{self._bridge_port}/{path}"
diff --git a/tests/gateway/test_whatsapp_text_batching.py b/tests/gateway/test_whatsapp_text_batching.py
index 2fb6c613fce..e58e46925c1 100644
--- a/tests/gateway/test_whatsapp_text_batching.py
+++ b/tests/gateway/test_whatsapp_text_batching.py
@@ -34,12 +34,21 @@ def _event(text):
def test_batch_delays_overridden_via_config_extra():
+ adapter = _make_adapter(
+ text_batch_delay_seconds="1.5",
+ text_batch_split_delay_seconds=3,
+ )
+ assert adapter._text_batch_delay_seconds == 1.5
+ assert adapter._text_batch_split_delay_seconds == 3.0
+
+
+def test_batch_delays_clamped_to_telegram_ceilings():
adapter = _make_adapter(
text_batch_delay_seconds="2.5",
text_batch_split_delay_seconds=7,
)
- assert adapter._text_batch_delay_seconds == 2.5
- assert adapter._text_batch_split_delay_seconds == 7.0
+ assert adapter._text_batch_delay_seconds == 2.0
+ assert adapter._text_batch_split_delay_seconds == 4.0
def test_invalid_config_value_falls_back_to_default():
@@ -47,7 +56,7 @@ def test_invalid_config_value_falls_back_to_default():
text_batch_delay_seconds="garbage",
text_batch_split_delay_seconds=-3,
)
- assert adapter._text_batch_delay_seconds == 5.0
- assert adapter._text_batch_split_delay_seconds == 10.0
+ assert adapter._text_batch_delay_seconds == 0.3
+ assert adapter._text_batch_split_delay_seconds == 1.0
diff --git a/website/docs/user-guide/messaging/weixin.md b/website/docs/user-guide/messaging/weixin.md
index eb23c084262..09a9e1c8d42 100644
--- a/website/docs/user-guide/messaging/weixin.md
+++ b/website/docs/user-guide/messaging/weixin.md
@@ -123,8 +123,8 @@ Set these in `config.yaml` under `platforms.weixin.extra`:
| `allow_from` | `[]` | User IDs allowed for DMs (when dm_policy=allowlist) |
| `group_allow_from` | `[]` | Group IDs allowed (when group_policy=allowlist) |
| `split_multiline_messages` | `false` | When `true`, split multi-line replies into multiple chat messages (legacy behavior). When `false`, keep multi-line replies as one message unless they exceed the length limit. |
-| `text_batch_delay_seconds` | `3.0` | Quiet period (seconds) before a buffered burst of rapid text messages is flushed as one combined request. iLink delivers messages individually, so this debounce avoids one agent invocation per fragment. Set `0` to dispatch each message immediately. |
-| `text_batch_split_delay_seconds` | `5.0` | Extended flush delay used when the latest fragment is near the split threshold (long messages iLink may have chunked). |
+| `text_batch_delay_seconds` | `0.3` | Quiet period (seconds) before a buffered burst of rapid text messages is flushed as one combined request. iLink delivers messages individually, so this debounce avoids one agent invocation per fragment. Set `0` to dispatch each message immediately. |
+| `text_batch_split_delay_seconds` | `1.0` | Extended flush delay used when the latest fragment is near the split threshold (long messages iLink may have chunked). |
## Access Policies
diff --git a/website/docs/user-guide/messaging/whatsapp.md b/website/docs/user-guide/messaging/whatsapp.md
index 60f4020e374..b2a85ef6279 100644
--- a/website/docs/user-guide/messaging/whatsapp.md
+++ b/website/docs/user-guide/messaging/whatsapp.md
@@ -238,7 +238,7 @@ All of this works out of the box in bot (Baileys) mode; no configuration needed.
### Message Batching (Debounce)
-WhatsApp delivers each message individually, so a rapid burst (forwarded batches, paste-splits, multi-line text) would otherwise trigger a separate agent invocation per fragment — wasting tokens and producing several disjointed replies. The adapter buffers successive text messages from the same chat and dispatches them as one combined request after a short quiet period (default **5s**, extended to **10s** for very long fragments). Tune via `config.yaml`:
+WhatsApp delivers each message individually, so a rapid burst (forwarded batches, paste-splits, multi-line text) would otherwise trigger a separate agent invocation per fragment — wasting tokens and producing several disjointed replies. The adapter buffers successive text messages from the same chat and dispatches them as one combined request after a short quiet period (default **0.3s**, extended to **1s** for very long fragments; capped at 2s / 4s). Tune via `config.yaml`:
```yaml
# ~/.hermes/config.yaml
@@ -246,8 +246,8 @@ gateway:
platforms:
whatsapp:
extra:
- text_batch_delay_seconds: 5.0 # quiet period before flushing a batch
- text_batch_split_delay_seconds: 10.0 # extended delay near the split threshold
+ text_batch_delay_seconds: 0.3 # quiet period before flushing a batch (max 2.0)
+ text_batch_split_delay_seconds: 1.0 # extended delay near the split threshold (max 4.0)
```
Set `text_batch_delay_seconds: 0` to dispatch each message immediately (disables batching).