multi-agent-gaia-system / test_agent.py
Omachoko
πŸ”§ Fix agent answer extraction issues
a1492aa
raw
history blame
4.64 kB
#!/usr/bin/env python3
"""
πŸ” GAIA Agent Diagnostic Test
Quick test to diagnose why the agent isn't answering questions
"""
import os
import sys
from gaia_system import BasicAgent, EnhancedMultiModelGAIASystem
def test_basic_agent():
"""Test the BasicAgent with simple questions"""
print("πŸ§ͺ Testing BasicAgent...")
try:
# Initialize agent
agent = BasicAgent()
print("βœ… Agent initialized successfully")
# Test simple questions
test_questions = [
"What is 2 + 2?",
"What is the capital of France?",
"How many days are in a week?",
"What color is the sky?"
]
for i, question in enumerate(test_questions, 1):
print(f"\nπŸ“ Test {i}: {question}")
try:
response = agent(question)
print(f"πŸ€– Response: '{response}'")
print(f"πŸ“ Length: {len(response)} characters")
if not response or response.strip() == "":
print("❌ Empty response!")
elif "Unable to" in response or "Error" in response:
print("⚠️ Error response detected")
else:
print("βœ… Got non-empty response")
except Exception as e:
print(f"❌ Error: {e}")
except Exception as e:
print(f"❌ Failed to initialize agent: {e}")
return False
return True
def test_enhanced_system():
"""Test the EnhancedMultiModelGAIASystem directly"""
print("\nπŸ§ͺ Testing EnhancedMultiModelGAIASystem...")
try:
# Test with HF token if available
hf_token = os.getenv('HF_TOKEN')
if hf_token:
print(f"βœ… Found HF_TOKEN: {hf_token[:10]}...")
else:
print("⚠️ No HF_TOKEN found - using fallback mode")
system = EnhancedMultiModelGAIASystem(hf_token=hf_token)
print("βœ… Enhanced system initialized")
# Test simple query
question = "What is 5 + 3?"
print(f"\nπŸ“ Testing: {question}")
response = system.query_with_tools(question)
print(f"πŸ€– Raw response: '{response}'")
# Test fallback
fallback = system._fallback_response(question)
print(f"πŸ›‘οΈ Fallback response: '{fallback}'")
# Test answer extraction
if response:
extracted = system._extract_final_answer(response)
print(f"✨ Extracted answer: '{extracted}'")
return True
except Exception as e:
print(f"❌ Enhanced system error: {e}")
import traceback
traceback.print_exc()
return False
def test_model_availability():
"""Test which AI models are available"""
print("\nπŸ” Testing model availability...")
try:
system = EnhancedMultiModelGAIASystem()
print(f"πŸ“Š Available models: {len(system.clients)}")
for name, client_info in system.clients.items():
provider = client_info.get('provider', 'Unknown')
priority = client_info.get('priority', 999)
print(f" - {name} (Priority: {priority}, Provider: {provider})")
if system.model_priority:
print(f"🎯 Top priority model: {system.model_priority[0]}")
else:
print("❌ No models in priority list!")
return True
except Exception as e:
print(f"❌ Model availability error: {e}")
return False
def main():
"""Run all diagnostic tests"""
print("πŸš€ GAIA Agent Diagnostic Tests\n")
# Test basic functionality
test1 = test_basic_agent()
test2 = test_enhanced_system()
test3 = test_model_availability()
print("\nπŸ“Š Test Summary:")
print(f" BasicAgent: {'βœ… PASS' if test1 else '❌ FAIL'}")
print(f" Enhanced System: {'βœ… PASS' if test2 else '❌ FAIL'}")
print(f" Model Availability: {'βœ… PASS' if test3 else '❌ FAIL'}")
if not any([test1, test2, test3]):
print("\n❌ All tests failed! Check dependencies and configuration.")
return False
elif not test1:
print("\n⚠️ BasicAgent failed - this is the issue for GAIA submissions!")
return False
else:
print("\nβœ… Core functionality working - issue might be elsewhere")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)