Skip to content

Refine Weixin multiline chunking - #7587

Closed
bravohenry wants to merge 2 commits into
NousResearch:mainfrom
bravohenry:codex/weixin-chunking-fix
Closed

Refine Weixin multiline chunking#7587
bravohenry wants to merge 2 commits into
NousResearch:mainfrom
bravohenry:codex/weixin-chunking-fix

Conversation

@bravohenry

Copy link
Copy Markdown
Contributor

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

  • Keep the existing markdown normalization and block-aware packing
  • Only split multiline blocks into separate bubbles when the block looks like a short chat exchange:
    • 2-3 non-empty lines
    • each line is short
    • no heading/list/quote/numbered-step markers
  • Preserve structured multiline blocks as a single message bubble

Tests

Added coverage for:

  • preserving 3-line short chat splitting
  • keeping structured table output together
  • keeping 4-line structured summaries together
  • keeping heading + body together

Ran:

  • pytest -q tests/gateway/test_weixin.py
  • python3 -m py_compile gateway/platforms/weixin.py tests/gateway/test_weixin.py

Result:

  • 16 passed

Motivation

This addresses real-world feedback that recent Weixin output became fragmented into too many bubbles, which made structured replies harder to read.

Copilot AI review requested due to automatic review settings April 11, 2026 07:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +739 to +742
return False
if len(stripped) > 48:
return False
if line.startswith((" ", "\t")):
Comment on lines +744 to +749
if stripped.startswith((">", "-", "*", "【")):
return False
if re.match(r"^\*\*[^*]+\*\*$", stripped):
return False
if re.match(r"^\d+\.\s", stripped):
return False
Comment thread gateway/platforms/weixin.py Outdated
Comment on lines +795 to +805
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))
@teknium1

Copy link
Copy Markdown
Contributor

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!

@teknium1 teknium1 closed this Apr 12, 2026
teknium1 pushed a commit that referenced this pull request Apr 12, 2026
…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.
teknium1 pushed a commit that referenced this pull request Apr 12, 2026
…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.
@teknium1

Copy link
Copy Markdown
Contributor

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 <think> tags you saw with MiniMax: that's unrelated to chunking. MiniMax's Anthropic-compatible endpoint (api.minimax.io/anthropic) properly parses reasoning into structured thinking blocks — if you're going through OpenRouter or MiniMax's OpenAI endpoint, the <think> tags won't be parsed. Switch to the Anthropic-compatible endpoint directly and the tags will be handled correctly.

Thanks for the contribution!

Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…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.
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…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.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants