|
|
|
|
|
""" |
|
|
Test script to debug the 'list' object has no attribute 'lower' error |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
|
|
|
|
os.environ["ANTHROPIC_API_KEY"]= "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" |
|
|
|
|
|
|
|
|
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 = [ |
|
|
|
|
|
"What is 2 + 2?", |
|
|
|
|
|
|
|
|
"Look at the image and tell me what you see", |
|
|
|
|
|
|
|
|
"Calculate the sum of [1, 2, 3, 4, 5]", |
|
|
|
|
|
|
|
|
"What is the output of this code:\n```python\nprint([1, 2, 3])\n```", |
|
|
|
|
|
|
|
|
".rewsna eht sa 'tfel' drow eht fo etisoppo eht etirw", |
|
|
|
|
|
|
|
|
"What is the final numeric output from the attached Python code?", |
|
|
] |
|
|
|
|
|
|
|
|
try: |
|
|
from app import LangGraphAgent, _clean_answer |
|
|
|
|
|
|
|
|
print("\n1. Testing _clean_answer function:") |
|
|
print("-" * 50) |
|
|
|
|
|
test_answers = [ |
|
|
"42", |
|
|
["The", "answer", "is", "42"], |
|
|
{"answer": "42"}, |
|
|
42, |
|
|
None, |
|
|
["list", "with", "numbers", 1, 2, 3], |
|
|
] |
|
|
|
|
|
|
|
|
class MockAgent: |
|
|
def _clean_answer(self, answer): |
|
|
|
|
|
answer = answer.strip() |
|
|
|
|
|
lower_answer = answer.lower() |
|
|
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}") |
|
|
|
|
|
|
|
|
print("\n\n2. Testing with tool responses that might return lists:") |
|
|
print("-" * 50) |
|
|
|
|
|
|
|
|
tool_responses = [ |
|
|
|
|
|
{"tool": "calculator", "output": "42"}, |
|
|
|
|
|
|
|
|
{"tool": "python_executor", "output": ["Result:", "42"]}, |
|
|
|
|
|
|
|
|
{"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_contents = [ |
|
|
"Normal string message", |
|
|
["List", "as", "content"], |
|
|
{"type": "image", "data": "base64..."}, |
|
|
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!") |
|
|
|