Skip to content

Feat/dingtalk ai table docs#2465

Open
zjncs wants to merge 8 commits intoagentscope-ai:mainfrom
zjncs:feat/dingtalk-ai-table-docs
Open

Feat/dingtalk ai table docs#2465
zjncs wants to merge 8 commits intoagentscope-ai:mainfrom
zjncs:feat/dingtalk-ai-table-docs

Conversation

@zjncs
Copy link
Copy Markdown

@zjncs zjncs commented Mar 28, 2026

Description

This PR adds DingTalk AI table and document operation support to CoPaw as built-in agent tools.

For DingTalk AI tables, this PR adds built-in tools for:

  • listing sheets
  • getting a sheet
  • creating a sheet
  • getting a record
  • listing records
  • inserting records
  • updating records
  • deleting records

For DingTalk documents, this PR adds built-in tools for:

  • listing accessible workspaces
  • getting workspace metadata
  • listing directory entries
  • getting dentry metadata
  • creating a document

This PR also introduces a shared DingTalk OpenAPI client used by both the DingTalk channel and the new tools. The client now handles access token caching, JSON request handling, transient retry for safe reads, and boolean query param normalization.

The document MVP scope intentionally excludes template listing and rich-text/body editing APIs, because they were not needed for the validated MVP path.

Related Issue: Relates to #2291

Security Considerations: Reuses the existing DingTalk client_id / client_secret from agent channel configuration. Credentials are not exposed as tool parameters. Requests are sent through the DingTalk OpenAPI client with existing token 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, Feishu, 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

Testing

Tested locally with:

  • python3 -m py_compile for the changed DingTalk tool/client/config files
  • python3 -m pytest -q tests/unit/agents/tools/test_dingtalk_tools.py tests/unit/app/channels/dingtalk/test_openapi_client.py tests/unit/app/test_chat_api.py tests/unit/agents/test_memory_fallback.py

Also verified against a real DingTalk app configuration:

  • AI table read APIs succeeded
  • AI table create-sheet API succeeded
  • document workspace listing succeeded
  • workspace metadata query succeeded
  • directory listing succeeded
  • dentry query succeeded
  • document creation succeeded

Local Verification Evidence

python3 -m pytest -q tests/unit/agents/tools/test_dingtalk_tools.py \
  tests/unit/app/channels/dingtalk/test_openapi_client.py \
  tests/unit/app/test_chat_api.py \
  tests/unit/agents/test_memory_fallback.py

29 passed, 2 warnings in 2.53s

@github-actions github-actions bot added the first-time-contributor PR created by a first time contributor label Mar 28, 2026
@github-actions
Copy link
Copy Markdown

Welcome to CoPaw! 🐾

Hi @zjncs, thank you for your first Pull Request! 🎉

🙌 Join Developer Community

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

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

We'll review your PR soon.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive set of DingTalk tools for AI table and document operations, supported by a new centralized DingTalkOpenAPIClient that handles token caching, retries, and error management. Additionally, it enhances the system's robustness by implementing memory fallback mechanisms and improved error handling for malformed session states. A critical performance issue was identified in the DingTalk tool implementations, where the repeated instantiation of HTTP sessions and API clients for every request negates the benefits of token caching and increases latency.

Comment on lines +96 to +101
async with aiohttp.ClientSession(timeout=_HTTP_TIMEOUT) as session:
client = DingTalkOpenAPIClient(
client_id=client_id,
client_secret=client_secret,
http_session=session,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Creating a new aiohttp.ClientSession and DingTalkOpenAPIClient for each tool call is inefficient and defeats the purpose of the token caching implemented in DingTalkOpenAPIClient.

This will result in:

  • Increased latency due to new TCP connections for every request.
  • Unnecessary calls to the DingTalk accessToken endpoint for every tool use, which can lead to performance issues and hitting API rate limits.

It is recommended to refactor this to reuse a single aiohttp.ClientSession and DingTalkOpenAPIClient instance across all DingTalk tool calls. The implementation in src/copaw/app/channels/dingtalk/channel.py provides a good example of managing a shared client instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time-contributor PR created by a first time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant