Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/skills/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
return skill_toolset, repository
13 changes: 6 additions & 7 deletions examples/team_with_skill/agent/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@

Mandatory execution order for every user request:
1. Call `skill_list` and confirm `leader-research` exists.
2. Call `skill_list_tools` for `leader-research`.
3. Call `skill_load` for `leader-research`.
4. Call `skill_run` with command:
2. Call `skill_load` for `leader-research`.
3. Call `skill_run` with command:
`bash scripts/gather_points.sh "<user topic>" out/leader_notes.txt`
and set `output_files` to include `out/leader_notes.txt`.
5. Then delegate to `researcher` exactly once.
6. Then delegate to `writer` exactly once.
7. Synthesize and return final answer.
4. Then delegate to `researcher` exactly once.
5. Then delegate to `writer` exactly once.
6. Synthesize and return final answer.

Rules:
- Never call `delegate_to_member` before step 4 succeeds.
- Never call `delegate_to_member` before step 3 succeeds.
- Use current-year context in final answer.
- Keep the final answer concise and practical.
"""
Expand Down
16 changes: 12 additions & 4 deletions tests/skills/tools/test_skill_list_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@

from trpc_agent_sdk.skills._types import Skill, SkillSummary
from trpc_agent_sdk.skills.tools._skill_list_tool import (
skill_list_tools,
)

skill_list_tools, )

# ---------------------------------------------------------------------------
# skill_list_tools
# ---------------------------------------------------------------------------


def _make_ctx(repository=None):
ctx = MagicMock()
ctx.agent_context.get_metadata = MagicMock(return_value=repository)
return ctx


class TestSkillListTools:

def test_returns_tools(self):
skill = Skill(
summary=SkillSummary(name="test"),
Expand All @@ -39,15 +39,21 @@ def test_returns_tools(self):
ctx = _make_ctx(repository=repo)

result = skill_list_tools(ctx, "test")
assert result["skill_name"] == "test"
assert result["available_tools"] == ["get_weather", "get_data"]
assert result["scope"] == "skill_declared_tools_only"
assert "not represent all tools available to the agent" in result["note"]

def test_skill_not_found(self):
repo = MagicMock()
repo.get = MagicMock(return_value=None)
ctx = _make_ctx(repository=repo)

result = skill_list_tools(ctx, "nonexistent")
assert result == {"available_tools": []}
assert result["skill_name"] == "nonexistent"
assert result["available_tools"] == []
assert result["scope"] == "skill_declared_tools_only"
assert "not represent all tools available to the agent" in result["note"]

def test_no_repository_raises(self):
ctx = _make_ctx(repository=None)
Expand All @@ -61,4 +67,6 @@ def test_no_tools_or_examples(self):
ctx = _make_ctx(repository=repo)

result = skill_list_tools(ctx, "test")
assert result["skill_name"] == "test"
assert result["available_tools"] == []
assert result["scope"] == "skill_declared_tools_only"
40 changes: 32 additions & 8 deletions trpc_agent_sdk/skills/_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,24 @@ 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,
**run_tool_kwargs: dict[str, Any]):
Comment on lines +83 to 84

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.

问题: 新增的 excluded_tools 只在 SkillToolSet.get_tools 一层过滤工具,与 SkillsRequestProcessor/SkillProfileFlags 生成系统提示词引导的既有机制完全脱节,二者之间没有任何信息传递。

触发条件: 用户按参数定义排除任何被引导文案点名的内置工具(例如 excluded_tools=["skill_run"]["skill_select_tools"]["skill_list_skills"]),同时 Agent 按示例标准接法设置了 skill_repository,使 SkillsRequestProcessor 以默认 full profile 注入引导。

实际影响: trpc_agent_sdk/agents/core/_skill_processor.py_tooling_guidance_text_default_full_tooling_and_workspace_guidance 仍会指示 LLM 使用已被排除的工具(如 "Use the skill_select_tools tool..." 以及大量 skill_run/skill_exec 指引),LLM 随后调用不存在的工具,触发 tool_not_found 错误事件,浪费对话轮次甚至导致任务失败。变更前工具无法从工具集中移除,引导不会指向不存在的工具。

修正方向: 将排除信息同步进技能配置/profile 机制,例如构造 SkillsRequestProcessor 时从 SkillToolSet 读取 excluded_tools 并并入 forbidden_tools/SkillProfileFlags 解析,或在参数文档中明确 excluded_tools 仅适用于引导文案未点名的工具,保证引导与实际可用工具集一致。

"""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"
Expand Down Expand Up @@ -136,6 +142,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] = []

