feat(agent): add LangGraph scaffold for assignment 1

- src/agent/state.py: minimal five-field AgentState
- src/agent/graph.py: START -> normalize_input -> reply -> END,
  compiled with InMemorySaver; reply emits <state>1002</state> prefix
- examples/langgraph_smoke.py: offline smoke, turns 1/2/1 verified
- test/agent/test_scaffold.py: turn accumulation, thread isolation,
  fixed-template assertions (3 passed)
- requirements.txt: pin langgraph==1.2.9

Known limit: InMemorySaver state disappears on process exit.
This commit is contained in:
Eric Wang
2026-10-19 13:32:43 +08:00
parent a9a1393f64
commit 5020903791
6 changed files with 211 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
"""图状态定义(作业 1)。
最小状态只包含脚手架所需的五个字段;作业 3 会扩充领域状态
(阶段、事故字段、人员字段、澄清计数、本轮 patch 等)。
所有字段必须可序列化,不得保存 HTTP client、数据库连接等资源。
"""
from typing import TypedDict
class AgentState(TypedDict):
"""一次对话轮次在图中流动的状态。
``turn_count`` 由同一 ``thread_id`` 的 checkpoint 承载,
节点每轮只负责 +1,不负责跨会话记忆。
"""
session_id: str
turn_count: int
input_text: str
response_text: str
stage_code: str