Spaces:
Build error
Build error
| #!/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.") |