hermes - โœ…(Solved) Fix [Feature]: Support Feishu/Lark document comment intelligent reply [2 pull requests, 1 comments, 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#11465โ€ขFetched 2026-04-18 06:00:56
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
cross-referenced ร—2closed ร—1commented ร—1labeled ร—1

Root Cause

  1. Route everything through Feishu IM โ€” loses the inline anchor (which paragraph is the user asking about?) and forces the user to re-paste context.
  2. Build this as an external skill instead of a bundled gateway handler โ€” rejected because comment handling is driven by platform webhook events, not user-invoked skills. Per CONTRIBUTING.md, gateway/platform integrations belong in the core repo; this is analogous to existing feishu.py, slack.py, discord.py handlers.
  3. Per-user session memory instead of per-doc โ€” rejected because multiple users commonly comment on the same doc and expect shared context within that doc.

Fix Action

Fix / Workaround

Teams who use Feishu for docs (spec reviews, doc Q&A, inline feedback) have no way to get AI replies on comment threads. The only workaround is copy/pasting doc context into an IM chat, which loses the inline anchor (quoted paragraph, comment thread history) and forces a context switch.

PR fix notes

PR #11898: feat(feishu): intelligent reply on document comments with 3-tier access control

Description (problem / solution / changelog)

Salvage of #11023 onto current main, preserving @liujinkun2025's authorship on the feature commit.

Summary

Adds an event handler for Feishu/Lark drive comment notifications so users can @-mention the bot on document comments (local or whole-doc) and get LLM replies inline, with a 3-tier allowlist/pairing access control system.

Changes

  • New handler (gateway/platforms/feishu_comment.py, 1383 LOC): parses drive.notice.comment_add_v1 events, filters self-replies/non-bot-targeted, fetches doc + comment metadata in parallel, builds local-comment or whole-doc timeline (20/12 msg caps), runs agent with feishu_doc/feishu_drive toolsets, chunks replies at 4000 chars, per-doc session cache (1h TTL, 50 msg cap).
  • Access control (gateway/platforms/feishu_comment_rules.py, 424 LOC): exact-doc > wildcard > top-level > default resolution with per-field fallback. Policies: allowlist (static) or pairing (static โˆช runtime-approved store). Mtime-cached hot-reload. CLI: python -m gateway.platforms.feishu_comment_rules {status|check|pairing}. Explicit-grant only โ€” no implicit allow-all mode.
  • 5 new tools, scoped to the comment agent only (NOT added to _HERMES_CORE_TOOLS or any platform toolset): feishu_doc_read, feishu_drive_list_comments, feishu_drive_list_comment_replies, feishu_drive_reply_comment, feishu_drive_add_comment.
  • Adapter wiring (gateway/platforms/feishu.py): +25 lines to register the event handler on both WebSocket and Webhook transports.
  • Tests: 643 LOC across tests/gateway/test_feishu_comment{,_rules}.py and tests/tools/test_feishu_tools.py.

Follow-up polish on top of the contributor commit

  • feishu_comment_rules.py: replaced import-time ~/.hermes expanduser fallback with get_hermes_home() from hermes_constants (canonical, profile-safe).
  • feishu_doc_tool.py / feishu_drive_tool.py: dropped the asyncio.get_event_loop().run_until_complete(asyncio.to_thread(...)) dance โ€” tool handlers run synchronously in a worker thread with no running loop, so the RuntimeError branch was always the one that executed. Now calls client.request directly. Unused asyncio import removed.
  • test_feishu.py: updated the mock EventDispatcher builder to include register_p2_customized_event for the new drive.notice.comment_add_v1 registration.
  • scripts/release.py: AUTHOR_MAP entry [email protected] โ†’ liujinkun2025.

Validation

Result
scripts/run_tests.sh -k feishu221 passed
Rule engine (allowlist/wildcard/pairing semantics) E2EPASS
Mtime hot-reload E2EPASS
Pairing store CRUD (idempotent add/remove, list) E2EPASS
CLI status / check / `pairing addlist` E2E
Tool registration + schemas + scoping (not in core) E2EPASS
Event parsing: WebSocket + Webhook + malformed โ†’ NonePASS
HERMES_HOME isolation honored in all pathsPASS

Live Feishu tenant E2E not performed (no tenant available); the contributor has already verified that path internally per the original PR description.

Credit

Feature implementation by @liujinkun2025 in #11023. Their commit is preserved as the first commit on this salvage branch (rebase merge to retain authorship).

Closes #11465 Supersedes #11023

Changed files

  • gateway/platforms/feishu.py (modified, +25/-0)
  • gateway/platforms/feishu_comment.py (added, +1383/-0)
  • gateway/platforms/feishu_comment_rules.py (added, +429/-0)
  • scripts/release.py (modified, +1/-0)
  • tests/gateway/test_feishu.py (modified, +5/-0)
  • tests/gateway/test_feishu_comment.py (added, +261/-0)
  • tests/gateway/test_feishu_comment_rules.py (added, +320/-0)
  • tests/tools/test_feishu_tools.py (added, +62/-0)
  • tools/feishu_doc_tool.py (added, +131/-0)
  • tools/feishu_drive_tool.py (added, +429/-0)
  • toolsets.py (modified, +15/-0)

PR #11023: feat: Feishu document comment intelligent reply with 3-tier access control

Description (problem / solution / changelog)

Summary

Add support for responding to Feishu document comments (drive.notice.comment_add_v1 events) with LLM-powered intelligent replies, including a configurable 3-tier access control system.

Comment Handler

  • Full event orchestration: parse comment event โ†’ filter โ†’ fetch doc meta + comment details โ†’ build timeline โ†’ run agent โ†’ deliver reply
  • Smart timeline selection: local comments (max 20 entries), whole-document comments (max 12 entries)
  • Long text chunking (4000 chars) for reply delivery with automatic fallback
  • Cross-card session sharing per document (in-memory cache, 50 msg cap, 1h TTL)
  • Semantic text extraction (strip @mention noise)
  • Document link resolution via /wiki/v2/spaces/get_node
  • OK reaction indicator while agent is processing

Tools (5 new)

  • feishu_doc_read โ€” read document raw content
  • feishu_drive_list_comments โ€” list document comments
  • feishu_drive_list_comment_replies โ€” list comment thread replies
  • feishu_drive_reply_comment โ€” reply to a comment
  • feishu_drive_add_comment โ€” add a whole-document comment

3-Tier Access Control (feishu_comment_rules.py)

  • Priority: exact document rule > wildcard "*" rule > top-level config > code defaults
  • Per-field fallback: enabled, policy, allow_from each resolve independently through the tiers
  • Policies: allowlist (static list only) / pairing (static list โˆช runtime-approved store)
  • Explicit-grant only: every user who triggers a reply must be listed in allow_from or in the pairing-approved store โ€” there is no implicit allow-all mode
  • Config: ~/.hermes/feishu_comment_rules.json, mtime-cached hot-reload (no restart needed)
  • CLI: status / check <doc> <user> / pairing add|remove|list

Event Filtering

  • Self-reply filter using generalized self_open_id (supports both tenant and future user-identity modes)
  • Receiver check: only process events where the bot is the @mentioned target
  • Notice type filter: only add_comment and add_reply

Files Changed

FileDescription
gateway/platforms/feishu_comment.pyMain comment handler + prompt builders + API layer
gateway/platforms/feishu_comment_rules.py3-tier access control engine + pairing store + CLI
gateway/platforms/feishu.pyRegister comment event handler in adapter
tools/feishu_doc_tool.pyDocument read tool
tools/feishu_drive_tool.py4 drive comment tools
toolsets.pyRegister feishu_doc and feishu_drive toolsets

Config Example

{
  "enabled": true,
  "policy": "pairing",
  "allow_from": ["ou_global_reviewer"],
  "documents": {
    "*": { "policy": "pairing", "allow_from": [] },
    "docx:dxxExxxxxMxxmxxxxxxxx": { "policy": "allowlist", "allow_from": ["ou_doc_owner", "ou_teammate"] }
  }
}

Test Plan

  • Allowlist policy: empty allow_from denies all users silently
  • Allowlist policy: user in allow_from gets normal reply
  • Exact document rule overrides top-level (doc allowlist + narrower allow_from, top pairing)
  • Exact document rule overrides wildcard (doc allowlist, wildcard pairing)
  • Wildcard rule applies when no exact match
  • Pairing policy: unapproved user silently denied
  • Pairing policy: CLI pairing add grants access immediately (hot-reload)
  • Pairing policy: user listed in allow_from granted without CLI approval (union semantics)
  • Self-reply filter: bot's own comments are skipped
  • Receiver filter: comments not @mentioning the bot are skipped

Changed files

  • gateway/platforms/feishu.py (modified, +25/-0)
  • gateway/platforms/feishu_comment.py (added, +1383/-0)
  • gateway/platforms/feishu_comment_rules.py (added, +424/-0)
  • tests/gateway/test_feishu_comment.py (added, +261/-0)
  • tests/gateway/test_feishu_comment_rules.py (added, +320/-0)
  • tests/tools/test_feishu_tools.py (added, +62/-0)
  • tools/feishu_doc_tool.py (added, +136/-0)
  • tools/feishu_drive_tool.py (added, +433/-0)
  • toolsets.py (modified, +15/-0)
RAW_BUFFERClick to expand / collapse

Problem or Use Case

Hermes currently integrates with Feishu IM via gateway/platforms/feishu.py, but Feishu's document comments โ€” one of the most common collaboration surfaces inside Lark/Feishu โ€” are not handled at all.

Teams who use Feishu for docs (spec reviews, doc Q&A, inline feedback) have no way to get AI replies on comment threads. The only workaround is copy/pasting doc context into an IM chat, which loses the inline anchor (quoted paragraph, comment thread history) and forces a context switch.

Concretely, three scenarios are unsupported today:

  1. User @mentions the bot on a local comment (pinned to a selected paragraph) and asks a question about that paragraph.
  2. User @mentions the bot on a whole-document comment asking about the doc overall.
  3. Multi-turn follow-up within the same doc โ€” e.g. asking "what did you mean by X earlier?" in a different comment thread on the same doc.

In our internal usage this is by far the most natural place to invoke an AI assistant inside Feishu โ€” more natural than DMs for doc-centric work.

Proposed Solution

A new gateway handler for drive.notice.comment_add_v1 events. High-level design:

  1. Event routing โ€” filter by notice_type (only add_comment / add_reply), skip self-authored events, skip events not addressed to the bot.
  2. Context assembly โ€” parallel fetch of doc metadata + comment details, build either a local-reply timeline or whole-doc timeline (with size caps: 20 local / 12 whole), strip @bot noise, resolve embedded docs_link / wiki links via GET /wiki/v2/spaces/get_node.
  3. Agent โ€” same LLM resolution path as IM messages (_resolve_model_and_runtime); agent has access to feishu_doc_read + feishu_drive_* tools for deeper lookup.
  4. Reply delivery โ€” local comments โ†’ reply_to_comment (with automatic fallback to whole-comment on 1069302); whole comments โ†’ new_comments. Long replies auto-chunked at 4000 chars. OK reaction added/removed for typing indication.
  5. Per-doc session memory โ€” key comment-doc:{file_type}:{file_token}, 50-msg cap, 1h TTL, so follow-ups across threads on the same doc stay coherent.
  6. Access control โ€” three-tier rule resolution (exact doc โ†’ wiki:{token} โ†’ * wildcard โ†’ top-level โ†’ defaults), field-by-field fallback for enabled/policy/allow_from, two policy modes:
    • allowlist โ€” only listed open_ids
    • pairing โ€” listed open_ids plus CLI-approved users Every user that triggers a reply must be explicitly listed โ€” there is no implicit allow-all mode. Config file is mtime-cached (hot reload, no restart). Ships with a CLI helper: python -m gateway.platforms.feishu_comment_rules {status|check|pairing}.

New files:

  • tools/feishu_doc_tool.py (1 tool)
  • tools/feishu_drive_tool.py (4 tools)
  • gateway/platforms/feishu_comment.py (handler + prompt + orchestration)
  • gateway/platforms/feishu_comment_rules.py (access control + CLI)

Required Feishu app scopes (tenant-level): drive:drive.metadata:readonly, docs:document.comment:read, docs:document.comment:create, docs:document.comment:write_only, docx:document:readonly.

โš ๏ธ A PR implementing this is already open: #11023 โ€” would love a review on the approach.

Alternatives Considered

  1. Route everything through Feishu IM โ€” loses the inline anchor (which paragraph is the user asking about?) and forces the user to re-paste context.
  2. Build this as an external skill instead of a bundled gateway handler โ€” rejected because comment handling is driven by platform webhook events, not user-invoked skills. Per CONTRIBUTING.md, gateway/platform integrations belong in the core repo; this is analogous to existing feishu.py, slack.py, discord.py handlers.
  3. Per-user session memory instead of per-doc โ€” rejected because multiple users commonly comment on the same doc and expect shared context within that doc.

Feature Type

Gateway / messaging improvement

Scope

Large (new module or significant refactor)

Contribution

  • I'd like to implement this myself and submit a PR

Debug Report (optional)

extent analysis

TL;DR

Implement a new gateway handler for drive.notice.comment_add_v1 events to support Feishu document comments.

Guidance

  • Review the proposed solution and the open PR #11023 to understand the approach and provide feedback.
  • Verify that the required Feishu app scopes are correctly configured: drive:drive.metadata:readonly, docs:document.comment:read, docs:document.comment:create, docs:document.comment:write_only, and docx:document:readonly.
  • Test the new gateway handler with different scenarios, such as local comments, whole-document comments, and multi-turn follow-up conversations.
  • Ensure that the access control rules are correctly implemented, with a focus on the three-tier rule resolution and field-by-field fallback for enabled/policy/allow_from.

Example

No code snippet is provided as the issue does not contain specific code that needs to be modified or added.

Notes

The implementation of the new gateway handler is already in progress, and a PR is open for review. The proposed solution seems to cover the required functionality, but it's essential to review and test it thoroughly to ensure it meets the requirements.

Recommendation

Apply the workaround by implementing the new gateway handler as proposed in the open PR #11023, as it seems to be the most suitable solution to support Feishu document comments.

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 [Feature]: Support Feishu/Lark document comment intelligent reply [2 pull requests, 1 comments, 1 participants]