feat(tools): Phase T.1-T.4 complete - manifest system, registry, implementations, runtime, collaboration, scheduler
This commit is contained in:
13
backend/app/tools/schemas/__init__.py
Normal file
13
backend/app/tools/schemas/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Schemas Module
|
||||
from tools.schemas.manifest import ToolManifest, ToolType, RuntimeType, InvocationCommand
|
||||
from tools.schemas.tool_call import ToolCallRequest, ToolCallResponse, ToolExecutionLog
|
||||
|
||||
__all__ = [
|
||||
"ToolManifest",
|
||||
"ToolType",
|
||||
"RuntimeType",
|
||||
"InvocationCommand",
|
||||
"ToolCallRequest",
|
||||
"ToolCallResponse",
|
||||
"ToolExecutionLog",
|
||||
]
|
||||
70
backend/app/tools/schemas/manifest.py
Normal file
70
backend/app/tools/schemas/manifest.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
Tool Manifest Schema
|
||||
|
||||
Defines the structure for tool manifest declarations following VCPToolBox plugin patterns.
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, List, Dict, Any
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ToolType(str, Enum):
|
||||
"""Tool execution type"""
|
||||
|
||||
SYNC = "sync" # Synchronous execution
|
||||
ASYNC = "async" # Asynchronous execution
|
||||
SERVICE = "service" # Continuous running service
|
||||
|
||||
|
||||
class RuntimeType(str, Enum):
|
||||
"""Runtime type for tool execution"""
|
||||
|
||||
PYTHON = "python"
|
||||
JAVASCRIPT = "javascript"
|
||||
NATIVE = "native"
|
||||
|
||||
|
||||
class InvocationCommand(BaseModel):
|
||||
"""Command definition for tool invocation"""
|
||||
|
||||
name: str = Field(..., description="Command name")
|
||||
description: str = Field(..., description="Command description (for AI)")
|
||||
parameters: Optional[Dict[str, Any]] = Field(default=None, description="Parameters JSON Schema")
|
||||
required: Optional[List[str]] = Field(default=None, description="Required parameter list")
|
||||
example: Optional[str] = Field(default=None, description="Invocation example")
|
||||
|
||||
|
||||
class ToolManifest(BaseModel):
|
||||
"""Tool Manifest - declarative tool definition"""
|
||||
|
||||
manifest_version: str = Field(default="1.0.0", description="Manifest version")
|
||||
name: str = Field(..., description="Tool name (English, unique)")
|
||||
display_name: str = Field(..., description="Display name (Chinese)")
|
||||
description: str = Field(..., description="Tool description")
|
||||
author: Optional[str] = Field(default=None, description="Author")
|
||||
version: str = Field(default="1.0.0", description="Version number")
|
||||
|
||||
# Execution configuration
|
||||
type: ToolType = Field(default=ToolType.SYNC, description="Tool type")
|
||||
runtime: RuntimeType = Field(default=RuntimeType.PYTHON, description="Runtime")
|
||||
entry: str = Field(..., description="Execution entry (file path or command)")
|
||||
timeout: int = Field(default=30000, description="Timeout (milliseconds)")
|
||||
|
||||
# Configuration
|
||||
config_schema: Optional[Dict[str, Any]] = Field(
|
||||
default=None, description="Configuration schema"
|
||||
)
|
||||
|
||||
# Capabilities
|
||||
commands: List[InvocationCommand] = Field(
|
||||
default_factory=list, description="Available commands"
|
||||
)
|
||||
|
||||
# Metadata
|
||||
tags: Optional[List[str]] = Field(default=None, description="Tags")
|
||||
dependencies: Optional[List[str]] = Field(default=None, description="Dependency tools")
|
||||
enabled: bool = Field(default=True, description="Whether enabled")
|
||||
|
||||
class Config:
|
||||
use_enum_values = True
|
||||
46
backend/app/tools/schemas/tool_call.py
Normal file
46
backend/app/tools/schemas/tool_call.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Tool Call Schema
|
||||
|
||||
Defines request/response structures for tool invocation.
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, Dict, Any, List
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class ToolCallRequest(BaseModel):
|
||||
"""Tool call request"""
|
||||
|
||||
tool_name: str = Field(..., description="Tool name")
|
||||
command: str = Field(..., description="Command name")
|
||||
parameters: Dict[str, Any] = Field(default_factory=dict, description="Parameters")
|
||||
timeout: Optional[int] = Field(default=None, description="Timeout override")
|
||||
context: Optional[Dict[str, Any]] = Field(default=None, description="Context information")
|
||||
|
||||
|
||||
class ToolCallResponse(BaseModel):
|
||||
"""Tool call response"""
|
||||
|
||||
status: str = Field(..., description="Status: success/error")
|
||||
result: Optional[Any] = Field(default=None, description="Execution result")
|
||||
error: Optional[str] = Field(default=None, description="Error message")
|
||||
message: Optional[str] = Field(default=None, description="AI-friendly message")
|
||||
base64: Optional[str] = Field(default=None, description="Base64 data")
|
||||
duration_ms: Optional[int] = Field(default=None, description="Execution duration")
|
||||
timestamp: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class ToolExecutionLog(BaseModel):
|
||||
"""Tool execution log"""
|
||||
|
||||
id: str
|
||||
tool_name: str
|
||||
command: str
|
||||
parameters: Dict[str, Any]
|
||||
status: str
|
||||
duration_ms: int
|
||||
error: Optional[str] = None
|
||||
user_id: Optional[str] = None
|
||||
agent_id: Optional[str] = None
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
37
backend/app/tools/schemas/validator.py
Normal file
37
backend/app/tools/schemas/validator.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Schema Validator
|
||||
|
||||
Validates tool manifests and tool calls against their schemas.
|
||||
"""
|
||||
|
||||
from pydantic import ValidationError
|
||||
from tools.schemas.manifest import ToolManifest
|
||||
from tools.schemas.tool_call import ToolCallRequest
|
||||
|
||||
|
||||
class ManifestValidationError(Exception):
|
||||
"""Manifest validation error"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ToolCallValidationError(Exception):
|
||||
"""Tool call validation error"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def validate_manifest(data: dict) -> ToolManifest:
|
||||
"""Validate manifest data against ToolManifest schema"""
|
||||
try:
|
||||
return ToolManifest(**data)
|
||||
except ValidationError as e:
|
||||
raise ManifestValidationError(str(e))
|
||||
|
||||
|
||||
def validate_tool_call(data: dict) -> ToolCallRequest:
|
||||
"""Validate tool call request against ToolCallRequest schema"""
|
||||
try:
|
||||
return ToolCallRequest(**data)
|
||||
except ValidationError as e:
|
||||
raise ToolCallValidationError(str(e))
|
||||
Reference in New Issue
Block a user