fix(plugins): sanitize non-ASCII tool names for strict LLM tool-name …(#272) - #308
Open
chujieHong wants to merge 1 commit into
Open
fix(plugins): sanitize non-ASCII tool names for strict LLM tool-name …(#272)#308chujieHong wants to merge 1 commit into
chujieHong wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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
develop(feature / fix — default)main(release/*orhotfix/*only)Type of change
Test plan
新增依赖 pypinyin>=0.53(纯 Python、零传递依赖);uv.lock 手工最小更新(+10 行)
测试:tests/unit/test_plugins.py 新增 8 个用例(拼音转写/去重/截断/无依赖退路/组合链路),全过;ruff、mypy clean
make allpasses locallyChecklist
CHANGELOG.md(if user-facing)