Download test_agent.py from AbdullahIsaMarkus/Final_Assignment_Agent: direct link, hf CLI and curl.
- Browser
- Download file 5.02 kB
-
https://huggingface.co/spaces/AbdullahIsaMarkus/Final_Assignment_Agent/resolve/main/test_agent.py
- Command line
-
hf download hf://spaces/AbdullahIsaMarkus/Final_Assignment_Agent/test_agent.py
-
curl -L -o test_agent.py https://huggingface.co/spaces/AbdullahIsaMarkus/Final_Assignment_Agent/resolve/main/test_agent.py
5.02 kB
| #!/usr/bin/env python3 | |
| """ | |
| Test script to debug the 'list' object has no attribute 'lower' error | |
| """ | |
| import os | |
| import sys | |
| # Add current directory to path | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| # Set test API keys | |
| os.environ["ANTHROPIC_API_KEY"]= "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" | |
| # Mock the API calls to avoid actual API usage | |
| from unittest.mock import patch, MagicMock | |
| def test_agent_with_various_inputs(): | |
| """Test the agent with different input types that might cause errors""" | |
| print("Testing agent with various input types...") | |
| # Test cases that might cause the error | |
| test_cases = [ | |
| # Normal string | |
| "What is 2 + 2?", | |
| # Question with image reference | |
| "Look at the image and tell me what you see", | |
| # Question with list-like content | |
| "Calculate the sum of [1, 2, 3, 4, 5]", | |
| # Question with code | |
| "What is the output of this code:\n```python\nprint([1, 2, 3])\n```", | |
| # Reversed text question | |
| ".rewsna eht sa 'tfel' drow eht fo etisoppo eht etirw", | |
| # Question with attachment reference | |
| "What is the final numeric output from the attached Python code?", | |
| ] | |
| # Import the agent | |
| try: | |
| from app import LangGraphAgent, _clean_answer | |
| # Test the _clean_answer function directly with different inputs | |
| print("\n1. Testing _clean_answer function:") | |
| print("-" * 50) | |
| test_answers = [ | |
| "42", | |
| ["The", "answer", "is", "42"], # List input | |
| {"answer": "42"}, # Dict input | |
| 42, # Integer | |
| None, # None | |
| ["list", "with", "numbers", 1, 2, 3], # Mixed list | |
| ] | |
| # Create a mock agent to test _clean_answer | |
| class MockAgent: | |
| def _clean_answer(self, answer): | |
| # This is the current implementation | |
| answer = answer.strip() # This will fail on lists! | |
| lower_answer = answer.lower() # This will also fail! | |
| return answer | |
| mock_agent = MockAgent() | |
| for test_answer in test_answers: | |
| print(f"\nTesting with: {test_answer} (type: {type(test_answer)})") | |
| try: | |
| result = mock_agent._clean_answer(test_answer) | |
| print(f"✅ Success: {result}") | |
| except AttributeError as e: | |
| print(f"❌ AttributeError: {e}") | |
| except Exception as e: | |
| print(f"❌ Other error: {type(e).__name__}: {e}") | |
| # Test with actual agent if possible | |
| print("\n\n2. Testing with tool responses that might return lists:") | |
| print("-" * 50) | |
| # Mock tool responses that might cause issues | |
| tool_responses = [ | |
| # Normal response | |
| {"tool": "calculator", "output": "42"}, | |
| # List response (this might be the issue!) | |
| {"tool": "python_executor", "output": ["Result:", "42"]}, | |
| # Complex response | |
| {"tool": "web_search", "output": {"results": ["item1", "item2"]}}, | |
| ] | |
| for response in tool_responses: | |
| print(f"\nTool response: {response}") | |
| output = response.get("output", "") | |
| print(f"Output type: {type(output)}") | |
| if isinstance(output, list): | |
| print("⚠️ This is a LIST - might cause 'lower' error!") | |
| except ImportError as e: | |
| print(f"Import error: {e}") | |
| except Exception as e: | |
| print(f"Unexpected error: {type(e).__name__}: {e}") | |
| def test_message_content_types(): | |
| """Test what types of content messages might contain""" | |
| print("\n\n3. Testing message content types:") | |
| print("-" * 50) | |
| from langchain_core.messages import HumanMessage, AIMessage | |
| # Test different message contents | |
| test_contents = [ | |
| "Normal string message", | |
| ["List", "as", "content"], # This might happen! | |
| {"type": "image", "data": "base64..."}, # Multimodal content | |
| None, | |
| ] | |
| for content in test_contents: | |
| print(f"\nTesting message with content: {content} (type: {type(content)})") | |
| try: | |
| msg = AIMessage(content=content) | |
| print(f"Message created successfully") | |
| print(f"Message.content type: {type(msg.content)}") | |
| except Exception as e: | |
| print(f"Error creating message: {e}") | |
| if __name__ == "__main__": | |
| print("=" * 60) | |
| print("GAIA Agent Error Debugging Test") | |
| print("=" * 60) | |
| test_agent_with_various_inputs() | |
| test_message_content_types() | |
| print("\n\nConclusion:") | |
| print("-" * 50) | |
| print("The error likely occurs when:") | |
| print("1. A tool returns a list instead of a string") | |
| print("2. The message content is a list (multimodal)") | |
| print("3. The _clean_answer method tries to call .strip() or .lower() on a list") | |
| print("\nFix: Add type checking in _clean_answer method!") | |