File size: 4,155 Bytes
fe36046 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
#!/usr/bin/env python3
"""
Debug script to test individual tools in isolation
"""
from src.agents.retrieval_agent import get_retrieval_tools, execute_tool_calls
from src.agents.execution_agent import get_execution_tools
def test_wikipedia_tool():
"""Test Wikipedia search tool directly"""
print("=" * 50)
print("Testing Wikipedia Tool")
print("=" * 50)
tools = get_retrieval_tools()
wiki_tool = None
for tool in tools:
if tool.name == "wiki_search":
wiki_tool = tool
break
if wiki_tool:
try:
print("Found wiki_search tool")
result = wiki_tool.invoke({"input": "Albert Einstein"})
print(f"Result: {result[:500]}...")
return True
except Exception as e:
print(f"Error: {e}")
return False
else:
print("wiki_search tool not found!")
return False
def test_web_search_tool():
"""Test web search tool directly"""
print("=" * 50)
print("Testing Web Search Tool")
print("=" * 50)
tools = get_retrieval_tools()
web_tool = None
for tool in tools:
if tool.name == "web_search":
web_tool = tool
break
if web_tool:
try:
print("Found web_search tool")
result = web_tool.invoke({"input": "artificial intelligence news"})
print(f"Result: {result[:500]}...")
return True
except Exception as e:
print(f"Error: {e}")
return False
else:
print("web_search tool not found!")
return False
def test_python_tool():
"""Test Python execution tool directly"""
print("=" * 50)
print("Testing Python Execution Tool")
print("=" * 50)
tools = get_execution_tools()
python_tool = None
for tool in tools:
if tool.name == "run_python":
python_tool = tool
break
if python_tool:
try:
print("Found run_python tool")
code = """
# Calculate first 5 Fibonacci numbers
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
result = [fibonacci(i) for i in range(5)]
print("First 5 Fibonacci numbers:", result)
"""
result = python_tool.invoke({"input": code})
print(f"Result: {result}")
return True
except Exception as e:
print(f"Error: {e}")
return False
else:
print("run_python tool not found!")
return False
def test_tool_calls_execution():
"""Test the tool call execution function"""
print("=" * 50)
print("Testing Tool Call Execution")
print("=" * 50)
tools = get_retrieval_tools()
# Simulate tool calls
mock_tool_calls = [
{
'name': 'wiki_search',
'args': {'input': 'Albert Einstein'},
'id': 'test_id_1'
}
]
try:
tool_messages = execute_tool_calls(mock_tool_calls, tools)
print(f"Tool execution successful: {len(tool_messages)} messages")
for msg in tool_messages:
print(f"Message type: {type(msg)}")
print(f"Content preview: {str(msg.content)[:200]}...")
return True
except Exception as e:
print(f"Error in tool execution: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
print("Starting individual tool tests...")
results = {}
results['wikipedia'] = test_wikipedia_tool()
results['web_search'] = test_web_search_tool()
results['python'] = test_python_tool()
results['tool_execution'] = test_tool_calls_execution()
print("\n" + "=" * 50)
print("TEST RESULTS SUMMARY")
print("=" * 50)
for test_name, result in results.items():
status = "✅ PASS" if result else "❌ FAIL"
print(f"{test_name}: {status}")
if all(results.values()):
print("\n🎉 All tools are working correctly!")
else:
print("\n⚠️ Some tools have issues that need to be fixed.") |