- Enhanced `ARCHITECTURE.md` with details on LLM models for work (Llama 3.1 70B Q4) and family agents (Phi-3 Mini 3.8B Q4). - Introduced new documents: - `ASR_EVALUATION.md` for ASR engine evaluation and selection. - `HARDWARE.md` outlining hardware requirements and purchase plans. - `IMPLEMENTATION_GUIDE.md` for Milestone 2 implementation steps. - `LLM_CAPACITY.md` assessing VRAM and context window limits. - `LLM_MODEL_SURVEY.md` surveying open-weight LLM models. - `LLM_USAGE_AND_COSTS.md` detailing LLM usage and operational costs. - `MCP_ARCHITECTURE.md` describing the Model Context Protocol architecture. - `MCP_IMPLEMENTATION_SUMMARY.md` summarizing MCP implementation status. These updates provide comprehensive guidance for the next phases of development and ensure clarity in project documentation.
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""
|
|
Tool Registry - Manages tool registration and execution.
|
|
"""
|
|
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
# Add parent directory to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
from tools.echo import EchoTool
|
|
from tools.weather import WeatherTool
|
|
from tools.time import (
|
|
GetCurrentTimeTool,
|
|
GetDateTool,
|
|
GetTimezoneInfoTool,
|
|
ConvertTimezoneTool
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ToolRegistry:
|
|
"""Registry for MCP tools."""
|
|
|
|
def __init__(self):
|
|
"""Initialize tool registry with default tools."""
|
|
self._tools: Dict[str, Any] = {}
|
|
self._register_default_tools()
|
|
|
|
def _register_default_tools(self):
|
|
"""Register default tools."""
|
|
self.register_tool(EchoTool())
|
|
self.register_tool(WeatherTool())
|
|
self.register_tool(GetCurrentTimeTool())
|
|
self.register_tool(GetDateTool())
|
|
self.register_tool(GetTimezoneInfoTool())
|
|
self.register_tool(ConvertTimezoneTool())
|
|
logger.info(f"Registered {len(self._tools)} tools")
|
|
|
|
def register_tool(self, tool):
|
|
"""Register a tool."""
|
|
self._tools[tool.name] = tool
|
|
logger.info(f"Registered tool: {tool.name}")
|
|
|
|
def list_tools(self) -> List[Dict[str, Any]]:
|
|
"""List all registered tools with their schemas."""
|
|
return [tool.get_schema() for tool in self._tools.values()]
|
|
|
|
def call_tool(self, name: str, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""
|
|
Call a tool by name with arguments.
|
|
|
|
Returns:
|
|
Dict with 'content' list containing tool results
|
|
"""
|
|
if name not in self._tools:
|
|
raise ValueError(f"Tool not found: {name}")
|
|
|
|
tool = self._tools[name]
|
|
logger.info(f"Calling tool: {name} with arguments: {arguments}")
|
|
|
|
try:
|
|
result = tool.execute(arguments)
|
|
return {
|
|
"content": [
|
|
{
|
|
"type": "text",
|
|
"text": str(result)
|
|
}
|
|
]
|
|
}
|
|
except Exception as e:
|
|
logger.error(f"Tool execution error: {e}", exc_info=True)
|
|
raise
|