-
Notifications
You must be signed in to change notification settings - Fork 99
feature: 支持关闭skill_list_tools tool #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,5 +58,6 @@ def create_skill_tool_set(is_link_stager: bool = True, use_cached_repository: bo | |
| use_cached_repository=use_cached_repository) | ||
| skill_stager = LinkSkillStager() if is_link_stager else CopySkillStager() | ||
| # skill_stager: The stager to use for staging skills. | ||
| skill_toolset = SkillToolSet(repository=repository, run_tool_kwargs=tool_kwargs, skill_stager=skill_stager) | ||
| skill_toolset = SkillToolSet(repository=repository, run_tool_kwargs=tool_kwargs, | ||
| skill_stager=skill_stager, excluded_tools=["skill_list_tools"]) | ||
|
Comment on lines
+61
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 特性落地不一致:本变更在此处通过 触发条件: 运行 实际影响: 修正方向: 统一示例与文档:要么在所有示例中一致启用排除并同步修改提示词,要么保留工具并更新提示词/文档为新的字典返回结构;同时更新 |
||
| return skill_toolset, repository | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,18 +80,25 @@ def __init__(self, | |
| runtime_tools: Optional[List[ToolABC]] = None, | ||
| skill_stager: Optional[Stager] = None, | ||
| skill_config: Optional[dict[str, Any]] = None, | ||
| excluded_tools: Optional[List[str]] = None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 本次提交为 触发条件: 后续迭代修改 实际影响: 排除工具的过滤正确性、缓存行为无测试保障;例如排除名单写错工具名、 修正方向: 在 |
||
| **run_tool_kwargs: dict[str, Any]): | ||
|
Comment on lines
+83
to
84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 新增的 触发条件: 用户按参数定义排除任何被引导文案点名的内置工具(例如 实际影响: 修正方向: 将排除信息同步进技能配置/profile 机制,例如构造 |
||
| """Initialize the skill toolset. | ||
|
|
||
| Args: | ||
| paths: Optional list of skill paths. If None, will create a new one. | ||
| repository: Skill repository. If None, will be retrieved from context metadata. | ||
| enable_hot_reload: Whether to enable skill hot reload checks for | ||
| auto-created repositories. | ||
| repo_resolver: Skill repository resolver. If None, will use the default repository resolver. | ||
| workspace_runtime_resolver: Workspace runtime resolver. | ||
| If None, will use the default workspace runtime resolver. | ||
| enable_hot_reload: Whether to enable skill hot reload checks for auto-created repositories. | ||
| tool_filter: Optional tool filter. If None, will include all tools. | ||
| is_include_all_tools: Optional flag to include all tools. If True, will include all tools. | ||
| user_tools: Optional list of user tools. If None, will not include any user tools. | ||
| run_tool_kwargs: Optional keyword arguments for skill run tool. If None, will use default values. | ||
| create_ws_name_cb: Optional workspace name callback. If None, will use the default workspace name callback. | ||
| runtime_tools: Optional list of runtime tools. If None, will use the default runtime tools. | ||
| skill_stager: Optional skill stager. If None, will use the default skill stager. | ||
| skill_config: Optional skill config. If None, will use the default skill config. | ||
| excluded_tools: Optional list of tools to exclude. If None, will not exclude any tools. | ||
| **run_tool_kwargs: Optional keyword arguments for skill run tool. If None, will use default values. | ||
| """ | ||
| super().__init__(tool_filter=tool_filter, is_include_all_tools=is_include_all_tools) | ||
| self.name = "skill_toolset" | ||
|
|
@@ -136,6 +143,8 @@ def __init__(self, | |
| WorkspaceWriteStdinTool(workspace_exec_tool), | ||
| WorkspaceKillSessionTool(workspace_exec_tool), | ||
| ] | ||
| self._excluded_tools: List[str] = excluded_tools or [] | ||
| self._default_tools: List[ToolABC] = [] | ||
|
Comment on lines
+146
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 本次变更的核心新特性 触发条件: 后续任何人回归 实际影响: 特性本身("支持关闭skill_list_tools")的保证不被任何自动化测试守护,示例中唯一的使用点( 修正方向: 在 |
||
|
|
||
| @property | ||
| def repository(self) -> BaseSkillRepository: | ||
|
|
@@ -152,9 +161,6 @@ async def get_tools(self, invocation_context: Optional[InvocationContext] = None | |
| Returns: | ||
| List of tools from all registered skills | ||
| """ | ||
| tools: List[ToolABC] = [] | ||
| skill_functions: List[SkillToolFunction] = SKILL_REGISTRY.get_all() | ||
| skill_functions.extend(self._function_tools) | ||
| if self._repo_resolver is not None: | ||
| repository = self._repo_resolver(invocation_context) | ||
| else: | ||
|
|
@@ -167,16 +173,35 @@ async def get_tools(self, invocation_context: Optional[InvocationContext] = None | |
| agent_context.with_metadata(SKILL_REPOSITORY_KEY, repository) | ||
| if not is_exist_skill_config(agent_context): | ||
| set_skill_config(agent_context, self._skill_config) | ||
| if self._default_tools: | ||
| return self._default_tools.copy() | ||
|
|
||
| tools: List[ToolABC] = [] | ||
| tools.append(self._load_tool) | ||
| tools.append(self._run_tool) | ||
| tools.append(self._exec_tool) | ||
| tools.extend(self._runtime_tools) | ||
| skill_functions: List[SkillToolFunction] = SKILL_REGISTRY.get_all() | ||
| skill_functions.extend(self._function_tools) | ||
| for skill_function in skill_functions: | ||
| try: | ||
| tools.append(FunctionTool(func=skill_function)) | ||
| except Exception as ex: # pylint: disable=broad-except | ||
| # Log error but continue loading other tools | ||
| logger.warning("Failed to get tools from skill '%s': %s", skill_function.__name__, ex) | ||
| continue | ||
|
|
||
| tools = self._exclude_tools(tools) | ||
| self._default_tools.extend(tools) | ||
|
Comment on lines
+176
to
+194
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: 任意一次 实际影响: 后续所有请求持续返回旧列表:新注册的技能函数永远不会暴露给 LLM,已注销或被 修正方向: 为缓存增加失效条件(例如在 |
||
| return tools | ||
|
Comment on lines
+176
to
195
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: 任一宿主在首次 实际影响: 新注册的技能工具在本进程生命周期内对模型不可见、已注销工具仍可见;同时 修正方向: 删除
Comment on lines
+184
to
195
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 新增的 触发条件: 任何在首个 实际影响: 新注册技能的工具对模型静默缺失,注销也不再生效,工具集内容在整个进程生命周期内陈旧,且无任何告警;这是本次变更引入的行为回归(变更前每次调用都重新求值)。 修正方向: 移除缓存,改为在每次调用时执行排除过滤后直接返回;若确需缓存,则为缓存增加显式失效机制(如监听
Comment on lines
+176
to
195
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 首次调用路径 触发条件: 任何对 实际影响: 未来调用方(或对首调用结果做过滤/裁剪的集成代码)一旦就地修改,缓存即被污染,LLM 请求中出现重复或伪造的工具声明(重复函数声明可能导致模型拒绝请求或歧义工具调用),问题难以排查。 修正方向: 首次调用同样返回 |
||
|
|
||
| def _exclude_tools(self, tools: List[ToolABC]) -> List[ToolABC]: | ||
| """Exclude tools from the list.""" | ||
| if not self._excluded_tools: | ||
| return tools | ||
| available_tools: List[ToolABC] = [] | ||
| for tool in tools: | ||
| name = getattr(tool, "name", None) | ||
| if not name or name in self._excluded_tools: | ||
| continue | ||
| available_tools.append(tool) | ||
| return available_tools | ||
|
Comment on lines
+197
to
+207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 本次提交的核心功能—— 触发条件: 运行现有测试套件即可确认: 实际影响: 排除名称拼写错误、过滤逻辑回归(例如误删具有合法名称的工具)或缓存行为破坏都不会被测试发现;"支持关闭 skill_list_tools" 这一提交主目标本身处于未验证状态。 修正方向: 在
Comment on lines
+197
to
+207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: 用户传入非空 实际影响: 与排除意图无关的工具从 LLM 可见工具集中消失,模型能力静默降级;同名函数被全部排除时用户无法感知排除只应作用于目标工具。 修正方向: 仅跳过 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,18 +20,35 @@ | |
|
|
||
|
|
||
| def skill_list_tools(tool_context: InvocationContext, skill_name: str) -> dict[str, Any]: | ||
| """List callable tools declared for a skill. | ||
| """List tool names declared by a specific skill. | ||
|
|
||
| This only reports tools referenced by the selected skill. It does not list | ||
| every tool available to the agent. An empty result means that this skill | ||
| declares no tools; it does not mean that the agent has no tools available. | ||
|
|
||
| Args: | ||
| skill_name: The name of the skill to load. | ||
| skill_name: The name of the skill to inspect. | ||
|
|
||
| Returns: | ||
| Object containing available tools. | ||
| Object containing the tool names declared by this skill. | ||
| """ | ||
| repository: Optional[BaseSkillRepository] = tool_context.agent_context.get_metadata(SKILL_REPOSITORY_KEY) | ||
| if repository is None: | ||
| raise ValueError("repository not found") | ||
| skill = repository.get(skill_name) | ||
| if skill is None: | ||
| logger.error("Skill %s not found", repr(skill_name)) | ||
| return {"available_tools": []} | ||
| return {"available_tools": list(skill.tools or [])} | ||
| available_tools = [] | ||
| else: | ||
| available_tools = list(skill.tools or []) | ||
| return { | ||
| "skill_name": | ||
| skill_name, | ||
| "available_tools": | ||
| available_tools, | ||
|
Comment on lines
+42
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: LLM 或调用方传入拼写错误/不存在的 实际影响: 模型收到 修正方向: 在返回结构中区分两种情况,例如增加 |
||
| "scope": | ||
| "skill_declared_tools_only", | ||
| "note": | ||
| "Only tools declared by this skill are listed. " | ||
| "This does not represent all tools available to the agent.", | ||
| } | ||
|
Comment on lines
+44
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: 任何按旧契约消费结果的调用方(例如把 实际影响: 相等性/类型断言调用方得到意外结果(新增键导致相等断言失败、LLM 收到非数组负载),提示词与文档会诱导模型按数组格式解析而实际拿到 dict,属于 source-breaking 的兼容性变化;本次仓库内无消费方,但 SDK 属对外发布库,外部影响真实存在。 修正方向: 同步更新两处 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题: 本变更同时修复了
RunnerManager.close()未await的问题(self._runner.close()→await self._runner.close()),经核对Runner.close为async(runners.py:948),修复本身正确;但该修复与"支持关闭skill_list_tools"特性无关,混入同一提交使针对排除功能的回归定位/回滚范围扩大。触发条件: 需要单独回滚或二分定位
excluded_tools相关行为时。实际影响: 无法独立回退关闭工具特性而不连带撤销该关闭相关的修补;提交范围混杂增大审查与维护成本。
修正方向: 将 FastAPI 示例的 close 修复拆分到独立提交(或独立 PR),保持特性提交的单一职责。