hermes - ✅(Solved) Fix Telegram: bots respond to messages @mentioning a different bot when require_mention is false [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#20373Fetched 2026-05-06 06:37:02
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×4cross-referenced ×2

When multiple Hermes bots share a Telegram group and require_mention: false, every bot responds to all messages — including messages where a user explicitly @mentions a different bot (e.g., @otherbot do X).

Root Cause

The Telegram _should_process_message() flow checks free_response_chats, then require_mention. When require_mention is false, it returns True immediately without inspecting whether the message explicitly targets a different entity via @mention or text_mention entities.

The only existing protection handles /command@otherbot syntax (bot_command entities), but Telegram only emits those for slash commands — not plain @mentions of other bots.

Fix Action

Fixed

PR fix notes

PR #20361: fix(telegram): reject messages that @mention a different bot in group chats

Description (problem / solution / changelog)

What does this PR do?

When multiple Hermes bots share a Telegram group and require_mention: false, every bot responds to all messages — including messages where a user explicitly @mentions a different bot. This adds filtering to reject such messages before processing, achieving parity with the Discord adapter which already handles this correctly.

Root Cause

The Telegram _should_process_message() flow checked free_response_chats then require_mention — if false, it returned True immediately. There was no gate for messages that explicitly target another entity via @mention or text_mention entities (only /command@otherbot was handled).

Additionally, _message_mentions_bot() and the new filtering both needed to scan the same entities, causing duplicate iteration when called sequentially from _should_process_message().

Type of Change

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

Changes Made

  • gateway/platforms/telegram.py — Extract _iter_entity_sources() (static) and _resolve_entity_targets() (single-pass scanner returning (self_mentioned, other_mentioned, other_command)). Refactor _message_mentions_bot() to delegate to the shared scanner. Add _message_targets_other_bot() that also delegates, positioned in _should_process_message() after free_response_chats but before require_mention.
  • tests/gateway/test_telegram_group_gating.py — 11 new tests covering: @otherbot rejected (require_mention false/true), @self not rejected, @self+@other dual mention not rejected, general messages unchanged, @human_user rejected, /command@otherbot rejected, @otherbot in caption entities, text_mention of other user rejected, text_mention of self not rejected.

Behavior

Messagerequire_mention: falserequire_mention: true
hello everyone✅ accepted❌ rejected (no mention)
@hermes_bot help✅ accepted✅ accepted
@otherbot helprejected (new)❌ rejected
@hermes_bot @otherbot help✅ accepted (self mentioned)✅ accepted
@john_doe hellorejected (new)❌ rejected
/status@other_botrejected (new)❌ rejected

Discord Parity

Mirrors the multi-agent filtering in discord.py (~L710-730). Telegram does not provide m.bot for mention entities, so we use entity text comparison instead.

How to Test

  1. pytest tests/gateway/test_telegram_group_gating.py -v — all 25 tests pass (14 existing + 11 new)
  2. Manual: deploy two Hermes bots to a shared group with require_mention: false. @mention one bot and verify only that bot responds.

Checklist

Code

  • I have read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(gateway): ...)
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix (no unrelated commits)
  • I have run pytest tests/ -q and all tests pass
  • I have added tests for my changes
  • I have tested on my platform: Ubuntu (Linux)

Documentation and Housekeeping

  • Updated relevant docstrings — N/A for README/docs
  • Updated cli-config.yaml.example — N/A (no new config keys)
  • Updated CONTRIBUTING.md/AGENTS.md — N/A (no architecture change)
  • Cross-platform impact — N/A (Telegram gateway, no OS interaction)
  • Updated tool descriptions/schemas — N/A (no tool changes)

Related Issue

Fixes #20373

Changed files

  • gateway/platforms/telegram.py (modified, +71/-19)
  • tests/gateway/test_telegram_group_gating.py (modified, +138/-0)

PR #20464: fix(gateway/telegram): skip messages that explicitly @mention another agent

Description (problem / solution / changelog)

