#!/usr/bin/env python3 """ Test script for GAIA Agent Run this to verify your agent works before deploying """ import os import sys from pathlib import Path # Add current directory to path sys.path.append(str(Path(__file__).parent)) def test_environment(): """Test environment variables and dependencies""" print("๐Ÿงช Testing Environment Setup") print("-" * 40) # Check environment variables serper_key = os.getenv("SERPER_API_KEY") hf_token = os.getenv("HUGGINGFACE_INFERENCE_TOKEN") print(f"SERPER_API_KEY: {'โœ… Found' if serper_key else 'โŒ Missing'}") print(f"HF_TOKEN: {'โœ… Found' if hf_token else 'โŒ Missing'}") # Test imports try: import gradio as gr print("Gradio: โœ… Imported") except ImportError as e: print(f"Gradio: โŒ Import failed - {e}") try: import smolagents print("SmolagentS: โœ… Imported") except ImportError as e: print(f"SmolagentS: โŒ Import failed - {e}") try: import pandas as pd print("Pandas: โœ… Imported") except ImportError as e: print(f"Pandas: โŒ Import failed - {e}") try: import requests print("Requests: โœ… Imported") except ImportError as e: print(f"Requests: โŒ Import failed - {e}") def test_agent_basic(): """Test basic agent functionality""" print("\n๐Ÿค– Testing Agent Initialization") print("-" * 40) try: # Import the agent from app import GAIAAgent # Initialize agent agent = GAIAAgent() if agent.agent is None: print("โŒ Agent initialization failed") return False print("โœ… Agent initialized successfully") # Test with simple questions test_questions = [ "What is 2 + 2?", "What is the capital of France?", "Calculate the square root of 16" ] for i, question in enumerate(test_questions, 1): print(f"\n๐Ÿ“ Test Question {i}: {question}") try: answer = agent(question) print(f"โœ… Answer: {answer[:100]}...") except Exception as e: print(f"โŒ Error: {e}") return True except Exception as e: print(f"โŒ Agent test failed: {e}") return False def test_tools(): """Test individual tools""" print("\n๐Ÿ› ๏ธ Testing Individual Tools") print("-" * 40) try: from app import SerperSearchTool, MathCalculatorTool # Test search tool search_tool = SerperSearchTool() try: result = search_tool("Python programming") print(f"โœ… Search Tool: {result[:100]}...") except Exception as e: print(f"โŒ Search Tool Error: {e}") # Test math tool math_tool = MathCalculatorTool() try: result = math_tool("2 + 2") print(f"โœ… Math Tool: {result}") except Exception as e: print(f"โŒ Math Tool Error: {e}") # Test math tool with complex expression try: result = math_tool("sqrt(16) + 3 * 2") print(f"โœ… Math Complex: {result}") except Exception as e: print(f"โŒ Math Complex Error: {e}") except Exception as e: print(f"โŒ Tools test failed: {e}") def main(): """Run all tests""" print("๐Ÿš€ GAIA Agent Test Suite") print("=" * 50) # Test environment test_environment() # Test tools test_tools() # Test agent success = test_agent_basic() print("\n" + "=" * 50) if success: print("โœ… All tests passed! Your agent is ready for deployment.") else: print("โŒ Some tests failed. Please check the errors above.") print("=" * 50) if __name__ == "__main__": main()