File size: 3,952 Bytes
9a6a4dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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)