GaiaAgentEvaluator / utils /tool_selection.py
davidgturner's picture
- changes for app.py
08e2c16
# Tool selection utilities for determining which tools to use
from config import (
YOUTUBE_PATTERNS, REVERSE_TEXT_PATTERNS, WIKIPEDIA_PATTERNS,
WEB_SEARCH_PATTERNS, AI_PATTERNS, FILE_PATTERNS
)
def determine_tools_needed(question):
"""Determine which tools should be used for a given question."""
question_lower = question.lower()
# YouTube detection
needs_youtube = any(pattern in question_lower for pattern in YOUTUBE_PATTERNS)
# Reverse text detection
is_reverse_text = (
any(pattern in question_lower for pattern in REVERSE_TEXT_PATTERNS) or
(question_lower != question_lower[::-1] and
"ecnetnes" in question_lower or "sdrow" in question_lower)
)
# Wikipedia detection
needs_wikipedia = any(pattern in question_lower for pattern in WIKIPEDIA_PATTERNS)
# Web search detection
needs_web_search = any(pattern in question_lower for pattern in WEB_SEARCH_PATTERNS)
# Knowledge retrieval for AI/agent questions
needs_knowledge = any(term in question_lower for term in AI_PATTERNS)
# File analysis detection
has_file_analysis = any(pattern in question_lower for pattern in FILE_PATTERNS)
return {
"use_youtube": needs_youtube,
"use_wikipedia": needs_wikipedia,
"is_reverse_text": is_reverse_text,
"use_web_search": needs_web_search,
"use_knowledge_retrieval": needs_knowledge,
"use_webpage_visit": needs_web_search and ("link" in question_lower or "paper" in question_lower),
"has_file_analysis": has_file_analysis
}
def needs_special_handling(question, tool_selection):
"""Check if question needs special handling beyond standard tools."""
question_lower = question.lower()
# Reverse text questions
if tool_selection.get("is_reverse_text", False):
return True
# Mathematical table analysis
if "table" in question_lower and ("commutative" in question_lower or "operation" in question_lower):
return True
# Grocery/botany questions
if "grocery" in question_lower and "botany" in question_lower:
return True
# File analysis questions
if tool_selection.get("has_file_analysis", False):
return True
return False