From d33e436440d75914457cc6dea14322a403e2f012 Mon Sep 17 00:00:00 2001 From: liuwei53 Date: Fri, 10 Apr 2026 23:12:43 +0800 Subject: [PATCH 1/2] fix: guard against None request_overrides in _build_api_kwargs Fix AttributeError when self.request_overrides is None in gateway mode, causing UnboundLocalError on api_kwargs and breaking all messaging platform integrations (Weixin, Telegram, etc.). Line 5522 called .get() directly on self.request_overrides without null-checking. While __init__ initializes it as dict(), gateway mode may create AIAgent instances without passing request_overrides. --- run_agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_agent.py b/run_agent.py index 129eb16797a3e..83a497ddfdd5e 100644 --- a/run_agent.py +++ b/run_agent.py @@ -5519,7 +5519,7 @@ def _build_api_kwargs(self, api_messages: list) -> dict: preserve_dots=self._anthropic_preserve_dots(), context_length=ctx_len, base_url=getattr(self, "_anthropic_base_url", None), - fast_mode=self.request_overrides.get("speed") == "fast", + fast_mode=(self.request_overrides or {}).get("speed") == "fast", ) if self.api_mode == "codex_responses": From c2f6663432f6722b990caed4242a4bc84070485a Mon Sep 17 00:00:00 2001 From: liuwei53 Date: Sat, 11 Apr 2026 11:43:31 +0800 Subject: [PATCH 2/2] fix(weixin): send single message per response instead of splitting --- gateway/platforms/weixin.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/gateway/platforms/weixin.py b/gateway/platforms/weixin.py index 42b0b7fffe83d..25f08a3a52a2f 100644 --- a/gateway/platforms/weixin.py +++ b/gateway/platforms/weixin.py @@ -758,20 +758,13 @@ def _pack_markdown_blocks_for_weixin(content: str, max_length: int) -> List[str] def _split_text_for_weixin_delivery(content: str, max_length: int) -> List[str]: """Split content into sequential Weixin messages. - Prefer one message per top-level line/markdown unit when the author used - explicit line breaks. Oversized units fall back to block-aware packing so - long code fences still split safely. + A single response = a single Weixin message. Only split when the content + genuinely exceeds the API limit. Oversized content is truncated (not + broken into multiple messages) to preserve readability. """ - if len(content) <= max_length and "\n" not in content: + if len(content) <= max_length: return [content] - - chunks: List[str] = [] - for unit in _split_delivery_units_for_weixin(content): - if len(unit) <= max_length: - chunks.append(unit) - continue - chunks.extend(_pack_markdown_blocks_for_weixin(unit, max_length)) - return chunks or [content] + return [BasePlatformAdapter.truncate_message(content, max_length)] def _extract_text(item_list: List[Dict[str, Any]]) -> str: