Files
vibe_data_ana/src/tools/tool_manager.py

53 lines
1.8 KiB
Python
Raw Normal View History

2026-03-09 10:06:21 +08:00
"""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
2026-03-09 10:06:21 +08:00
from src.tools.base import AnalysisTool, ToolRegistry, _global_registry
from src.models import DataProfile
class ToolManager:
"""
2026-03-09 10:06:21 +08:00
Tool manager that selects applicable tools based on data characteristics.
2026-03-09 10:06:21 +08:00
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):
2026-03-09 10:06:21 +08:00
self.registry = registry if registry else _global_registry
self._missing_tools: List[str] = []
2026-03-09 10:06:21 +08:00
def select_tools(self, data_profile: DataProfile) -> List[AnalysisTool]:
"""
2026-03-09 10:06:21 +08:00
Return all tools applicable to this data profile.
Each tool's is_applicable() checks if the data has the right column types.
"""
2026-03-09 10:06:21 +08:00
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))
2026-03-09 10:06:21 +08:00
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
]