Hermes Agent连接飞书群聊中不用@无响应问题

最近在使用了一段时间openclaw后,觉得多agent协作非常好用,但有些🔥token,正好最近hermes开源了,就研究了一下,但对飞书的群聊支持需要一些调整,我做了几种情况的案例,供大家参考,希望大家共同推进多agent技术进步,具体调整如下。详细源码见github库

一、方式1:指定群不用@有响应,其他群需要@才响应

实现在群1中不用@也有反馈,但在其他群聊中仍保持原样,通过@进行返回。经过测试只能通过修改配置文件和feishu.py代码来实现,具体记录如下。

1..env文件修改
复制代码
# 主要增加了 FEISHU_FREE_RESPONSE_CHATS 环境变量
FEISHU_DOMAIN=feishu
FEISHU_CONNECTION_MODE=websocket
FEISHU_ALLOW_ALL_USERS=false
FEISHU_ALLOWED_USERS=群1id,群2id
FEISHU_GROUP_POLICY=open
FEISHU_FREE_RESPONSE_CHATS=群1id # ← 新增:这个群免 @
2.config.yaml文件修改
复制代码
# 其实这两个参数可以去掉,对feishu无效,好像对discord有用,这里可以不做调整
feishu:
  require_mention: false
  free_response_chats: 群1id
3.feishu.py修改

完整代码请访问github库的feishu.py

复制代码
# 关键调整如下,详见dded by 注释之间内容。
def _should_accept_group_message(self, message: Any, sender_id: Any, chat_id: str = "") -> bool:
        """Require an explicit @mention before group messages enter the agent.
		
		Exception: chats listed in FEISHU_FREE_RESPONSE_CHATS bypass the @mention gate.
		"""
        if not self._allow_group_message(sender_id, chat_id):
            return False
		# added by in 2026-4-22 start=====================
		# Check if this chat is in the free-response allowlist (no @mention required)
        free_response_chats = set(
            item.strip()
            for item in os.getenv("FEISHU_FREE_RESPONSE_CHATS", "").split(",")
            if item.strip()
        )
        if chat_id and chat_id in free_response_chats:
            return True
		# added by in 2026-4-22 end=====================

        # @_all is Feishu's @everyone placeholder --- always route to the bot.
        raw_content = getattr(message, "content", "") or ""
        if "@_all" in raw_content:
            return True
        mentions = getattr(message, "mentions", None) or []
        if mentions:
            return self._message_mentions_bot(mentions)
        normalized = normalize_feishu_message(
            message_type=getattr(message, "message_type", "") or "",
            raw_content=raw_content,
        )
        if normalized.mentioned_ids:
            return self._post_mentions_bot(normalized.mentioned_ids)
        return False
二、方式2:指定群不用@有响应,其他允许群需要@才响应,没配置群一律无响应

实现在群1中不哟用@也有反馈,但在其他允许群聊中仍保持原样,通过@进行返回,但在没有设置允许的其他群没有任何响应(相当于不允许群聊)。经过测试只能通过修改配置文件和feishu.py代码来实现,这种情况修改的内容有些多,具体记录如下。

1..env文件修改
复制代码
# 主要增加了 FEISHU_FREE_RESPONSE_CHATS 环境变量
FEISHU_DOMAIN=feishu
FEISHU_CONNECTION_MODE=websocket
FEISHU_ALLOW_ALL_USERS=false
FEISHU_ALLOWED_USERS=群1id,群2id
FEISHU_GROUP_POLICY=allowlist
FEISHU_HOME_CHANNEL=群1id # 可以不用
2.config.yaml文件修改
复制代码
# 关键修改,增加的群聊规则,支持三种情况
feishu:
  extra:
      # 群聊规则配置
      group_rules:
        群1id:
          policy: open           # 允许所有人
          at_only: false         # ← 免 @ 响应!
        群2id:
          policy: open           # 允许所有人
          at_only: true         # ← 需要 @ 才响应!
      # 默认策略:未配置的群聊全部禁用
      default_group_policy: disabled
3.feishu.py修改

主要修改feishu.py文件,具体如下。完整代码请访问github库的feishu-noreply.py

