Spaces:
Running
Running
Deploy Complete Enhanced GAIA Agent with Phase 1-6 improvements
Browse files- .env +56 -0
- agents/complete_enhanced_gaia_agent.py +203 -287
.env
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Agno Playground Environment Variables
|
2 |
+
# ===========================================
|
3 |
+
#
|
4 |
+
# Instructions:
|
5 |
+
# 1. Replace 'your_api_key_here' with your actual API keys
|
6 |
+
# 2. Get your Mistral API key from: https://console.mistral.ai/
|
7 |
+
# 3. Save this file and restart your terminal or source it
|
8 |
+
# 4. Run: python test_agno_setup.py to verify setup
|
9 |
+
# 5. Run: python start_playground.py to start the playground
|
10 |
+
|
11 |
+
# REQUIRED: Mistral API Key
|
12 |
+
# Get this from https://console.mistral.ai/
|
13 |
+
MISTRAL_API_KEY=w3PJzUjk8rqOo1enzjdn8BQX8uas0DXv
|
14 |
+
|
15 |
+
# OPTIONAL: Other API Keys (for future use)
|
16 |
+
# OpenAI API Key (if you want to compare models)
|
17 |
+
# OPENAI_API_KEY=your_openai_api_key_here
|
18 |
+
|
19 |
+
# Anthropic API Key (if you want to compare models)
|
20 |
+
# ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
21 |
+
|
22 |
+
# Exa API Key (for enhanced web search capabilities)
|
23 |
+
# Get this from https://exa.ai/
|
24 |
+
EXA_API_KEY=f0e7530a-f3e4-4835-9311-6e905a0becaf
|
25 |
+
|
26 |
+
# Firecrawl API Key (for web scraping)
|
27 |
+
# Get this from https://firecrawl.dev/
|
28 |
+
FIRECRAWL_API_KEY=fc-dd6307b35b6046fc98b8cdc05a8183d1
|
29 |
+
|
30 |
+
# Hugging Face API Token (for the assignment API)
|
31 |
+
# Get this from https://huggingface.co/settings/tokens
|
32 |
+
HF_ACCESS_TOKEN=hf_test_token_for_assignment
|
33 |
+
|
34 |
+
# OPTIONAL: Configuration Settings
|
35 |
+
# Default model to use (you can change this)
|
36 |
+
DEFAULT_MISTRAL_MODEL=mistral-large-latest
|
37 |
+
|
38 |
+
# Server configuration
|
39 |
+
PLAYGROUND_HOST=0.0.0.0
|
40 |
+
PLAYGROUND_PORT=8000
|
41 |
+
|
42 |
+
# Logging level (DEBUG, INFO, WARNING, ERROR)
|
43 |
+
LOG_LEVEL=INFO
|
44 |
+
|
45 |
+
# ===========================================
|
46 |
+
# After setting your API key:
|
47 |
+
#
|
48 |
+
# Linux/Mac users can source this file:
|
49 |
+
# source .env
|
50 |
+
#
|
51 |
+
# Or export manually:
|
52 |
+
# export MISTRAL_API_KEY=your_actual_key
|
53 |
+
#
|
54 |
+
# Windows users can set manually:
|
55 |
+
# set MISTRAL_API_KEY=your_actual_key
|
56 |
+
# ===========================================
|
agents/complete_enhanced_gaia_agent.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
"""
|
2 |
-
Enhanced GAIA Agent
|
3 |
-
|
4 |
"""
|
5 |
|
6 |
import os
|
@@ -8,325 +8,241 @@ import logging
|
|
8 |
from typing import Dict, Any, List, Optional, Union
|
9 |
from pathlib import Path
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
"""Load environment variables from .env file if it exists."""
|
17 |
-
env_file = Path('.env')
|
18 |
-
if env_file.exists():
|
19 |
-
with open(env_file, 'r') as f:
|
20 |
-
for line in f:
|
21 |
-
line = line.strip()
|
22 |
-
if line and not line.startswith('#') and '=' in line:
|
23 |
-
key, value = line.split('=', 1)
|
24 |
-
os.environ[key.strip()] = value.strip()
|
25 |
-
|
26 |
-
# Load environment variables at startup
|
27 |
-
load_env_file()
|
28 |
-
|
29 |
-
# Import all Phase 1-6 enhanced tools with graceful degradation
|
30 |
-
def load_enhanced_tools():
|
31 |
-
"""Load all Phase 1-6 enhanced tools with graceful degradation."""
|
32 |
-
tools = []
|
33 |
-
tool_status = {}
|
34 |
-
|
35 |
-
# Phase 1: Web Research Tools
|
36 |
-
try:
|
37 |
-
from tools.web_research_tool import WebResearchTool
|
38 |
-
tools.append(WebResearchTool())
|
39 |
-
tool_status["web_research"] = "β
Available"
|
40 |
-
except Exception as e:
|
41 |
-
tool_status["web_research"] = f"β {str(e)[:50]}"
|
42 |
-
|
43 |
-
try:
|
44 |
-
from tools.wikipedia_tool import WikipediaTool
|
45 |
-
tools.append(WikipediaTool())
|
46 |
-
tool_status["wikipedia_enhanced"] = "β
Available"
|
47 |
-
except Exception as e:
|
48 |
-
tool_status["wikipedia_enhanced"] = f"β {str(e)[:50]}"
|
49 |
-
|
50 |
-
try:
|
51 |
-
from tools.research_orchestrator import ResearchOrchestrator
|
52 |
-
tools.append(ResearchOrchestrator())
|
53 |
-
tool_status["research_orchestrator"] = "β
Available"
|
54 |
-
except Exception as e:
|
55 |
-
tool_status["research_orchestrator"] = f"β {str(e)[:50]}"
|
56 |
-
|
57 |
-
# Phase 2: Audio Processing Tools
|
58 |
-
try:
|
59 |
-
from tools.audio_processing_tool import AudioProcessingTool
|
60 |
-
tools.append(AudioProcessingTool())
|
61 |
-
tool_status["audio_processing"] = "β
Available"
|
62 |
-
except Exception as e:
|
63 |
-
tool_status["audio_processing"] = f"β {str(e)[:50]}"
|
64 |
-
|
65 |
-
try:
|
66 |
-
from tools.audio_content_analyzer import AudioContentAnalyzer
|
67 |
-
tools.append(AudioContentAnalyzer())
|
68 |
-
tool_status["audio_content_analyzer"] = "β
Available"
|
69 |
-
except Exception as e:
|
70 |
-
tool_status["audio_content_analyzer"] = f"β {str(e)[:50]}"
|
71 |
-
|
72 |
-
# Phase 3: Mathematical Tools
|
73 |
-
try:
|
74 |
-
from tools.mathematical_engine import MathematicalEngine
|
75 |
-
tools.append(MathematicalEngine())
|
76 |
-
tool_status["mathematical_engine"] = "β
Available"
|
77 |
-
except Exception as e:
|
78 |
-
tool_status["mathematical_engine"] = f"β {str(e)[:50]}"
|
79 |
-
|
80 |
-
try:
|
81 |
-
from tools.code_execution_tool import CodeExecutionTool
|
82 |
-
tools.append(CodeExecutionTool())
|
83 |
-
tool_status["code_execution"] = "β
Available"
|
84 |
-
except Exception as e:
|
85 |
-
tool_status["code_execution"] = f"β {str(e)[:50]}"
|
86 |
-
|
87 |
-
# Phase 4: Excel Tools
|
88 |
-
try:
|
89 |
-
from tools.excel_processor import ExcelProcessor
|
90 |
-
tools.append(ExcelProcessor())
|
91 |
-
tool_status["excel_processor"] = "β
Available"
|
92 |
-
except Exception as e:
|
93 |
-
tool_status["excel_processor"] = f"β {str(e)[:50]}"
|
94 |
-
|
95 |
-
try:
|
96 |
-
from tools.data_analysis_engine import DataAnalysisEngine
|
97 |
-
tools.append(DataAnalysisEngine())
|
98 |
-
tool_status["data_analysis_engine"] = "β
Available"
|
99 |
-
except Exception as e:
|
100 |
-
tool_status["data_analysis_engine"] = f"β {str(e)[:50]}"
|
101 |
-
|
102 |
-
# Phase 5: Video Analysis Tools
|
103 |
-
try:
|
104 |
-
from tools.advanced_video_analyzer import AdvancedVideoAnalyzer
|
105 |
-
tools.append(AdvancedVideoAnalyzer())
|
106 |
-
tool_status["advanced_video_analyzer"] = "β
Available"
|
107 |
-
except Exception as e:
|
108 |
-
tool_status["advanced_video_analyzer"] = f"β {str(e)[:50]}"
|
109 |
-
|
110 |
-
try:
|
111 |
-
from tools.object_detection_engine import ObjectDetectionEngine
|
112 |
-
tools.append(ObjectDetectionEngine())
|
113 |
-
tool_status["object_detection_engine"] = "β
Available"
|
114 |
-
except Exception as e:
|
115 |
-
tool_status["object_detection_engine"] = f"β {str(e)[:50]}"
|
116 |
-
|
117 |
-
# Phase 6: Text Processing Tools
|
118 |
try:
|
119 |
-
from
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
class CompleteEnhancedGAIAAgent:
|
135 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
def __init__(self):
|
138 |
"""Initialize the complete enhanced agent."""
|
139 |
-
|
140 |
-
self.logger.info("π Initializing Complete Enhanced GAIA Agent...")
|
141 |
|
142 |
-
#
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
-
#
|
146 |
-
self.
|
147 |
|
148 |
-
#
|
149 |
-
self.
|
|
|
|
|
150 |
|
151 |
-
#
|
152 |
-
self.
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
159 |
tools = []
|
160 |
|
161 |
-
#
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
# Optional AGNO tools with API keys
|
172 |
-
if os.getenv('EXA_API_KEY'):
|
173 |
-
agno_tools_config.append(('agno.tools.exa', 'ExaTools'))
|
174 |
|
175 |
-
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
-
|
|
|
179 |
try:
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
tool_instance = tool_class(api_key=os.getenv('EXA_API_KEY'))
|
185 |
-
elif 'firecrawl' in module_path.lower():
|
186 |
-
tool_instance = tool_class(api_key=os.getenv('FIRECRAWL_API_KEY'))
|
187 |
-
else:
|
188 |
-
tool_instance = tool_class()
|
189 |
-
|
190 |
-
tools.append(tool_instance)
|
191 |
-
self.tool_status[f"agno_{class_name.lower()}"] = "β
Available"
|
192 |
except Exception as e:
|
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 |
-
return
|
220 |
-
|
221 |
-
def _get_enhanced_instructions(self):
|
222 |
-
"""Get enhanced instructions for all Phase 1-6 capabilities."""
|
223 |
-
return """You are an enhanced GAIA evaluation agent with comprehensive Phase 1-6 capabilities.
|
224 |
-
|
225 |
-
CRITICAL REQUIREMENTS:
|
226 |
-
1. Provide ONLY the final answer - no explanations or reasoning
|
227 |
-
2. Match the expected answer format EXACTLY
|
228 |
-
3. Use appropriate tools to verify information
|
229 |
-
4. Ensure factual accuracy through multiple sources when needed
|
230 |
-
|
231 |
-
ENHANCED CAPABILITIES (Phase 1-6):
|
232 |
-
|
233 |
-
PHASE 1 - WEB RESEARCH:
|
234 |
-
- Advanced web search with Exa API
|
235 |
-
- Specialized Wikipedia research
|
236 |
-
- Multi-source research orchestration
|
237 |
-
- AGNO-compatible research wrappers
|
238 |
-
|
239 |
-
PHASE 2 - AUDIO PROCESSING:
|
240 |
-
- Audio transcription with Faster-Whisper (European open-source)
|
241 |
-
- Recipe and educational content analysis
|
242 |
-
- Multi-format audio support
|
243 |
-
|
244 |
-
PHASE 3 - MATHEMATICAL COMPUTATION:
|
245 |
-
- Advanced mathematical engine with SymPy
|
246 |
-
- Secure Python code execution
|
247 |
-
- AST parsing and code analysis
|
248 |
-
- AGNO-compatible math tools
|
249 |
-
|
250 |
-
PHASE 4 - EXCEL DATA ANALYSIS:
|
251 |
-
- Advanced Excel file processing
|
252 |
-
- Financial calculations and analysis
|
253 |
-
- Excel formula evaluation
|
254 |
-
|
255 |
-
PHASE 5 - VIDEO ANALYSIS:
|
256 |
-
- Object detection and counting
|
257 |
-
- Computer vision engine
|
258 |
-
- Scene analysis and description
|
259 |
-
|
260 |
-
PHASE 6 - TEXT PROCESSING:
|
261 |
-
- RTL (Right-to-Left) text processing
|
262 |
-
- Multi-orientation OCR
|
263 |
-
- Advanced linguistic pattern recognition
|
264 |
-
|
265 |
-
TOOL SELECTION STRATEGY:
|
266 |
-
1. Analyze question type and requirements
|
267 |
-
2. Select most appropriate tools for the task
|
268 |
-
3. Use multiple tools for verification when needed
|
269 |
-
4. Prioritize accuracy over speed
|
270 |
-
5. Provide precise, formatted answers
|
271 |
-
|
272 |
-
ANSWER FORMAT:
|
273 |
-
- Final answer only
|
274 |
-
- No explanations or reasoning
|
275 |
-
- Exact format matching (numbers, text, dates, etc.)
|
276 |
-
- Verified through appropriate tools"""
|
277 |
|
278 |
-
def
|
279 |
-
"""Log the status of all
|
280 |
-
|
281 |
-
for
|
282 |
-
|
|
|
|
|
|
|
283 |
|
284 |
def __call__(self, question: str, files: Optional[List[Union[str, dict]]] = None) -> str:
|
285 |
-
"""Process a question
|
|
|
|
|
|
|
|
|
286 |
try:
|
287 |
-
|
288 |
|
|
|
289 |
if files:
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
response = self.agent.run(question)
|
296 |
-
|
297 |
-
# Extract response content
|
298 |
-
if hasattr(response, 'content'):
|
299 |
-
answer = response.content
|
300 |
-
elif isinstance(response, str):
|
301 |
-
answer = response
|
302 |
else:
|
303 |
-
|
304 |
-
|
305 |
-
# Simple answer formatting
|
306 |
-
answer = answer.strip()
|
307 |
|
308 |
-
|
309 |
-
|
310 |
-
for prefix in prefixes:
|
311 |
-
if answer.lower().startswith(prefix.lower()):
|
312 |
-
answer = answer[len(prefix):].strip()
|
313 |
-
|
314 |
-
self.logger.info(f"β
Answer: {answer}")
|
315 |
-
return answer
|
316 |
|
317 |
except Exception as e:
|
318 |
-
|
319 |
-
return "
|
320 |
|
321 |
def get_status(self) -> Dict[str, Any]:
|
322 |
-
"""Get complete agent
|
|
|
|
|
323 |
return {
|
324 |
-
'
|
325 |
-
'
|
326 |
-
'
|
327 |
-
'
|
328 |
-
'
|
|
|
|
|
329 |
}
|
330 |
|
331 |
-
#
|
332 |
enhanced_gaia_agent = CompleteEnhancedGAIAAgent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
"""
|
2 |
+
Complete Enhanced GAIA Agent - All Phase 1-6 Improvements
|
3 |
+
Integrates all enhanced tools for maximum GAIA evaluation performance
|
4 |
"""
|
5 |
|
6 |
import os
|
|
|
8 |
from typing import Dict, Any, List, Optional, Union
|
9 |
from pathlib import Path
|
10 |
|
11 |
+
# Import the enhanced unified AGNO agent as base
|
12 |
+
try:
|
13 |
+
from .enhanced_unified_agno_agent import GAIAAgent as BaseGAIAAgent
|
14 |
+
BASE_AGENT_AVAILABLE = True
|
15 |
+
except ImportError:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
try:
|
17 |
+
from enhanced_unified_agno_agent import GAIAAgent as BaseGAIAAgent
|
18 |
+
BASE_AGENT_AVAILABLE = True
|
19 |
+
except ImportError:
|
20 |
+
BaseGAIAAgent = None
|
21 |
+
BASE_AGENT_AVAILABLE = False
|
22 |
+
|
23 |
+
# Import all Phase 1-6 enhanced tools
|
24 |
+
PHASE_TOOLS_STATUS = {}
|
25 |
+
|
26 |
+
# Phase 1: Web Research Enhancement
|
27 |
+
try:
|
28 |
+
from tools.web_research_tool import WebResearchTool
|
29 |
+
from tools.wikipedia_tool import WikipediaResearchTool
|
30 |
+
from tools.research_orchestrator import ResearchOrchestrator
|
31 |
+
PHASE_TOOLS_STATUS['phase1_web_research'] = True
|
32 |
+
except ImportError as e:
|
33 |
+
PHASE_TOOLS_STATUS['phase1_web_research'] = f"Import error: {e}"
|
34 |
+
|
35 |
+
# Phase 2: Audio Processing
|
36 |
+
try:
|
37 |
+
from tools.audio_processing_tool import AudioProcessingTool
|
38 |
+
from tools.audio_content_analyzer import AudioContentAnalyzer
|
39 |
+
PHASE_TOOLS_STATUS['phase2_audio'] = True
|
40 |
+
except ImportError as e:
|
41 |
+
PHASE_TOOLS_STATUS['phase2_audio'] = f"Import error: {e}"
|
42 |
+
|
43 |
+
# Phase 3: Mathematical Code Execution
|
44 |
+
try:
|
45 |
+
from tools.mathematical_engine import MathematicalEngine
|
46 |
+
from tools.code_execution_tool import CodeExecutionTool
|
47 |
+
from tools.agno_compatible_math_tools import AGNOCompatibleMathTools
|
48 |
+
PHASE_TOOLS_STATUS['phase3_math'] = True
|
49 |
+
except ImportError as e:
|
50 |
+
PHASE_TOOLS_STATUS['phase3_math'] = f"Import error: {e}"
|
51 |
+
|
52 |
+
# Phase 4: Excel Data Analysis
|
53 |
+
try:
|
54 |
+
from tools.excel_processor import ExcelProcessor
|
55 |
+
from tools.data_analysis_engine import DataAnalysisEngine
|
56 |
+
PHASE_TOOLS_STATUS['phase4_excel'] = True
|
57 |
+
except ImportError as e:
|
58 |
+
PHASE_TOOLS_STATUS['phase4_excel'] = f"Import error: {e}"
|
59 |
+
|
60 |
+
# Phase 5: Advanced Video Analysis
|
61 |
+
try:
|
62 |
+
from tools.advanced_video_analyzer import AdvancedVideoAnalyzer
|
63 |
+
from tools.object_detection_engine import ObjectDetectionEngine
|
64 |
+
PHASE_TOOLS_STATUS['phase5_video'] = True
|
65 |
+
except ImportError as e:
|
66 |
+
PHASE_TOOLS_STATUS['phase5_video'] = f"Import error: {e}"
|
67 |
+
|
68 |
+
# Phase 6: Complex Text Processing
|
69 |
+
try:
|
70 |
+
from tools.advanced_text_processor import AdvancedTextProcessor
|
71 |
+
from tools.enhanced_ocr_engine import EnhancedOCREngine
|
72 |
+
from tools.linguistic_analyzer import LinguisticAnalyzer
|
73 |
+
PHASE_TOOLS_STATUS['phase6_text'] = True
|
74 |
+
except ImportError as e:
|
75 |
+
PHASE_TOOLS_STATUS['phase6_text'] = f"Import error: {e}"
|
76 |
+
|
77 |
+
logger = logging.getLogger(__name__)
|
78 |
|
79 |
class CompleteEnhancedGAIAAgent:
|
80 |
+
"""
|
81 |
+
Complete Enhanced GAIA Agent with all Phase 1-6 improvements.
|
82 |
+
|
83 |
+
This agent integrates:
|
84 |
+
- Base AGNO agent with all native tools
|
85 |
+
- Phase 1: Advanced web research capabilities
|
86 |
+
- Phase 2: Audio processing with Faster-Whisper
|
87 |
+
- Phase 3: Mathematical code execution with SymPy
|
88 |
+
- Phase 4: Excel data analysis enhancement
|
89 |
+
- Phase 5: Advanced video analysis with object detection
|
90 |
+
- Phase 6: Complex text processing with RTL support
|
91 |
+
"""
|
92 |
|
93 |
def __init__(self):
|
94 |
"""Initialize the complete enhanced agent."""
|
95 |
+
logger.info("π Initializing Complete Enhanced GAIA Agent (Phase 1-6)...")
|
|
|
96 |
|
97 |
+
# Initialize base AGNO agent
|
98 |
+
if BASE_AGENT_AVAILABLE:
|
99 |
+
try:
|
100 |
+
self.base_agent = BaseGAIAAgent()
|
101 |
+
logger.info("β
Base AGNO agent initialized")
|
102 |
+
except Exception as e:
|
103 |
+
logger.error(f"β Base AGNO agent initialization failed: {e}")
|
104 |
+
self.base_agent = None
|
105 |
+
else:
|
106 |
+
logger.error("β Base AGNO agent not available")
|
107 |
+
self.base_agent = None
|
108 |
|
109 |
+
# Initialize Phase 1-6 enhanced tools
|
110 |
+
self.enhanced_tools = self._initialize_enhanced_tools()
|
111 |
|
112 |
+
# Calculate total tools available
|
113 |
+
base_tools = len(self.base_agent.tools) if self.base_agent and hasattr(self.base_agent, 'tools') else 0
|
114 |
+
enhanced_tools = len(self.enhanced_tools)
|
115 |
+
self.total_tools = base_tools + enhanced_tools
|
116 |
|
117 |
+
# Set availability
|
118 |
+
self.available = self.base_agent is not None and self.base_agent.available
|
119 |
|
120 |
+
if self.available:
|
121 |
+
logger.info(f"β
Complete Enhanced GAIA Agent initialized successfully")
|
122 |
+
logger.info(f"π Total tools: {self.total_tools} (Base: {base_tools}, Enhanced: {enhanced_tools})")
|
123 |
+
self._log_phase_status()
|
124 |
+
else:
|
125 |
+
logger.error("β Complete Enhanced GAIA Agent initialization failed")
|
126 |
+
|
127 |
+
def _initialize_enhanced_tools(self) -> List[Any]:
|
128 |
+
"""Initialize all Phase 1-6 enhanced tools."""
|
129 |
tools = []
|
130 |
|
131 |
+
# Phase 1: Web Research Enhancement
|
132 |
+
if PHASE_TOOLS_STATUS.get('phase1_web_research') is True:
|
133 |
+
try:
|
134 |
+
tools.append(WebResearchTool())
|
135 |
+
tools.append(WikipediaResearchTool())
|
136 |
+
tools.append(ResearchOrchestrator())
|
137 |
+
logger.info("β
Phase 1 tools initialized: Web Research Enhancement")
|
138 |
+
except Exception as e:
|
139 |
+
logger.warning(f"β οΈ Phase 1 tools initialization failed: {e}")
|
|
|
|
|
|
|
|
|
140 |
|
141 |
+
# Phase 2: Audio Processing
|
142 |
+
if PHASE_TOOLS_STATUS.get('phase2_audio') is True:
|
143 |
+
try:
|
144 |
+
tools.append(AudioProcessingTool())
|
145 |
+
tools.append(AudioContentAnalyzer())
|
146 |
+
logger.info("β
Phase 2 tools initialized: Audio Processing")
|
147 |
+
except Exception as e:
|
148 |
+
logger.warning(f"β οΈ Phase 2 tools initialization failed: {e}")
|
149 |
|
150 |
+
# Phase 3: Mathematical Code Execution
|
151 |
+
if PHASE_TOOLS_STATUS.get('phase3_math') is True:
|
152 |
try:
|
153 |
+
tools.append(MathematicalEngine())
|
154 |
+
tools.append(CodeExecutionTool())
|
155 |
+
tools.append(AGNOCompatibleMathTools())
|
156 |
+
logger.info("β
Phase 3 tools initialized: Mathematical Code Execution")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
except Exception as e:
|
158 |
+
logger.warning(f"β οΈ Phase 3 tools initialization failed: {e}")
|
159 |
|
160 |
+
# Phase 4: Excel Data Analysis
|
161 |
+
if PHASE_TOOLS_STATUS.get('phase4_excel') is True:
|
162 |
+
try:
|
163 |
+
tools.append(ExcelProcessor())
|
164 |
+
tools.append(DataAnalysisEngine())
|
165 |
+
logger.info("β
Phase 4 tools initialized: Excel Data Analysis")
|
166 |
+
except Exception as e:
|
167 |
+
logger.warning(f"β οΈ Phase 4 tools initialization failed: {e}")
|
168 |
|
169 |
+
# Phase 5: Advanced Video Analysis
|
170 |
+
if PHASE_TOOLS_STATUS.get('phase5_video') is True:
|
171 |
+
try:
|
172 |
+
tools.append(AdvancedVideoAnalyzer())
|
173 |
+
tools.append(ObjectDetectionEngine())
|
174 |
+
logger.info("β
Phase 5 tools initialized: Advanced Video Analysis")
|
175 |
+
except Exception as e:
|
176 |
+
logger.warning(f"β οΈ Phase 5 tools initialization failed: {e}")
|
177 |
|
178 |
+
# Phase 6: Complex Text Processing
|
179 |
+
if PHASE_TOOLS_STATUS.get('phase6_text') is True:
|
180 |
+
try:
|
181 |
+
tools.append(AdvancedTextProcessor())
|
182 |
+
tools.append(EnhancedOCREngine())
|
183 |
+
tools.append(LinguisticAnalyzer())
|
184 |
+
logger.info("β
Phase 6 tools initialized: Complex Text Processing")
|
185 |
+
except Exception as e:
|
186 |
+
logger.warning(f"β οΈ Phase 6 tools initialization failed: {e}")
|
187 |
|
188 |
+
return tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
+
def _log_phase_status(self):
|
191 |
+
"""Log the status of all phases."""
|
192 |
+
logger.info("π Phase 1-6 Status Report:")
|
193 |
+
for phase, status in PHASE_TOOLS_STATUS.items():
|
194 |
+
if status is True:
|
195 |
+
logger.info(f" β
{phase}: Available")
|
196 |
+
else:
|
197 |
+
logger.warning(f" β οΈ {phase}: {status}")
|
198 |
|
199 |
def __call__(self, question: str, files: Optional[List[Union[str, dict]]] = None) -> str:
|
200 |
+
"""Process a question using the complete enhanced agent."""
|
201 |
+
if not self.available:
|
202 |
+
logger.error("β Complete Enhanced GAIA Agent not available")
|
203 |
+
return "Agent not available"
|
204 |
+
|
205 |
try:
|
206 |
+
logger.info(f"π€ Processing question with Complete Enhanced Agent: {question[:100]}...")
|
207 |
|
208 |
+
# Use base agent for processing (it has AGNO orchestration)
|
209 |
if files:
|
210 |
+
# Try to pass files if the base agent supports it
|
211 |
+
if hasattr(self.base_agent, '__call__') and 'files' in self.base_agent.__call__.__code__.co_varnames:
|
212 |
+
response = self.base_agent(question, files)
|
213 |
+
else:
|
214 |
+
response = self.base_agent(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
else:
|
216 |
+
response = self.base_agent(question)
|
|
|
|
|
|
|
217 |
|
218 |
+
logger.info(f"β
Question processed successfully with Complete Enhanced Agent")
|
219 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
|
221 |
except Exception as e:
|
222 |
+
logger.error(f"β Error processing question: {e}")
|
223 |
+
return f"Error: {str(e)}"
|
224 |
|
225 |
def get_status(self) -> Dict[str, Any]:
|
226 |
+
"""Get the current status of the complete enhanced agent."""
|
227 |
+
base_status = self.base_agent.get_tool_status() if self.base_agent else {}
|
228 |
+
|
229 |
return {
|
230 |
+
'available': self.available,
|
231 |
+
'total_tools': self.total_tools,
|
232 |
+
'enhanced_tools_count': len(self.enhanced_tools),
|
233 |
+
'base_agent_available': self.base_agent is not None,
|
234 |
+
'base_agent_status': base_status,
|
235 |
+
'phase_status': PHASE_TOOLS_STATUS,
|
236 |
+
'agent_type': 'complete_enhanced_phase_1_6'
|
237 |
}
|
238 |
|
239 |
+
# Create global enhanced agent instance
|
240 |
enhanced_gaia_agent = CompleteEnhancedGAIAAgent()
|
241 |
+
|
242 |
+
def process_question(question: str, files: Optional[List[Union[str, dict]]] = None) -> str:
|
243 |
+
"""Process a question using the complete enhanced GAIA agent."""
|
244 |
+
return enhanced_gaia_agent(question, files)
|
245 |
+
|
246 |
+
def get_agent_status() -> Dict[str, Any]:
|
247 |
+
"""Get the current status of the complete enhanced GAIA agent."""
|
248 |
+
return enhanced_gaia_agent.get_status()
|