- time_context.py: server-side observation clocks for relative-time evidence (anti client-forgery); resolves X分钟前/小时前 against the observation timestamp of the turn that produced them, never re-basing history on the current clock; flags historical references without a reliable baseline - state: dialogue_timestamps keyed by dialogue message index, persisted with checkpoint; welcome seeds index 0 - collect: single clock per turn shared by reply/extraction/repair; time_evidence injected into runtime context; reply_validator hook rejects time claims lacking evidence (one shared repair budget); model still interprets facts and chooses actions - prompts: collection prompt restructured (shorter, state-bound-to-action table, gatekeeper principle, time source rules); extraction prompt aligned; workflow@20261021 json updated to match - evals: prompt_probes / prompt_compare / time_boundary probe scripts (supplementary checks, original cases untouched) - docs: collection-prompt-optimization.md (method + baselines), time-boundary-fix.md (problem, design, verification) - gitignore: editor artifact dirs (.agents/.claude/.vscode, skills-lock) Verified: 171 unit tests pass (16 new time-context tests)
57 lines
2.7 KiB
Python
57 lines
2.7 KiB
Python
"""图状态定义。
|
||
|
||
作业 1 的五个基础字段之上,作业 3 扩充领域状态:内部阶段、原始状态码、
|
||
待回答问题、事故字段、两方人员字段、字段确认状态、澄清计数、无回复计数、
|
||
本轮 patch 和业务版本。
|
||
|
||
约束(迁移计划作业 3-2):所有字段必须可序列化,
|
||
不保存 HTTP client、数据库连接、音频或图片 base64。
|
||
字段读取一律用 ``state.get(...)`` 并提供默认值——首轮会话没有
|
||
历史 checkpoint,字段可能尚未初始化。
|
||
"""
|
||
|
||
from typing import TypedDict
|
||
|
||
|
||
class AgentState(TypedDict):
|
||
"""一次对话轮次在图中流动的状态。
|
||
|
||
``turn_count``、``stage_code`` 等由同一 ``thread_id`` 的
|
||
checkpoint 承载跨轮记忆;节点返回字段增量,LangGraph 合并写回。
|
||
"""
|
||
|
||
# ---- 基础(作业 1) ----
|
||
session_id: str
|
||
turn_count: int
|
||
input_text: str
|
||
response_text: str
|
||
stage_code: str
|
||
|
||
# ---- 客户端事件(作业 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 并发冲突检测)
|
||
|
||
# ---- 对话上下文(作业 4/5) ----
|
||
# 已交换的消息列表 [{"role": "user"/"assistant", "content": str}],
|
||
# 用于注入提示词,让模型跳过已知信息;可序列化,随 checkpoint 持久化。
|
||
dialogue: list
|
||
# 服务器接收用户消息时的时钟,key为完整dialogue的消息索引;
|
||
# 独立于消息正文,避免客户端伪造历史基准,随checkpoint跨轮保存。
|
||
dialogue_timestamps: dict[str, str]
|
||
client_mode: str # direct / browser_addon(LangGraphBackend 注入)
|
||
|
||
# ---- 信息核实(作业 5) ----
|
||
person_index: int # 当前核实的驾驶员序号(双车:1/2)
|
||
# pending_question 复用作业 3 字段:当前待回答问题 ID(如 "owner_identity")
|