根据事件中的插件设置,过滤请求中的工具列表。 注意:没有 handler_module_path 的工具(如 MCP 工具)会被保留, 因为它们不属于任何插件,不应被插件过滤逻辑影响。
(event: AstrMessageEvent, req: ProviderRequest)
| 993 | |
| 994 | |
| 995 | def _plugin_tool_fix(event: AstrMessageEvent, req: ProviderRequest) -> None: |
| 996 | """根据事件中的插件设置,过滤请求中的工具列表。 |
| 997 | |
| 998 | 注意:没有 handler_module_path 的工具(如 MCP 工具)会被保留, |
| 999 | 因为它们不属于任何插件,不应被插件过滤逻辑影响。 |
| 1000 | """ |
| 1001 | if event.plugins_name is not None and req.func_tool: |
| 1002 | new_tool_set = ToolSet() |
| 1003 | for tool in req.func_tool.tools: |
| 1004 | if isinstance(tool, MCPTool): |
| 1005 | # 保留 MCP 工具 |
| 1006 | new_tool_set.add_tool(tool) |
| 1007 | continue |
| 1008 | mp = tool.handler_module_path |
| 1009 | if not mp: |
| 1010 | # 没有 plugin 归属信息的工具(如 subagent transfer_to_*) |
| 1011 | # 不应受到会话插件过滤影响。 |
| 1012 | new_tool_set.add_tool(tool) |
| 1013 | continue |
| 1014 | plugin = star_map.get(mp) |
| 1015 | if not plugin: |
| 1016 | # 无法解析插件归属时,保守保留工具,避免误过滤。 |
| 1017 | new_tool_set.add_tool(tool) |
| 1018 | continue |
| 1019 | if plugin.name in event.plugins_name or plugin.reserved: |
| 1020 | new_tool_set.add_tool(tool) |
| 1021 | req.func_tool = new_tool_set |
| 1022 | |
| 1023 | |
| 1024 | async def _handle_webchat( |
no test coverage detected