File size: 3,041 Bytes
3708220 |
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 |
#!/usr/bin/env python3
"""
Test script for the LangGraph multi-agent system with LangChain tools
"""
import asyncio
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv("env.local")
async def test_langgraph_system():
"""Test the LangGraph system with a simple question"""
print("๐ง Testing LangGraph System with LangChain Tools")
print("=" * 60)
try:
# Import the main system
from langgraph_agent_system import run_agent_system
# Test with a simple computational question
test_query = "What is 25 + 17?"
print(f"๐ Test Query: {test_query}")
print("-" * 40)
# Run the agent system
result = await run_agent_system(
query=test_query,
user_id="test_user",
session_id="test_session",
max_iterations=2
)
print("\n๐ Final Result:")
print(result)
print("\nโ
Test completed successfully!")
except Exception as e:
print(f"โ Test failed: {e}")
import traceback
traceback.print_exc()
async def test_research_tools():
"""Test the research tools separately"""
print("\n๐ Testing Research Tools")
print("=" * 40)
try:
from langgraph_tools import get_research_tools
# Get the tools
tools = get_research_tools()
print(f"โ
Loaded {len(tools)} research tools:")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
# Test Wikipedia tool (if available)
wiki_tool = next((t for t in tools if t.name == "wikipedia_search"), None)
if wiki_tool:
print("\n๐ Testing Wikipedia search...")
result = wiki_tool.invoke({"query": "Python programming"})
print(f"Wikipedia result length: {len(str(result))} characters")
print(f"Preview: {str(result)[:200]}...")
except Exception as e:
print(f"โ Research tools test failed: {e}")
async def test_code_tools():
"""Test the code tools separately"""
print("\n๐งฎ Testing Code Tools")
print("=" * 40)
try:
from langgraph_tools import get_code_tools
# Get the tools
tools = get_code_tools()
print(f"โ
Loaded {len(tools)} code tools:")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
# Test add tool
add_tool = next((t for t in tools if t.name == "add"), None)
if add_tool:
print("\nโ Testing addition...")
result = add_tool.invoke({"a": 25, "b": 17})
print(f"Addition result: {result}")
except Exception as e:
print(f"โ Code tools test failed: {e}")
if __name__ == "__main__":
async def main():
await test_research_tools()
await test_code_tools()
await test_langgraph_system()
asyncio.run(main()) |