|
|
@@ -14,7 +14,9 @@ import json
|
|
|
import inspect
|
|
|
import logging
|
|
|
import time
|
|
|
-from typing import Any, Callable, Dict, List, Optional
|
|
|
+from typing import Any, Callable, Dict, List, Optional, Sequence
|
|
|
+
|
|
|
+from agent.tools.models import ToolCapability
|
|
|
|
|
|
from agent.tools.url_matcher import filter_by_url
|
|
|
|
|
|
@@ -70,6 +72,7 @@ class ToolRegistry:
|
|
|
hidden_params: Optional[List[str]] = None,
|
|
|
inject_params: Optional[Dict[str, Any]] = None,
|
|
|
groups: Optional[List[str]] = None,
|
|
|
+ capabilities: Optional[Sequence[ToolCapability | str]] = None,
|
|
|
):
|
|
|
"""
|
|
|
注册工具
|
|
|
@@ -84,6 +87,7 @@ class ToolRegistry:
|
|
|
hidden_params: 隐藏参数列表(不生成 schema,LLM 看不到)
|
|
|
inject_params: 注入参数规则 {param_name: injector_func}
|
|
|
groups: 工具分组标签(如 ["core"]、["browser"]),用于 RunConfig.tool_groups 过滤
|
|
|
+ capabilities: 安全副作用标签;explicit_validation 工具必须显式声明
|
|
|
"""
|
|
|
func_name = func.__name__
|
|
|
|
|
|
@@ -103,6 +107,7 @@ class ToolRegistry:
|
|
|
"hidden_params": hidden_params or [],
|
|
|
"inject_params": inject_params or {},
|
|
|
"groups": groups or [],
|
|
|
+ "capabilities": frozenset(ToolCapability(item) for item in capabilities or []),
|
|
|
"ui_metadata": {
|
|
|
"requires_confirmation": requires_confirmation,
|
|
|
"editable_params": editable_params or [],
|
|
|
@@ -208,6 +213,13 @@ class ToolRegistry:
|
|
|
groups.update(tool.get("groups", []))
|
|
|
return sorted(groups)
|
|
|
|
|
|
+ def get_capabilities(self, tool_name: str) -> frozenset[ToolCapability]:
|
|
|
+ """Return declared effects; an empty set means unclassified."""
|
|
|
+ tool = self._tools.get(tool_name)
|
|
|
+ if not tool:
|
|
|
+ return frozenset()
|
|
|
+ return frozenset(tool.get("capabilities", ()))
|
|
|
+
|
|
|
def get_schemas_for_url(self, current_url: Optional[str] = None) -> List[Dict]:
|
|
|
"""
|
|
|
根据当前 URL 获取匹配的工具 Schema
|
|
|
@@ -516,6 +528,7 @@ def tool(
|
|
|
hidden_params: Optional[List[str]] = None,
|
|
|
inject_params: Optional[Dict[str, Any]] = None,
|
|
|
groups: Optional[List[str]] = None,
|
|
|
+ capabilities: Optional[Sequence[ToolCapability | str]] = None,
|
|
|
):
|
|
|
"""
|
|
|
工具装饰器 - 自动注册工具并生成 Schema
|
|
|
@@ -530,6 +543,7 @@ def tool(
|
|
|
hidden_params: 隐藏参数列表(不生成 schema,LLM 看不到)
|
|
|
inject_params: 注入参数规则 {param_name: injector_func}
|
|
|
groups: 工具分组标签(如 ["core"]、["browser"]),用于 RunConfig.tool_groups 过滤
|
|
|
+ capabilities: 安全副作用标签(read/write/agent_spawn/external_send 等)
|
|
|
|
|
|
Example:
|
|
|
@tool(
|
|
|
@@ -565,6 +579,7 @@ def tool(
|
|
|
hidden_params=hidden_params,
|
|
|
inject_params=inject_params,
|
|
|
groups=groups,
|
|
|
+ capabilities=capabilities,
|
|
|
)
|
|
|
return func
|
|
|
|