test_final_graph.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from __future__ import annotations
  2. """测试完整多角色工作流端到端流程:从需求输入到最终旅行方案输出。"""
  3. import asyncio
  4. from rich.console import Console
  5. from app.graph.planner_builder import (
  6. build_planner_graph,
  7. )
  8. console = Console()
  9. async def main() -> None:
  10. graph = await build_planner_graph()
  11. result = await graph.ainvoke(
  12. {
  13. "user_query": (
  14. "我和妻子计划2026年8月10日"
  15. "从上海去成都,8月14日返回,"
  16. "总预算5000元。"
  17. "喜欢熊猫、自然景观和川菜,"
  18. "希望行程轻松一些。"
  19. "酒店每晚不超过300元,"
  20. "评分不低于3,"
  21. "并且希望靠近地铁。"
  22. "机票价格和便利性综合考虑。"
  23. ),
  24. "errors": [],
  25. "missing_fields": [],
  26. "planning_attempts": 0,
  27. "review_attempts": 0,
  28. "revision_feedback": [],
  29. "workflow_status": "running",
  30. },
  31. config={
  32. "recursion_limit": 80,
  33. },
  34. )
  35. console.rule(
  36. "[bold]最终多角色工作流"
  37. )
  38. console.print(
  39. {
  40. "工作流状态": result.get(
  41. "workflow_status"
  42. ),
  43. "Supervisor决策": result.get(
  44. "supervisor_decision"
  45. ),
  46. "Planner次数": result.get(
  47. "planning_attempts"
  48. ),
  49. "Reviewer次数": result.get(
  50. "review_attempts"
  51. ),
  52. "校验通过": result.get(
  53. "validation_passed"
  54. ),
  55. "审查通过": result.get(
  56. "review_passed"
  57. ),
  58. "系统错误": result.get(
  59. "errors"
  60. ),
  61. }
  62. )
  63. console.rule("[bold]最终旅行方案")
  64. console.print(
  65. result.get(
  66. "final_answer",
  67. "没有最终回答。",
  68. )
  69. )
  70. if __name__ == "__main__":
  71. asyncio.run(main())