28 lines
727 B
Python
28 lines
727 B
Python
"""
|
|
LangGraph 状态定义模块
|
|
包含 MessagesState 和 GraphContext
|
|
"""
|
|
|
|
import operator
|
|
from typing import Annotated, Any
|
|
from typing_extensions import TypedDict
|
|
from dataclasses import dataclass
|
|
from langchain_core.messages import AnyMessage
|
|
|
|
|
|
class MessagesState(TypedDict):
|
|
"""对话状态类型定义"""
|
|
messages: Annotated[list[AnyMessage], operator.add]
|
|
llm_calls: int
|
|
memory_context: str
|
|
last_token_usage: dict # 本次调用的 token 使用详情
|
|
last_elapsed_time: float # 本次调用耗时(秒)
|
|
turns_since_last_summary: int # 距离上次生成摘要的轮数
|
|
|
|
|
|
@dataclass
|
|
class GraphContext:
|
|
"""图执行上下文"""
|
|
user_id: str
|
|
# 可扩展更多上下文信息
|