|
|
|
|
|
""" |
|
|
Test script for the LangGraph multi-agent system with LangChain tools |
|
|
""" |
|
|
|
|
|
import asyncio |
|
|
import os |
|
|
from dotenv import load_dotenv |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
from langgraph_agent_system import run_agent_system |
|
|
|
|
|
|
|
|
test_query = "What is 25 + 17?" |
|
|
print(f"๐ Test Query: {test_query}") |
|
|
print("-" * 40) |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
tools = get_research_tools() |
|
|
print(f"โ
Loaded {len(tools)} research tools:") |
|
|
for tool in tools: |
|
|
print(f" - {tool.name}: {tool.description}") |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
tools = get_code_tools() |
|
|
print(f"โ
Loaded {len(tools)} code tools:") |
|
|
for tool in tools: |
|
|
print(f" - {tool.name}: {tool.description}") |
|
|
|
|
|
|
|
|
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()) |