Spaces:
Running
Running
#!/usr/bin/env python3 | |
""" | |
Integration test for the enhanced GAIA Agent with file handling capabilities. | |
This demonstrates the complete workflow from file processing to agent response. | |
""" | |
import os | |
import sys | |
import logging | |
from pathlib import Path | |
# Add the deployment-ready directory to the path | |
sys.path.insert(0, str(Path(__file__).parent)) | |
from agents.fixed_enhanced_unified_agno_agent import FixedGAIAAgent | |
# Configure logging | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
logger = logging.getLogger(__name__) | |
def test_file_handling_integration(): | |
"""Test the complete file handling integration with the GAIA agent.""" | |
print("π Testing Enhanced GAIA Agent File Handling Integration") | |
print("=" * 60) | |
# Initialize the agent | |
print("\n1. Initializing Enhanced GAIA Agent...") | |
agent = FixedGAIAAgent() | |
if not agent.available: | |
print("β Agent not available - check MISTRAL_API_KEY") | |
return False | |
print("β Agent initialized successfully") | |
# Test file processing capabilities | |
print("\n2. Testing file processing capabilities...") | |
# Test with sample files | |
sample_files = [ | |
"sample_files/test_image.txt", | |
"sample_files/test_data.json", | |
"sample_files/test_code.py", | |
"sample_files/test_data.csv" | |
] | |
for file_path in sample_files: | |
if os.path.exists(file_path): | |
print(f"π Testing with {file_path}...") | |
# Test file processing without agent call | |
try: | |
processed_files = agent._process_attached_files([file_path]) | |
if processed_files: | |
file_info = processed_files[0].info | |
print(f" β File type: {file_info.file_type.value}") | |
print(f" β File format: {file_info.file_format.value}") | |
print(f" β Size: {file_info.size_bytes} bytes") | |
else: | |
print(f" β Failed to process {file_path}") | |
except Exception as e: | |
print(f" β Error processing {file_path}: {e}") | |
else: | |
print(f"β οΈ Sample file not found: {file_path}") | |
# Test agent status | |
print("\n3. Testing agent status...") | |
status = agent.get_tool_status() | |
print(f"β Tools available: {status['tools_count']}") | |
print(f"β File handler status: {bool(status.get('file_handler_status'))}") | |
# Test simple question without files | |
print("\n4. Testing simple question processing...") | |
try: | |
question = "What is 15 + 27?" | |
answer = agent(question) | |
print(f"Question: {question}") | |
print(f"Answer: {answer}") | |
print("β Simple question processing works") | |
except Exception as e: | |
print(f"β Error processing simple question: {e}") | |
return False | |
# Test question with file attachment (if available) | |
print("\n5. Testing question with file attachment...") | |
if os.path.exists("sample_files/test_data.json"): | |
try: | |
question = "What data is in this JSON file?" | |
files = ["sample_files/test_data.json"] | |
answer = agent(question, files=files) | |
print(f"Question: {question}") | |
print(f"Files: {files}") | |
print(f"Answer: {answer}") | |
print("β File attachment processing works") | |
except Exception as e: | |
print(f"β Error processing question with file: {e}") | |
return False | |
else: | |
print("β οΈ Skipping file attachment test - sample file not found") | |
print("\n" + "=" * 60) | |
print("π Integration test completed successfully!") | |
print("β Enhanced file handling is working correctly") | |
return True | |
if __name__ == "__main__": | |
success = test_file_handling_integration() | |
sys.exit(0 if success else 1) |