test_router_agent.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """测试 Router Agent 基本功能"""
  2. import asyncio
  3. import logging
  4. import sys
  5. # 修复 Windows 控制台编码问题
  6. if sys.platform == 'win32':
  7. import io
  8. sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
  9. sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
  10. from tool_agent.router.agent import Router
  11. from tool_agent.router.router_agent import RouterAgent
  12. logging.basicConfig(
  13. level=logging.INFO,
  14. format="%(asctime)s [%(name)s] %(levelname)s: %(message)s"
  15. )
  16. async def test_router_agent():
  17. """测试 Router Agent 的基本功能"""
  18. print("=" * 60)
  19. print("Testing Router Agent")
  20. print("=" * 60)
  21. # 初始化 Router
  22. router = Router()
  23. router_agent = RouterAgent(router)
  24. # 测试 1: 搜索工具
  25. print("\n[Test 1] Searching for tools...")
  26. response = await router_agent.chat("列出所有可用的工具")
  27. print(f"Response: {response}")
  28. # 测试 2: 创建工具请求
  29. print("\n[Test 2] Requesting tool creation...")
  30. response = await router_agent.chat("我需要一个图片压缩工具")
  31. print(f"Response: {response}")
  32. print("\n" + "=" * 60)
  33. print("Tests completed")
  34. print("=" * 60)
  35. if __name__ == "__main__":
  36. asyncio.run(test_router_agent())