复制代码
# 关键调整如下,详见dded by 注释内容。
class FeishuGroupRule:
    """Per-group policy rule for controlling which users may interact with the bot."""

    policy: str  # "open" | "allowlist" | "blacklist" | "admin_only" | "disabled"
	at_only: bool = True  # ← 新增:True=需要@,False=免@响应 added by 
    allowlist: set[str] = field(default_factory=set)
    blacklist: set[str] = field(default_factory=set)

...

def _load_settings(extra: Dict[str, Any]) -> FeishuAdapterSettings:
        # Parse per-group rules from config
        raw_group_rules = extra.get("group_rules", {})
        group_rules: Dict[str, FeishuGroupRule] = {}
        if isinstance(raw_group_rules, dict):
            for chat_id, rule_cfg in raw_group_rules.items():
                if not isinstance(rule_cfg, dict):
                    continue
                group_rules[str(chat_id)] = FeishuGroupRule(
                    policy=str(rule_cfg.get("policy", "open")).strip().lower(),
					at_only=_to_boolean(rule_cfg.get("at_only", True)),  # ← 新增 added by 
                    allowlist=set(str(u).strip() for u in rule_cfg.get("allowlist", []) if str(u).strip()),
                    blacklist=set(str(u).strip() for u in rule_cfg.get("blacklist", []) if str(u).strip()),
                )

def _should_accept_group_message(self, message: Any, sender_id: Any, chat_id: str = "") -> bool:
        """Require an explicit @mention before group messages enter the agent.
		
		Per-group behavior:
        - If group has a rule with policy="disabled": no response at all
        - If group has a rule with at_only=false: no @mention required
        - If group has a rule with at_only=true (default): @mention required
        - If no group rule: fallback to default behavior (@mention required)
		"""
        if not self._allow_group_message(sender_id, chat_id):
            return False
		# added by in 2026-4-22 start=====================
		# Check per-group at_only setting
        rule = self._group_rules.get(chat_id) if chat_id else None
        if rule:
            # at_only=false means respond without @mention
            if not rule.at_only:
                return True
            # at_only=true (default): fall through to @mention check below
		# add by in 2026-4-22 end=====================

        # @_all is Feishu's @everyone placeholder --- always route to the bot.
        raw_content = getattr(message, "content", "") or ""
        if "@_all" in raw_content:
            return True
        mentions = getattr(message, "mentions", None) or []
        if mentions:
            return self._message_mentions_bot(mentions)
        normalized = normalize_feishu_message(
            message_type=getattr(message, "message_type", "") or "",
            raw_content=raw_content,
        )
        if normalized.mentioned_ids:
            return self._post_mentions_bot(normalized.mentioned_ids)
        return False
相关推荐
组合缺一12 小时前
OpenClaw vs SolonCode:绑定飞书与钉钉,到底谁更简单?
ai·钉钉·飞书·ai编程·数字员工·openclaw·soloncode
野指针YZZ12 小时前
飞书MCP配置cc
飞书
三产1 天前
Hermes 教程 02:配置详解
人工智能·hermes
周易宅1 天前
2026年自主智能体系统架构演进:OpenClaw与Hermes Agent在现代软件生态中的定位、机制与应用
ai·系统架构·openclaw·hermes
带刺的坐椅1 天前
OpenClaw vs SolonCode:绑定飞书与钉钉,到底谁更简单?
钉钉·飞书·openclaw·soloncode
GoodTimeGGB1 天前
Windows 原生部署 Hermes Agent + 火山引擎 Agent Plan + Harness + 飞书机器人 完整实战教程与踩坑总结
agent·飞书机器人·harness·hermes·agent plan
无心水2 天前
【Hermes:安全、权限与生产环境】38、Hermes Agent 安全四层纵深:最小权限原则从理论到落地的完全指南
人工智能·安全·mcp协议·openclaw·养龙虾·hermes·honcho
无心水2 天前
【Hermes:安全、权限与生产环境】39、智能体也会犯错?Hermes 纠错、回滚与遗忘机制全指南 —— 让 AI 的错误像 Git 一样可逆可控
人工智能·git·安全·mcp协议·openclaw·hermes·honcho
广州灵眸科技有限公司2 天前
瑞芯微(EASY EAI)RV1126B openclaw部署接入飞书
linux·网络·人工智能·算法·yolo·飞书
YoungHong19922 天前
服务器部署Hermes教程 —— 从零搭建你的私人 AI 助手
飞书·claude·云服务器·deepseek·爱马仕·hermess