Skip to content

feat(feishu): bind sender identities and scope conversation memory - #4000

Open
kkmaple wants to merge 2 commits into
zhayujie:masterfrom
kkmaple:fix/feishu-sender-identity
Open

kkmaple wants to merge 2 commits into
zhayujie:masterfrom
kkmaple:fix/feishu-sender-identity

Conversation

@kkmaple

@kkmaple kkmaple commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Binds incoming Feishu messages to the sender’s Open ID and applies the conversation’s memory scope to member profiles, session history, file and memory tools, nightly summaries, and Deep Dream.

  • Direct chats keep history separate by sender. Each bot can use owner_workspace (the default), per_user, or shared to control access to the workspace profile and memory. Switching to personal memory starts a separate session.
  • Group chats share memory within each group and maintain a separate profile for each member. Scoped chats retain access to shared knowledge.
  • Bot setup lets admins configure multiple owners, select a memory mode, and toggle direct messages in the web console and desktop app. QR registration adds the scanning user as an owner when Feishu returns their Open ID. Manual setup supports looking up and adopting the app owner.
  • Migration moves legacy owner settings when the old App ID matches exactly one bot instance. Ambiguous settings remain available for review.

Type of change

  • Bug fix
  • New feature
  • Docs
  • Refactor / chore

Checklist

  • I have read the Contributing Guide
  • I tested this change locally
  • Code comments and docs are in English
  • Linked related issue (if any): closes #

Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:59
@mintlify

mintlify Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit d6b74b5.

Approve preview

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Approval is blocked because the change introduces at least one critical runtime compatibility defect (using Path.is_relative_to() despite a declared Python >=3.7 support), alongside additional prompt/documentation inconsistencies and missing i18n that need correction.

4 open issues
What changed in this PR

Binds each Feishu turn to the sender’s open_id to preserve speaker attribution and enforce per-chat scoping for member profiles and memory operations (with an optional owner exception for direct chats).

Changes:

  • Add trusted Feishu identity derivation and attach it per turn to scope prompts, tools, and stored message attribution.
  • Introduce per-sender, per-chat Markdown member profiles via a backend-bound member_profile tool.
  • Scope memory search/reads/summaries to the current conversation and document the behavior in EN/zh/ja guides, with regression tests.
File Description
tests/​test_feishu_identity_profiles.py Adds offline regression tests covering identity binding, profile isolation, scoped memory behavior, and attribution persistence.
docs/​zh/​channels/​feishu.mdx Documents feishu_owner_open_id and explains the member profile and memory isolation behavior in Chinese.
docs/​ja/​channels/​feishu.mdx Documents feishu_owner_open_id and explains the member profile and memory isolation behavior in Japanese.
docs/​channels/​feishu.mdx Documents feishu_owner_open_id and explains the member profile and memory isolation behavior in English.
config.py Adds the feishu_owner_open_id configuration option to support owner binding in direct chats.
config-template.json Updates the configuration template to include feishu_owner_open_id.
channel/​feishu/​feishu_message.py Captures Feishu identity metadata and hardens extraction of the sender open_id for downstream identity binding.
channel/​feishu/​feishu_channel.py Propagates configured app identity and owner binding into message context before processing.
bridge/​agent_bridge.py Binds sender identity per turn, adds attribution to the model input, and persists sender metadata with user messages.
agent/​tools/​memory/​memory_search.py Plumbs scoped memory search settings and improves empty-result guidance under conversation-scoped memory roots.
agent/​tools/​memory/​memory_get.py Enforces an optional allowed scope for memory reads to prevent cross-conversation access.
agent/​tools/​memory/​member_profile.py Introduces a member_profile tool that operates only on the backend-bound current speaker’s profile for view/update/clear actions.
agent/​protocol/​agent.py Adjusts prompt/context loading and memory manager behavior based on bound identity and appends identity/scope guidance to the system prompt.
agent/​prompt/​builder.py Updates prompt text related to workspace files and identity boundaries for scoped Feishu sessions.
agent/​memory/​summarizer.py Updates summarizer instructions to preserve sender attribution (e.g., sender_id) in generated summaries.
agent/​memory/​identity.py Implements trusted Feishu identity derivation, profile path resolution, per-turn tool scoping, and attribution labeling.

Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

