Files
JARVIS/backend/app/agents/tools/manifest.py
WIN-JHFT4D3SIVT\caoxiaozhu e5bd492d74 feat(agents): Phase 6 tool system refactoring
Phase 6.1: ToolRegistry infrastructure
- Add ToolManifest with ToolCategory, PermissionClass, SideEffectScope
- Add ToolRegistry singleton with register/get/unregister/list/search
- Add BaseTool abstract class with ReadTool/WriteTool/DBWriteTool/ExternalTool/NetworkTool subclasses
- Add migration layer for backward compatibility

Phase 6.2: Hook interception system
- Add HookType (PRE_TOOL_USE, POST_TOOL_USE, TOOL_ERROR, TOOL_SKIP)
- Add HookManager with singleton for hook registration
- Add HookExecutor for pre/post/error hook execution

Phase 6.3: Streaming execution
- Add StreamingToolExecutor with batch execution support

Phase 6.4: New builtin tools
- Add file_tools: GlobTool, GrepTool, ReadFileTool, WriteFileTool
- Add system_tools: BashTool, PowerShellTool
- Add dev_tools: LSPTools, GitTool
- Add collaboration_tools: TeamAgentTool, TaskBroadcastTool

Tests: 29 passed
2026-04-04 22:47:48 +08:00

78 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""工具元数据和数据类型定义"""
from dataclasses import dataclass, field
from enum import Enum
from typing import Any
class ToolCategory(Enum):
"""工具类别"""
READ = "read"
WRITE = "write"
EXTERNAL = "external"
DB_WRITE = "db_write"
NETWORK = "network"
class SideEffectScope(Enum):
"""副作用范围"""
NONE = "none"
LOCAL_STATE = "local_state"
DB_WRITE = "db_write"
NETWORK = "network"
class PermissionClass(Enum):
"""权限级别"""
READ = "read"
WRITE = "write"
EXTERNAL = "external"
@dataclass
class ToolManifest:
"""工具元数据"""
name: str
description: str
category: ToolCategory
parameters: dict[str, Any] # JSON Schema
return_schema: dict[str, Any]
permission_class: PermissionClass
side_effect_scope: SideEffectScope
requires_confirmation: bool = False
is_streaming: bool = False
tags: list[str] = field(default_factory=list)
def to_dict(self) -> dict[str, Any]:
return {
"name": self.name,
"description": self.description,
"category": self.category.value,
"parameters": self.parameters,
"return_schema": self.return_schema,
"permission_class": self.permission_class.value,
"side_effect_scope": self.side_effect_scope.value,
"requires_confirmation": self.requires_confirmation,
"is_streaming": self.is_streaming,
"tags": self.tags,
}
@dataclass
class HookConfig:
"""Hook 配置"""
name: str
hook_type: str # "pre_tool_use", "post_tool_use", "tool_error", "tool_skip"
filter_names: list[str] | None = None # 只对特定工具生效None 表示全部
def matches_tool(self, tool_name: str) -> bool:
"""检查 Hook 是否对指定工具生效"""
if self.filter_names is None:
return True
return tool_name in self.filter_names