state.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. context_type: Optional[str] # 上下文类型 ("DATABASE" 或 "CHAT")
  10. # 分类结果
  11. question_type: Literal["DATABASE", "CHAT", "UNCERTAIN"]
  12. classification_confidence: float
  13. classification_reason: str
  14. classification_method: str # "rule_based_*", "enhanced_llm", "direct_database", "direct_chat", etc.
  15. # 数据库查询流程状态
  16. sql: Optional[str]
  17. sql_generation_attempts: int
  18. query_result: Optional[Dict[str, Any]]
  19. summary: Optional[str]
  20. # 聊天响应
  21. chat_response: Optional[str]
  22. # 最终输出
  23. final_response: Dict[str, Any]
  24. # 错误处理
  25. error: Optional[str]
  26. error_code: Optional[int]
  27. # 流程控制
  28. current_step: str
  29. execution_path: List[str]
  30. retry_count: int
  31. max_retries: int
  32. # 调试信息
  33. debug_info: Dict[str, Any]
  34. # 路由模式相关
  35. routing_mode: Optional[str] # 记录使用的路由模式