Summary

  • Adds _message_targets_other_bot() to the Telegram adapter, which scans MessageEntity objects for @mention and text_mention entities directed at a different account
  • Wires it into _should_process_message() so that if another agent is explicitly @mentioned but this bot is not, the message is skipped early — regardless of the require_mention setting
  • Updates the _should_process_message docstring to document the new cross-talk guard
  • Mirrors the equivalent guard already present in the Discord adapter

Root cause

_should_process_message() hit return True immediately when require_mention: false, before any check for whether the message was addressed to a different bot. In a multi-agent group this caused every bot to respond whenever any one of them was @mentioned.

Test plan

  • Single-bot group with require_mention: false — bot still responds to all messages with no @mention
  • Multi-bot group: @other_bot do this — only other_bot responds, not this bot
  • Multi-bot group: @this_bot do this — this bot responds normally
  • Multi-bot group: @this_bot @other_bot help — both bots respond (both mentioned)
  • DM to bot — unaffected, always responds

Fixes #20373

🤖 Generated with Claude Code

Changed files

  • gateway/platforms/telegram.py (modified, +68/-16)
RAW_BUFFERClick to expand / collapse

Bug Report

Description

When multiple Hermes bots share a Telegram group and require_mention: false, every bot responds to all messages — including messages where a user explicitly @mentions a different bot (e.g., @otherbot do X).

Steps to Reproduce

  1. Deploy two or more Hermes bot instances to the same Telegram group
  2. Set require_mention: false (or leave it as default) on at least two of them
  3. Send a message like @bot_b change the cron schedule where @bot_b mentions one specific bot
  4. Observe: both bots respond

Expected Behavior

Only the bot that was @mentioned should process the message. All other bots in the group should reject it — regardless of their require_mention setting.

Root Cause

The Telegram _should_process_message() flow checks free_response_chats, then require_mention. When require_mention is false, it returns True immediately without inspecting whether the message explicitly targets a different entity via @mention or text_mention entities.

The only existing protection handles /command@otherbot syntax (bot_command entities), but Telegram only emits those for slash commands — not plain @mentions of other bots.

Environment

  • OS: Ubuntu (Linux)
  • Hermes version: v0.12.x (latest main)
  • Platform: Telegram
  • Setup: 14-agent fleet (5 PAs + 9 workers) sharing multiple Telegram groups

Additional Context

The Discord adapter already handles this correctly — it checks message.mentions for other bots and rejects if other_bot_mentioned and not self_mentioned. The Telegram adapter needs equivalent parity.

Additionally, _message_mentions_bot() and _message_targets_other_bot() both need to iterate the same entities. When _should_process_message() calls them sequentially, the message entities get scanned twice. A shared single-pass resolver would eliminate this duplication.

extent analysis

TL;DR

Modify the Telegram adapter to check for mentions of other bots and reject messages when the current bot is not mentioned.

Guidance

  • Review the _should_process_message() flow to ensure it checks for @mentions of other bots when require_mention is false.
  • Implement a check similar to the Discord adapter's message.mentions to reject messages that mention other bots.
  • Consider creating a shared single-pass resolver to eliminate duplicated entity scanning in _message_mentions_bot() and _message_targets_other_bot().
  • Verify the fix by testing with multiple bots in the same Telegram group and checking that only the mentioned bot responds.

Example

def _should_process_message(message):
    # ... existing code ...
    if not require_mention:
        # Check if the message mentions another bot
        other_bot_mentioned = _message_targets_other_bot(message)
        self_mentioned = _message_mentions_bot(message)
        if other_bot_mentioned and not self_mentioned:
            return False
    # ... existing code ...

Notes

The provided solution assumes that the _message_targets_other_bot() and _message_mentions_bot() functions are correctly implemented. If these functions are not accurate, the solution may not work as expected.

Recommendation

Apply workaround: Modify the Telegram adapter to check for mentions of other bots and reject messages when the current bot is not mentioned. This is necessary to achieve the expected behavior of only responding to messages that explicitly mention the bot.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Telegram: bots respond to messages @mentioning a different bot when require_mention is false [2 pull requests, 1 participants]