2026-10-19 16:25:04 +08:00
|
|
|
|
"""图状态定义。
|
2026-10-19 13:32:43 +08:00
|
|
|
|
|
2026-10-19 16:25:04 +08:00
|
|
|
|
作业 1 的五个基础字段之上,作业 3 扩充领域状态:内部阶段、原始状态码、
|
|
|
|
|
|
待回答问题、事故字段、两方人员字段、字段确认状态、澄清计数、无回复计数、
|
|
|
|
|
|
本轮 patch 和业务版本。
|
|
|
|
|
|
|
|
|
|
|
|
约束(迁移计划作业 3-2):所有字段必须可序列化,
|
|
|
|
|
|
不保存 HTTP client、数据库连接、音频或图片 base64。
|
|
|
|
|
|
字段读取一律用 ``state.get(...)`` 并提供默认值——首轮会话没有
|
|
|
|
|
|
历史 checkpoint,字段可能尚未初始化。
|
2026-10-19 13:32:43 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from typing import TypedDict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AgentState(TypedDict):
|
|
|
|
|
|
"""一次对话轮次在图中流动的状态。
|
|
|
|
|
|
|
2026-10-19 16:25:04 +08:00
|
|
|
|
``turn_count``、``stage_code`` 等由同一 ``thread_id`` 的
|
|
|
|
|
|
checkpoint 承载跨轮记忆;节点返回字段增量,LangGraph 合并写回。
|
2026-10-19 13:32:43 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
2026-10-19 16:25:04 +08:00
|
|
|
|
# ---- 基础(作业 1) ----
|
2026-10-19 13:32:43 +08:00
|
|
|
|
session_id: str
|
|
|
|
|
|
turn_count: int
|
|
|
|
|
|
input_text: str
|
|
|
|
|
|
response_text: str
|
|
|
|
|
|
stage_code: str
|
2026-10-19 16:25:04 +08:00
|
|
|
|
|
|
|
|
|
|
# ---- 客户端事件(作业 3) ----
|
|
|
|
|
|
# ClientEvent.value 或 ""(普通输入)。由 normalize_input 每轮解析。
|
|
|
|
|
|
client_event: str
|
|
|
|
|
|
|
|
|
|
|
|
# ---- 领域状态(作业 3,作业 4—6 逐步充实) ----
|
|
|
|
|
|
raw_status_code: str # 原始状态码(外部归一化前的内部码)
|
|
|
|
|
|
pending_question: str # 当前待回答问题 ID(如 "driver_identity")
|
|
|
|
|
|
accident_fields: dict # 事故字段:jdcsl/ywrysw/sgfssj/...
|
|
|
|
|
|
person_fields: dict # 两方人员字段:xm1/2、hphm1/2、sfzmwh1/2...
|
|
|
|
|
|
confirm_status: dict # 字段确认状态:unknown/candidate/confirmed
|
|
|
|
|
|
clarify_count: int # 澄清计数(阈值按阶段配置,作业 4-9)
|
|
|
|
|
|
no_reply_count: int # 连续无回复计数(两次 → 0004)
|
|
|
|
|
|
turn_patch: dict # 本轮输出字段差量;每轮开始清空(作业 3-7)
|
|
|
|
|
|
state_version: int # 业务版本(作业 7 并发冲突检测)
|