Refine Weixin multiline chunking - #7587
Conversation
There was a problem hiding this comment.
Pull request overview
Refines the Weixin (WeChat) outbound message chunking so structured multiline content (tables, summaries, headings + body) is kept together in a single bubble, while still splitting short “chatty” multiline exchanges into separate bubbles for readability.
Changes:
- Added a heuristic to detect short chat-like multiline blocks (2–3 short, non-structural lines) and only split those into multiple bubbles.
- Updated Weixin delivery splitting to operate per markdown block and apply the new heuristic.
- Expanded pytest coverage for structured multiline cases (tables, 4-line summaries, heading + body).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
gateway/platforms/weixin.py |
Introduces the chatty-block heuristic and updates the delivery splitting logic to preserve structured multiline blocks. |
tests/gateway/test_weixin.py |
Adds/updates tests to validate the refined chunking behavior for structured output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return False | ||
| if len(stripped) > 48: | ||
| return False | ||
| if line.startswith((" ", "\t")): |
| if stripped.startswith((">", "-", "*", "【")): | ||
| return False | ||
| if re.match(r"^\*\*[^*]+\*\*$", stripped): | ||
| return False | ||
| if re.match(r"^\d+\.\s", stripped): | ||
| return False |
| for block in _split_markdown_blocks(content): | ||
| units = ( | ||
| _split_delivery_units_for_weixin(block) | ||
| if _should_split_short_chat_block_for_weixin(block) | ||
| else [block] | ||
| ) | ||
| for unit in units: | ||
| if len(unit) <= max_length: | ||
| chunks.append(unit) | ||
| continue | ||
| chunks.extend(_pack_markdown_blocks_for_weixin(unit, max_length)) |
|
Thanks for the contribution @bravohenry! This was a thoughtful approach — the chatty-vs-structured heuristics were well thought out. However, this was already addressed on main in PR #7903 (commit da9f96b), which landed the same day. That fix takes a simpler approach: compact mode keeps all content in a single bubble by default when under the platform limit, with legacy per-line splitting available as an opt-in config toggle. Since compact mode covers all the cases your heuristics were targeting (tables, headings, structured blocks) without the detection complexity, we're going to go with that. Closing as redundant — appreciate the effort! |
…tructured content together Add content-aware splitting to compact mode: short chat-like exchanges (2-6 short lines without headings/lists/quotes) get separate message bubbles for a natural chat feel, while structured content (tables, headings with body, numbered lists) stays in a single message. Cherry-picked from PR #7587 by bravohenry, adapted to the compact/legacy split_per_line architecture from #7903.
…tructured content together Add content-aware splitting to compact mode: short chat-like exchanges (2-6 short lines without headings/lists/quotes) get separate message bubbles for a natural chat feel, while structured content (tables, headings with body, numbered lists) stays in a single message. Cherry-picked from PR #7587 by bravohenry, adapted to the compact/legacy split_per_line architecture from #7903.
|
Your content-aware chatty splitting has been merged via PR #8230 — cherry-picked onto current main with your authorship preserved in git history. Regarding the Thanks for the contribution! |
…tructured content together Add content-aware splitting to compact mode: short chat-like exchanges (2-6 short lines without headings/lists/quotes) get separate message bubbles for a natural chat feel, while structured content (tables, headings with body, numbered lists) stays in a single message. Cherry-picked from PR NousResearch#7587 by bravohenry, adapted to the compact/legacy split_per_line architecture from NousResearch#7903.
…tructured content together Add content-aware splitting to compact mode: short chat-like exchanges (2-6 short lines without headings/lists/quotes) get separate message bubbles for a natural chat feel, while structured content (tables, headings with body, numbered lists) stays in a single message. Cherry-picked from PR NousResearch#7587 by bravohenry, adapted to the compact/legacy split_per_line architecture from NousResearch#7903.
…tructured content together Add content-aware splitting to compact mode: short chat-like exchanges (2-6 short lines without headings/lists/quotes) get separate message bubbles for a natural chat feel, while structured content (tables, headings with body, numbered lists) stays in a single message. Cherry-picked from PR NousResearch#7587 by bravohenry, adapted to the compact/legacy split_per_line architecture from NousResearch#7903.
Summary
This PR refines Weixin message chunking so structured multiline output stays readable in WeChat.
The original adapter split any top-level multiline block into separate message bubbles. That worked for short chatty replies, but it fragmented structured content such as summaries, headings with body text, and table-like output.
What changed
Tests
Added coverage for:
Ran:
pytest -q tests/gateway/test_weixin.pypython3 -m py_compile gateway/platforms/weixin.py tests/gateway/test_weixin.pyResult:
16 passedMotivation
This addresses real-world feedback that recent Weixin output became fragmented into too many bubbles, which made structured replies harder to read.