From 458b1a1d88fbc7c2f42ecb8edbfde7b83ea25829 Mon Sep 17 00:00:00 2001 From: 6vision Date: Sat, 30 May 2026 14:41:51 +0800 Subject: [PATCH] fix(wechatmp): merge cached text segments in passive reply In subscription account passive reply mode, WeChat allows only one reply per request. Multi-turn agent output was cached as separate entries, forcing the user to send an extra message to fetch each one. Now drain and merge all consecutive cached text segments into a single reply; media still returns one at a time. Co-authored-by: Cursor --- channel/wechatmp/passive_reply.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/channel/wechatmp/passive_reply.py b/channel/wechatmp/passive_reply.py index d03efc4d..6206e0e7 100644 --- a/channel/wechatmp/passive_reply.py +++ b/channel/wechatmp/passive_reply.py @@ -131,8 +131,22 @@ class Query: # Only one request can access to the cached data try: - (reply_type, reply_content) = channel.cache_dict[from_user].pop(0) - if not channel.cache_dict[from_user]: # If popping the message makes the list empty, delete the user entry from cache + # WeChat passive reply allows only a single reply per request. + # To avoid forcing the user to send an extra message for every + # segment of multi-turn agent output, drain all consecutive + # cached text segments at once and merge them into one reply. + # Media (voice/image) can only be returned one at a time, so it + # stops the merge and is returned on its own. + cached = channel.cache_dict[from_user] + if cached[0][0] == "text": + reply_type = "text" + merged_parts = [] + while cached and cached[0][0] == "text": + merged_parts.append(cached.pop(0)[1]) + reply_content = "\n\n".join(merged_parts) + else: + (reply_type, reply_content) = cached.pop(0) + if not channel.cache_dict[from_user]: # If draining empties the list, delete the user entry from cache del channel.cache_dict[from_user] except IndexError: return "success"