Comment thread agent/memory/identity.py Resolved
Comment thread agent/protocol/agent.py Resolved
Comment thread agent/prompt/builder.py Resolved
Comment thread agent/tools/memory/member_profile.py Resolved
@kkmaple
kkmaple marked this pull request as draft November 19, 2026 11:30
@kkmaple
kkmaple requested a balanced review from Copilot November 19, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

An active moderate issue remains because the new scope guard in agent/tools/memory/memory_get.py blocks reads outside the scoped user path, likely preventing access to shared knowledge pages (and related search results) when allowed_memory_scope is set.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Scope guard blocks knowledge pages needed for scoped sessions

agent/​tools/​memory/​memory_get.py:136

The new scope guard blocks all reads outside memory/users/<scope>/…, which also prevents memory_get from opening knowledge/... pages when allowed_memory_scope is set (scoped Feishu sessions). This likely breaks the intended "memory isolation" without disabling the shared knowledge base, and can make memory_search results pointing at knowledge/ unreadable.

3 resolved since last review

Review effort: Balanced

@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch from 6456e70 to 29947e6 Compare November 20, 2026 03:32
@kkmaple
kkmaple requested a balanced review from Copilot November 20, 2026 03:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change introduces blocking runtime and state-handling defects—an unimported conf() call that will raise NameError when producing messages and unhandled ValueError during Feishu registration that can leave the system stuck while retaining app_secret—so it needs fixes before review approval.

4 open issues

Review effort: Balanced

Comment thread channel/channel.py Resolved
Comment thread channel/web/api/channels.py Resolved
Comment thread channel/feishu/feishu_channel.py Resolved
@kkmaple kkmaple changed the title fix(feishu): bind sender identity and scope member profiles feat(feishu): bind sender identity and scope member profiles Nov 20, 2026
@kkmaple kkmaple changed the title feat(feishu): bind sender identity and scope member profiles feat(feishu): bind sender identities and scope conversation memory Nov 20, 2026
@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch 2 times, most recently from 45f9c69 to 5786fa4 Compare November 24, 2026 13:37
@kkmaple
kkmaple requested a balanced review from Copilot November 24, 2026 13:46
@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch from 5786fa4 to 292566a Compare November 24, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

An active moderate issue remains where missing sender.sender_type can default to an empty string and be misclassified as non-user in feishu_identity(), potentially breaking owner binding and workspace-memory access in direct chats.

3 open issues
2 resolved since last review

Review effort: Balanced

Comment thread channel/feishu/feishu_message.py Resolved
@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch from 292566a to 06a3778 Compare November 25, 2026 02:45
@kkmaple
kkmaple requested a balanced review from Copilot November 25, 2026 03:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical bug in agent/team.py misuses a @contextmanager as a decorator—causing module import failure and preventing startup—alongside a sender-type default in Feishu handling that can misclassify human senders and break routing behavior.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread agent/team.py Resolved
@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch 2 times, most recently from 8f91769 to 12ce564 Compare November 26, 2026 03:12
@kkmaple

kkmaple commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

I've been using this in Feishu for a few days and haven't noticed any issues so far.

mermaid-diagram mermaid-diagram2

@kkmaple
kkmaple marked this pull request as ready for review November 26, 2026 03:26
@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch 2 times, most recently from 21f77e1 to c1220d7 Compare November 28, 2026 12:07
Bind Feishu sender identities and member profiles to their context. Share
group memory while isolating conversations and images, and align knowledge
access with conversation scope.

Reply to direct messages by chat ID, keep the direct-message toggle per
bot, and limit Feishu configuration migration to Feishu instances.
@kkmaple
kkmaple force-pushed the fix/feishu-sender-identity branch from c1220d7 to d6b74b5 Compare December 2, 2026 02:02

This branch has not been deployed

No deployments
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.

2 participants