state.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from __future__ import annotations
  2. """多角色工作流共享状态:定义TravelState(TypedDict)及Supervisor决策、Workflow状态等类型枚举。"""
  3. from app.schemas.place import MapResearchResult
  4. from typing import Any, Literal
  5. from typing_extensions import TypedDict
  6. from app.schemas.travel_request import (
  7. TravelRequest,
  8. )
  9. from app.schemas.selection import (
  10. CandidateSelectionResult,
  11. )
  12. from app.schemas.route import (
  13. RouteEvaluationResult,
  14. )
  15. from app.schemas.itinerary import ItineraryPlan
  16. from app.schemas.validation import (
  17. PlanValidationResult,
  18. )
  19. from app.schemas.review import (
  20. TripReviewResult,
  21. )
  22. SupervisorDecision = Literal[
  23. "replan",
  24. "finalize",
  25. "finalize_with_risks",
  26. "terminate",
  27. ]
  28. WorkflowStatus = Literal[
  29. "running",
  30. "approved",
  31. "completed_with_risks",
  32. "failed",
  33. ]
  34. class TravelState(TypedDict, total=False):
  35. """旅行规划工作流共享状态。
  36. 后面会逐步加入航班、酒店、景点和路线结果。
  37. """
  38. user_query: str
  39. travel_request: TravelRequest
  40. missing_fields: list[str]
  41. errors: list[str]
  42. needs_clarification: bool
  43. clarification_question: str
  44. # 资源查询阶段新增
  45. origin_airports: list[str]
  46. destination_airports: list[str]
  47. flight_search_result: dict[str, Any]
  48. hotel_search_result: dict[str, Any]
  49. resource_messages: list[Any]
  50. final_answer: str
  51. # 本阶段新增
  52. map_research_result: MapResearchResult
  53. map_messages: list[Any]
  54. candidate_selection_result: (
  55. CandidateSelectionResult
  56. )
  57. selection_warnings: list[str]
  58. route_evaluation_result: RouteEvaluationResult
  59. route_warnings: list[str]
  60. itinerary_plan: ItineraryPlan
  61. planner_messages: list[Any]
  62. planning_attempts: int
  63. # 后续Reviewer要求重新规划时使用。
  64. revision_feedback: list[str]
  65. plan_validation_result: PlanValidationResult
  66. validation_passed: bool
  67. validation_warnings: list[str]
  68. trip_review_result: TripReviewResult
  69. reviewer_messages: list[Any]
  70. review_passed: bool
  71. review_attempts: int
  72. supervisor_decision: SupervisorDecision
  73. supervisor_reason: str
  74. workflow_status: WorkflowStatus
  75. final_answer: str