@property
def repository(self) -> BaseSkillRepository:
Expand All @@ -152,9 +160,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:
Expand All @@ -167,16 +172,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 +175 to +193

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.

问题: get_tools 新增的 self._default_tools 结果缓存没有任何失效机制,也未做线程同步;首次调用构建后工具列表即被永久冻结,与该方法文档字符串 "Get all tools from registered skills" 的契约不符。

触发条件: 任意一次 get_tools 完成缓存填充(首次 LLM 请求的 process_llm_request 即触发)之后,运行期通过 SkillRegistry 单例的 register/unregister/clear 变更技能函数(SkillRegistry() 与模块级 SKILL_REGISTRY 是同一单例),或调用方追加传入的 runtime_tools 列表;此外多线程并发执行首次 get_tools 时,"检查为空—构建—extend" 序列会交错执行。

实际影响: 后续所有请求持续返回旧列表:新注册的技能函数永远不会暴露给 LLM,已注销或被 clear 的技能函数继续暴露;并发首次调用还会把构建结果重复 extend 进缓存,使后续请求携带同名重复工具,LLM 请求出现重复 function declaration 并可能被模型接口拒绝。变更前 get_tools 每次重新执行 SKILL_REGISTRY.get_all(),不存在上述问题。

修正方向: 为缓存增加失效条件(例如在 SkillRegistry 变更时递增版本号并在 get_tools 中比对,或只缓存静态内置工具、每次调用重新解析注册表函数),并将 self._default_tools.extend(tools) 改为原子赋值 self._default_tools = tools 或加锁,消除并发重复写入。

return tools

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 +196 to +206

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.

问题: 本次提交的核心功能——excluded_tools 参数、_exclude_tools 过滤逻辑和 _default_tools 缓存——没有任何测试覆盖。

触发条件: 运行现有测试套件即可确认:tests/skills/test_toolset.py 未新增用例且只断言默认工具存在,tests/skills/tools/test_skill_list_tool.py 仅断言返回结构,没有任何用例构造带 excluded_toolsSkillToolSet

实际影响: 排除名称拼写错误、过滤逻辑回归(例如误删具有合法名称的工具)或缓存行为破坏都不会被测试发现;"支持关闭 skill_list_tools" 这一提交主目标本身处于未验证状态。

修正方向:tests/skills/test_toolset.py 补充用例:默认包含 skill_list_tools;传入 excluded_tools=["skill_list_tools"] 后该工具被移除且其余工具保留;连续两次调用 get_tools 返回一致结果。

27 changes: 22 additions & 5 deletions trpc_agent_sdk/skills/tools/_skill_list_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

问题: skill_list_tools 对"技能不存在"与"技能未声明工具"两种情况返回完全相同的载荷(available_tools 为空且携带同一段 note),而本次新增的文档字符串和 note 断言 "An empty result means that this skill declares no tools",该断言在技能不存在的路径上不成立。

触发条件: LLM 或调用方传入拼写错误/不存在的 skill_name(如 "leader-researchx"),repository.get 返回 None,代码仅记录 logger.error 后以空列表落入共享返回结构。

实际影响: 模型收到 skill_name 回显、空 available_tools 和 "Only tools declared by this skill are listed..." 的说明,会把"技能不存在"误读为"该技能存在但未声明工具",在后续推理中得出错误结论(例如向用户报告技能没有工具而不是技能不存在),与本次变更想澄清返回语义的目标相悖。

修正方向: 在返回结构中区分两种情况,例如增加 found/status 字段,技能不存在时返回明确的 "skill not found" 提示;或保留命中路径才附加 note 的区分逻辑。

"scope":
"skill_declared_tools_only",
"note":
"Only tools declared by this skill are listed. "
"This does not represent all tools available to the agent.",
}
Loading