#!/usr/bin/env python3 """ Local testing script for the GAIA agent. Run this to test the agent before deploying to HF Spaces. """ import os import sys from dotenv import load_dotenv # Load environment variables load_dotenv() # Add current directory to path for imports sys.path.append(os.path.dirname(os.path.abspath(__file__))) from utils import fetch_random_question, analyze_question_type from agent import smart_agent def test_question_analysis(): """Test the question analysis functionality.""" print("๐Ÿงช Testing question analysis...") test_questions = [ "What is the current population of Tokyo?", "Calculate 15 * 23 + 45", "Analyze the image shown in the document", "Extract all dates from the provided text file" ] for question in test_questions: analysis = analyze_question_type(question) print(f"Question: {question}") print(f"Analysis: {analysis}") print() def test_tools(): """Test individual tools.""" print("๐Ÿ”ง Testing individual tools...") # Test calculator from tools import calculator_tool calc_result = calculator_tool.func("15 + 27") print(f"Calculator test: {calc_result}") # Test web search (if available) try: from tools import web_search_tool search_result = web_search_tool.func("Python programming language") print(f"Web search test: {search_result[:100]}...") except Exception as e: print(f"Web search test failed: {e}") print() def test_agent_simple(): """Test the agent with a simple question.""" print("๐Ÿค– Testing Smart agent with simple question...") test_question = "What is 25 + 17?" try: result = smart_agent(test_question) print(f"Question: {test_question}") print(f"Answer: {result}") print("โœ… Simple test passed!") except Exception as e: print(f"โŒ Simple test failed: {e}") print() def test_agent_with_api(): """Test the agent with a real GAIA question from the API.""" print("๐ŸŒ Testing with real GAIA question from API...") try: question_data = fetch_random_question() if not question_data: print("โŒ Failed to fetch question from API") return task_id = question_data.get("task_id") question = question_data.get("question") print(f"Task ID: {task_id}") print(f"Question: {question}") # Run the agent answer = smart_agent(question, task_id) print(f"Agent Answer: {answer}") print("โœ… API test completed!") except Exception as e: print(f"โŒ API test failed: {e}") print() def check_environment(): """Check if all required environment variables are set.""" print("๐Ÿ” Checking environment...") required_vars = ["HUGGINGFACE_API_TOKEN"] missing_vars = [] for var in required_vars: if not os.getenv(var): missing_vars.append(var) else: print(f"โœ… {var} is set") if missing_vars: print(f"โŒ Missing environment variables: {missing_vars}") print("Please set these in your .env file or environment") return False print("โœ… All required environment variables are set") return True def main(): """Run all tests.""" print("๐Ÿš€ Starting GAIA Agent Local Tests") print("=" * 50) # Check environment first if not check_environment(): print("โŒ Environment check failed. Please fix and try again.") return print() # Run tests # test_question_analysis() # test_tools() # test_agent_simple() test_agent_with_api() if __name__ == "__main__": main()