Spaces:
Running
Running
File size: 10,320 Bytes
9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc 9a6a4dc 8de15cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
"""
Complete Enhanced GAIA Agent - All Phase 1-6 Improvements
Integrates all enhanced tools for maximum GAIA evaluation performance
"""
import os
import logging
from typing import Dict, Any, List, Optional, Union
from pathlib import Path
# Import the enhanced unified AGNO agent as base
try:
from .enhanced_unified_agno_agent import GAIAAgent as BaseGAIAAgent
BASE_AGENT_AVAILABLE = True
except ImportError:
try:
from enhanced_unified_agno_agent import GAIAAgent as BaseGAIAAgent
BASE_AGENT_AVAILABLE = True
except ImportError:
BaseGAIAAgent = None
BASE_AGENT_AVAILABLE = False
# Import all Phase 1-6 enhanced tools
PHASE_TOOLS_STATUS = {}
# Phase 1: Web Research Enhancement
try:
from tools.web_research_tool import WebResearchTool
from tools.wikipedia_tool import WikipediaResearchTool
from tools.research_orchestrator import ResearchOrchestrator
PHASE_TOOLS_STATUS['phase1_web_research'] = True
except ImportError as e:
PHASE_TOOLS_STATUS['phase1_web_research'] = f"Import error: {e}"
# Phase 2: Audio Processing
try:
from tools.audio_processing_tool import AudioProcessingTool
from tools.audio_content_analyzer import AudioContentAnalyzer
PHASE_TOOLS_STATUS['phase2_audio'] = True
except ImportError as e:
PHASE_TOOLS_STATUS['phase2_audio'] = f"Import error: {e}"
# Phase 3: Mathematical Code Execution
try:
from tools.mathematical_engine import MathematicalEngine
from tools.code_execution_tool import CodeExecutionTool
from tools.agno_compatible_math_tools import AGNOCompatibleMathTools
PHASE_TOOLS_STATUS['phase3_math'] = True
except ImportError as e:
PHASE_TOOLS_STATUS['phase3_math'] = f"Import error: {e}"
# Phase 4: Excel Data Analysis
try:
from tools.excel_processor import ExcelProcessor
from tools.data_analysis_engine import DataAnalysisEngine
PHASE_TOOLS_STATUS['phase4_excel'] = True
except ImportError as e:
PHASE_TOOLS_STATUS['phase4_excel'] = f"Import error: {e}"
# Phase 5: Advanced Video Analysis
try:
from tools.advanced_video_analyzer import AdvancedVideoAnalyzer
from tools.object_detection_engine import ObjectDetectionEngine
PHASE_TOOLS_STATUS['phase5_video'] = True
except ImportError as e:
PHASE_TOOLS_STATUS['phase5_video'] = f"Import error: {e}"
# Phase 6: Complex Text Processing
try:
from tools.advanced_text_processor import AdvancedTextProcessor
from tools.enhanced_ocr_engine import EnhancedOCREngine
from tools.linguistic_analyzer import LinguisticAnalyzer
PHASE_TOOLS_STATUS['phase6_text'] = True
except ImportError as e:
PHASE_TOOLS_STATUS['phase6_text'] = f"Import error: {e}"
logger = logging.getLogger(__name__)
class CompleteEnhancedGAIAAgent:
"""
Complete Enhanced GAIA Agent with all Phase 1-6 improvements.
This agent integrates:
- Base AGNO agent with all native tools
- Phase 1: Advanced web research capabilities
- Phase 2: Audio processing with Faster-Whisper
- Phase 3: Mathematical code execution with SymPy
- Phase 4: Excel data analysis enhancement
- Phase 5: Advanced video analysis with object detection
- Phase 6: Complex text processing with RTL support
"""
def __init__(self):
"""Initialize the complete enhanced agent."""
logger.info("π Initializing Complete Enhanced GAIA Agent (Phase 1-6)...")
# Initialize base AGNO agent
if BASE_AGENT_AVAILABLE:
try:
self.base_agent = BaseGAIAAgent()
logger.info("β
Base AGNO agent initialized")
except Exception as e:
logger.error(f"β Base AGNO agent initialization failed: {e}")
self.base_agent = None
else:
logger.error("β Base AGNO agent not available")
self.base_agent = None
# Initialize Phase 1-6 enhanced tools
self.enhanced_tools = self._initialize_enhanced_tools()
# Calculate total tools available
base_tools = len(self.base_agent.tools) if self.base_agent and hasattr(self.base_agent, 'tools') else 0
enhanced_tools = len(self.enhanced_tools)
self.total_tools = base_tools + enhanced_tools
# Set availability
self.available = self.base_agent is not None and self.base_agent.available
if self.available:
logger.info(f"β
Complete Enhanced GAIA Agent initialized successfully")
logger.info(f"π Total tools: {self.total_tools} (Base: {base_tools}, Enhanced: {enhanced_tools})")
self._log_phase_status()
else:
logger.error("β Complete Enhanced GAIA Agent initialization failed")
def _initialize_enhanced_tools(self) -> List[Any]:
"""Initialize all Phase 1-6 enhanced tools."""
tools = []
# Phase 1: Web Research Enhancement
if PHASE_TOOLS_STATUS.get('phase1_web_research') is True:
try:
tools.append(WebResearchTool())
tools.append(WikipediaResearchTool())
tools.append(ResearchOrchestrator())
logger.info("β
Phase 1 tools initialized: Web Research Enhancement")
except Exception as e:
logger.warning(f"β οΈ Phase 1 tools initialization failed: {e}")
# Phase 2: Audio Processing
if PHASE_TOOLS_STATUS.get('phase2_audio') is True:
try:
tools.append(AudioProcessingTool())
tools.append(AudioContentAnalyzer())
logger.info("β
Phase 2 tools initialized: Audio Processing")
except Exception as e:
logger.warning(f"β οΈ Phase 2 tools initialization failed: {e}")
# Phase 3: Mathematical Code Execution
if PHASE_TOOLS_STATUS.get('phase3_math') is True:
try:
tools.append(MathematicalEngine())
tools.append(CodeExecutionTool())
tools.append(AGNOCompatibleMathTools())
logger.info("β
Phase 3 tools initialized: Mathematical Code Execution")
except Exception as e:
logger.warning(f"β οΈ Phase 3 tools initialization failed: {e}")
# Phase 4: Excel Data Analysis
if PHASE_TOOLS_STATUS.get('phase4_excel') is True:
try:
tools.append(ExcelProcessor())
tools.append(DataAnalysisEngine())
logger.info("β
Phase 4 tools initialized: Excel Data Analysis")
except Exception as e:
logger.warning(f"β οΈ Phase 4 tools initialization failed: {e}")
# Phase 5: Advanced Video Analysis
if PHASE_TOOLS_STATUS.get('phase5_video') is True:
try:
tools.append(AdvancedVideoAnalyzer())
tools.append(ObjectDetectionEngine())
logger.info("β
Phase 5 tools initialized: Advanced Video Analysis")
except Exception as e:
logger.warning(f"β οΈ Phase 5 tools initialization failed: {e}")
# Phase 6: Complex Text Processing
if PHASE_TOOLS_STATUS.get('phase6_text') is True:
try:
tools.append(AdvancedTextProcessor())
tools.append(EnhancedOCREngine())
tools.append(LinguisticAnalyzer())
logger.info("β
Phase 6 tools initialized: Complex Text Processing")
except Exception as e:
logger.warning(f"β οΈ Phase 6 tools initialization failed: {e}")
return tools
def _log_phase_status(self):
"""Log the status of all phases."""
logger.info("π Phase 1-6 Status Report:")
for phase, status in PHASE_TOOLS_STATUS.items():
if status is True:
logger.info(f" β
{phase}: Available")
else:
logger.warning(f" β οΈ {phase}: {status}")
def __call__(self, question: str, files: Optional[List[Union[str, dict]]] = None) -> str:
"""Process a question using the complete enhanced agent."""
if not self.available:
logger.error("β Complete Enhanced GAIA Agent not available")
return "Agent not available"
try:
logger.info(f"π€ Processing question with Complete Enhanced Agent: {question[:100]}...")
# Use base agent for processing (it has AGNO orchestration)
if files:
# Try to pass files if the base agent supports it
if hasattr(self.base_agent, '__call__') and 'files' in self.base_agent.__call__.__code__.co_varnames:
response = self.base_agent(question, files)
else:
response = self.base_agent(question)
else:
response = self.base_agent(question)
logger.info(f"β
Question processed successfully with Complete Enhanced Agent")
return response
except Exception as e:
logger.error(f"β Error processing question: {e}")
return f"Error: {str(e)}"
def get_status(self) -> Dict[str, Any]:
"""Get the current status of the complete enhanced agent."""
base_status = self.base_agent.get_tool_status() if self.base_agent else {}
return {
'available': self.available,
'total_tools': self.total_tools,
'enhanced_tools_count': len(self.enhanced_tools),
'base_agent_available': self.base_agent is not None,
'base_agent_status': base_status,
'phase_status': PHASE_TOOLS_STATUS,
'agent_type': 'complete_enhanced_phase_1_6'
}
# Create global enhanced agent instance
enhanced_gaia_agent = CompleteEnhancedGAIAAgent()
def process_question(question: str, files: Optional[List[Union[str, dict]]] = None) -> str:
"""Process a question using the complete enhanced GAIA agent."""
return enhanced_gaia_agent(question, files)
def get_agent_status() -> Dict[str, Any]:
"""Get the current status of the complete enhanced GAIA agent."""
return enhanced_gaia_agent.get_status()
|