53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
"""Tool manager — selects applicable tools based on data profile.
|
|
|
|
The ToolManager filters tools by data type compatibility (e.g., time series tools
|
|
need datetime columns). The actual tool+parameter selection is fully AI-driven.
|
|
"""
|
|
|
|
from typing import List, Dict, Any
|
|
|
|
from src.tools.base import AnalysisTool, ToolRegistry, _global_registry
|
|
from src.models import DataProfile
|
|
|
|
|
|
class ToolManager:
|
|
"""
|
|
Tool manager that selects applicable tools based on data characteristics.
|
|
|
|
This is a filter, not a decision maker. AI decides which tools to actually
|
|
call and with what parameters at runtime.
|
|
"""
|
|
|
|
def __init__(self, registry: ToolRegistry = None):
|
|
self.registry = registry if registry else _global_registry
|
|
self._missing_tools: List[str] = []
|
|
|
|
def select_tools(self, data_profile: DataProfile) -> List[AnalysisTool]:
|
|
"""
|
|
Return all tools applicable to this data profile.
|
|
Each tool's is_applicable() checks if the data has the right column types.
|
|
"""
|
|
self._missing_tools = []
|
|
return self.registry.get_applicable_tools(data_profile)
|
|
|
|
def get_all_tools(self) -> List[AnalysisTool]:
|
|
"""Return all registered tools regardless of data profile."""
|
|
tool_names = self.registry.list_tools()
|
|
return [self.registry.get_tool(name) for name in tool_names]
|
|
|
|
def get_missing_tools(self) -> List[str]:
|
|
return list(set(self._missing_tools))
|
|
|
|
def get_tool_descriptions(self, tools: List[AnalysisTool] = None) -> List[Dict[str, Any]]:
|
|
"""Get tool descriptions for AI consumption."""
|
|
if tools is None:
|
|
tools = self.get_all_tools()
|
|
return [
|
|
{
|
|
'name': t.name,
|
|
'description': t.description,
|
|
'parameters': t.parameters
|
|
}
|
|
for t in tools
|
|
]
|