This commit is contained in:
25
backend/app/graph/state.py
Normal file
25
backend/app/graph/state.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""
|
||||
LangGraph 状态定义模块
|
||||
包含 MessagesState 和 GraphContext
|
||||
"""
|
||||
|
||||
import operator
|
||||
from typing import Annotated
|
||||
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
|
||||
# 可扩展更多上下文信息
|
||||
Reference in New Issue
Block a user