state.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # 在 agent/state.py 中更新 AgentState 定义
  2. from typing import TypedDict, Literal, Optional, List, Dict, Any
  3. class AgentState(TypedDict):
  4. """LangGraph Agent状态定义"""
  5. # 输入信息
  6. question: str
  7. session_id: Optional[str]
  8. # 分类结果
  9. question_type: Literal["DATABASE", "CHAT", "UNCERTAIN"]
  10. classification_confidence: float
  11. classification_reason: str
  12. classification_method: str # "rule_based_*", "enhanced_llm", "direct_database", "direct_chat", etc.
  13. # 数据库查询流程状态
  14. sql: Optional[str]
  15. sql_generation_attempts: int
  16. data_result: Optional[Dict[str, Any]]
  17. summary: Optional[str]
  18. # 聊天响应
  19. chat_response: Optional[str]
  20. # 最终输出
  21. final_response: Dict[str, Any]
  22. # 错误处理
  23. error: Optional[str]
  24. error_code: Optional[int]
  25. # 流程控制
  26. current_step: str
  27. execution_path: List[str]
  28. retry_count: int
  29. max_retries: int
  30. # 调试信息
  31. debug_info: Dict[str, Any]
  32. # 路由模式相关
  33. routing_mode: Optional[str] # 记录使用的路由模式