Skip to content

feat(dingtalk): support shared session context in group chats - #7208

Merged
cuiyuebing merged 2 commits into
agentscope-ai:mainfrom
hongxicheng:ding-shared-session
Aug 26, 2026
Merged

feat(dingtalk): support shared session context in group chats#7208
cuiyuebing merged 2 commits into
agentscope-ai:mainfrom
hongxicheng:ding-shared-session

Conversation

@hongxicheng

Copy link
Copy Markdown
Collaborator

Description

DingTalk group chats previously always isolated context per member: session_id
is derived from the conversation id suffix, but user_id is the sender, and
session state is keyed by (user_id, session_id) — so every member got their
own context.

This PR adds a share_session_in_group toggle so group members can share one
conversation context, matching the existing option in Feishu / WeCom / OneBot /
Matrix.

Defaults to false, preserving current behavior — existing users see no change.

Implementation (two call sites, both required)

  1. build_agent_request_from_native — in a group with sharing on, request.user_id
    collapses to the constant "group" (same approach as WeCom). The raw
    payload["sender_id"] is left untouched, so logging, acl_sender_id and
    meta["user_name"] are unaffected.

  2. get_debounce_key — stops appending sender_id when sharing is on. This one
    is easy to miss but necessary: the queue key is computed from the payload at
    enqueue time, before the AgentRequest exists, so it cannot see the
    collapsed user_id. Changing only (1) would route two members of the same
    group into two queues with two concurrent consumers, while their chat.id is
    now identical — TaskTracker.attach_or_start then returns is_new=False, the
    later message only receives a subscriber queue and its payload is never
    executed (log: Message ignored (task already running)). Feishu and WeCom
    don't hit this because their payloads carry session_id, so their queues are
    already per-conversation.

Send path is unaffected

DingTalk resolves delivery targets through a stored sessionWebhook table.
Verified that changing user_id does not affect it:

  • Live replies read the webhook straight from the current request's
    meta["session_webhook"] — no table lookup.
  • The group webhook entry is already stored under dingtalk:sw:<session_id>
    (no user_id in the key).
  • Proactive/cron sends resolve dingtalk:sw:group_<session_id> and fall back
    through _suffix_only_webhook_key to the group entry (covered by a test).
  • The Open API fallback uses conversation_id / sender_staff_id, unrelated to
    user_id.

The shared id must not contain _, otherwise the rfind("_") split in that
fallback key breaks — noted in a code comment.

Drive-by fix (missing docs)

Feishu and WeCom have supported share_session_in_group in code for a while, but
neither channel doc ever mentioned it (WeCom even defaults to true, so users had
no documented way to find or disable it). This PR adds the field to their JSON
examples, channel-specific field tables and the appendix config overview.

Related Issue: Closes #7158

Security Considerations: [If applicable, e.g. channel auth, env/config handling]

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Core / Backend (app, agents, config, providers, utils, local_models)
  • Console (frontend web UI)
  • Channels (DingTalk, Lark, QQ, Discord, iMessage, etc.)
  • Skills
  • CLI
  • Documentation (website)
  • Tests
  • CI/CD
  • Scripts / Deploy

Checklist

  • I ran pre-commit run --all-files locally and it passes
  • If pre-commit auto-fixed files, I committed those changes and reran checks
  • I ran tests locally (pytest or as relevant) and they pass
  • Documentation updated (if needed)
  • Ready for review

For Channel Changes (DingTalk, Lark, QQ, Console, etc.)

  • I ran ./scripts/check-channels.sh (or ./scripts/check-channels.sh --changed) and it passes
  • Contract test exists in tests/contract/channels/test_<channel>_contract.py (REQUIRED)
  • Contract test implements create_instance() with proper channel initialization
  • All 19 contract verification points pass (see tests/contract/channels/__init__.py)
  • Optional: Unit tests in tests/unit/channels/test_<channel>.py for complex internal logic

Testing

[How to test these changes]

Evidence

Examples of valid evidence:

  • Terminal transcript of the test run (e.g. pytest tests/unit/app/chats/ -q output)
  • Screenshot of the Console UI showing the fix
  • CI artifact link
  • pre-commit run --all-files summary
pre-commit run --all-files
# paste summary result

pytest
# paste summary result

Additional Notes

[Optional: any other context]

@github-actions

Copy link
Copy Markdown

Welcome to QwenPaw! 🐾

Hi @hongxicheng, this is your 156th Pull Request.

🙌 Join Developer Community

Thanks so much for your contribution! We'd love to invite you to join the official QwenPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page:
https://qwenpaw.agentscope.io/docs/community

We truly appreciate your enthusiasm—and look forward to your future contributions! 😊

We'll review your PR soon.

@xieyxclack xieyxclack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@hongxicheng
hongxicheng deployed to maintainer-approved August 24, 2026 08:57 — with GitHub Actions Active
@hongxicheng
hongxicheng deployed to maintainer-approved August 26, 2026 04:09 — with GitHub Actions Active
@cuiyuebing
cuiyuebing merged commit 7f82521 into agentscope-ai:main Aug 26, 2026
30 of 31 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in QwenPaw Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature]: 支持配置钉钉群聊上下文模式 / Configurable context modes for DingTalk group chats

3 participants