33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
"""LangGraph Agent 状态类型定义。
|
|
|
|
系统定位:
|
|
定义图运行时共享状态 ``AgentState``,被 ``graph_builder``、``nodes``、
|
|
``routing`` 作为 StateGraph 的 schema 使用。
|
|
|
|
可扩展性:
|
|
- 可在此增加 ``session_id``、``agent_mode``、``pending_approval`` 等字段,
|
|
需配合 reducer(如 add_messages)声明合并策略。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Annotated, Sequence, TypedDict
|
|
|
|
from langchain_core.messages import BaseMessage
|
|
from langgraph.graph.message import add_messages
|
|
|
|
|
|
class AgentState(TypedDict):
|
|
"""LangGraph 图状态:消息列表为唯一状态字段。
|
|
|
|
字段:
|
|
messages: 对话消息序列,通过 ``add_messages`` 追加合并。
|
|
|
|
系统定位:
|
|
ReAct 循环(agent -> tools -> process_tool_artifact -> agent)的载体。
|
|
|
|
可扩展性:
|
|
扩展字段时保持 TypedDict 与 reducer 注解一致,避免并发更新冲突。
|
|
"""
|
|
|
|
messages: Annotated[Sequence[BaseMessage], add_messages]
|