Skip to content

fix(plugins): sanitize non-ASCII tool names for strict LLM tool-name …(#272) - #308

Open
chujieHong wants to merge 1 commit into
TencentCloud:developfrom
chujieHong:fix/plugin-tool-names-pr
Open

fix(plugins): sanitize non-ASCII tool names for strict LLM tool-name …(#272)#308
chujieHong wants to merge 1 commit into
TencentCloud:developfrom
chujieHong:fix/plugin-tool-names-pr

Conversation

@chujieHong

Copy link
Copy Markdown
Contributor

…APIs

Plugin tools registered with Chinese names passed straight into the function-calling schema and failed on APIs that require ^[a-zA-Z0-9_-]{1,64}$. Rewrite illegal names to legal pinyin transliterations (underscore fallback when pypinyin is unavailable), dedupe collisions with _2/_3 suffixes, and keep the original name in a [原名: ...] description prefix. Config keys and plugin-side closures still use the original names, so routing and per-agent tool config are unaffected.

Summary

issue:#272
插件允许用中文名注册工具(ctx.tool("文章划分", fn)),但该名称会被原样透传进 function-calling schema。OpenAI/Anthropic 等主流 API 要求工具名匹配 ^[a-zA-Z0-9_-]{1,64}$,导致含中文工具名的插件在对话中调用失败。MCP 工具路径已有 sanitize_llm_tool_name 清洗,唯独插件路径缺失。

新增 plugin_tool_names.py:非法工具名自动转写为合法拼音名(天气查询 → tianqichaxun;pypinyin 不可用时退回下划线替换);重名追加 _2/_3 后缀;超 64 字符截断;改名工具的描述前缀 [原名: …] 保留原名映射
manager.py 的 _build_harness_config 在 build_plugin_tools 后统一清洗,并与 cron/knowledge 工具名去重

Target branch

  • Base is develop (feature / fix — default)
  • Base is main (release/* or hotfix/* only)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactor / chore
  • Release / hotfix

Test plan

新增依赖 pypinyin>=0.53(纯 Python、零传递依赖);uv.lock 手工最小更新(+10 行)
测试:tests/unit/test_plugins.py 新增 8 个用例(拼音转写/去重/截断/无依赖退路/组合链路),全过;ruff、mypy clean

  • make all passes locally
  • Added/updated tests

Checklist

  • Updated CHANGELOG.md (if user-facing)
  • README / docs updated (if needed)

…APIs

Plugin tools registered with Chinese names passed straight into the
function-calling schema and failed on APIs that require
^[a-zA-Z0-9_-]{1,64}$. Rewrite illegal names to legal pinyin
transliterations (underscore fallback when pypinyin is unavailable),
dedupe collisions with _2/_3 suffixes, and keep the original name in a
[原名: ...] description prefix. Config keys and plugin-side closures
still use the original names, so routing and per-agent tool config are
unaffected.
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.

1 participant