Skip to content

fix(feishu): record non-mentioned group messages as context-only transcript entries - #16112

Open
lewislulu wants to merge 1 commit into
NousResearch:mainfrom
lewislulu:fix/feishu-group-context-only
Open

fix(feishu): record non-mentioned group messages as context-only transcript entries#16112
lewislulu wants to merge 1 commit into
NousResearch:mainfrom
lewislulu:fix/feishu-group-context-only

Conversation

@lewislulu

Copy link
Copy Markdown

What does this PR do?

When a Feishu/Lark group message passes the policy gate (_allow_group_message) but does not @mention the bot, the message is currently silently dropped. This means the agent has zero awareness of the ongoing group conversation — when a user later @mentions the bot and references earlier messages, the agent cannot see them.

This PR introduces a context_only pathway: non-mentioned group messages are still processed and persisted to the session transcript, but they skip the agent pipeline entirely (no reaction, no typing indicator, no response). When the bot is later @mentioned, it can see the full conversation history.

Related Issue

Fixes #9835
Ref #10275

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

gateway/platforms/base.py

  • Added context_only: bool = False field to MessageEvent dataclass

gateway/platforms/feishu.py

  • _handle_message_event_data() — Split the group message gate into two steps: (1) policy check via _allow_group_message(), (2) mention check via new _message_is_bot_addressed(). Messages passing policy but not mentioning the bot are flagged context_only=True
  • _handle_message_with_guards() — Added early return for context_only events, routing them to _record_context_only_message() instead of the agent pipeline
  • _record_context_only_message() — New method that persists context-only events to the session transcript with a context_only: true marker
  • _message_is_bot_addressed() — New method extracted from _should_accept_group_message() containing the pure mention-check logic (@mention / @ALL detection), callable independently
  • _process_inbound_message() — Added context_only parameter passthrough to MessageEvent construction

How to Test

  1. Add the bot to a Feishu group with FEISHU_GROUP_POLICY=open
  2. Send several messages in the group without @mentioning the bot
  3. Verify: no bot reaction, no typing indicator, no response (context_only path)
  4. Then @mention the bot and ask "what were we just talking about?"
  5. Verify: the bot can see and reference the earlier non-mentioned messages from the transcript

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: macOS 15 (Apple Silicon)

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've considered cross-platform impact — or N/A

Design Notes

Why context_only instead of FEISHU_REQUIRE_MENTION=false?

A simple require_mention=false toggle (as proposed in #10275) would route all group messages through the full agent pipeline — triggering reactions, typing indicators, and LLM inference for every message. This is wasteful and noisy.

The context_only approach is surgical: non-mentioned messages are recorded for context but never trigger the agent. The bot stays silent until explicitly addressed, yet has full conversational awareness when called upon.

…script entries

Group messages that pass the policy gate but do not @mention the bot are
currently silently dropped.  This means the agent has no awareness of the
ongoing group conversation — when a user later @mentions the bot and
references earlier messages, the agent cannot see them.

This commit introduces a 'context_only' flag on MessageEvent.  When a
group message passes _allow_group_message() but is not addressed to the
bot (_message_is_bot_addressed() returns False), the message is still
processed through _process_inbound_message() but flagged context_only.

context_only events:
- Are persisted to the session transcript with a context_only: true marker
- Skip the agent pipeline entirely (no reaction, no typing, no response)
- Give the agent conversational awareness when later @mentioned

The mention-check logic is extracted from _should_accept_group_message()
into a new _message_is_bot_addressed() method for independent reuse.

Fixes NousResearch#9835
Ref NousResearch#10275
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter comp/gateway Gateway runner, session dispatch, delivery labels Apr 26, 2026
@DarkMagicCK

Copy link
Copy Markdown

this is exact user case for group chat with multiple people discussion and let agent summary and make further actions, hope can add this feature to release!

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for addressing a real Feishu group-chat gap. Current main still drops policy-allowed, unmentioned group messages when require_mention is effective (plugins/platforms/feishu/adapter.py:4270-4275).

Problems

  • The PR targets the removed gateway/platforms/feishu.py; Feishu now lives in plugins/platforms/feishu/adapter.py after 552adbe, and GitHub reports this branch as conflicting.
  • A port must preserve require_mention: false: the current admission gate only requires a mention when that setting is true (plugins/platforms/feishu/adapter.py:4274-4275).
  • Sender-specific sources would not provide full group context across participants: Feishu builds sources with sender IDs (plugins/platforms/feishu/adapter.py:3282-3291) and the base adapter keys group sessions per user by default (gateway/platforms/base.py:4604-4608).
  • The proposed context_only key is not persisted by SessionStore.append_to_transcript() (gateway/session.py:2253-2284), and current text batching can merge an observed event with an addressed event (plugins/platforms/feishu/adapter.py:3643-3679).

Suggested changes

  • Port this through the current observed-context design used by Telegram (plugins/platforms/telegram/adapter.py:7306-7339): shared group source, observed: true transcript rows, and addressed-turn-only context.
  • Add coverage for effective mention policy, cross-user context, batching, and silent observation.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu adapter has no require_mention toggle — file messages in group chats are silently dropped

4 participants