彻底重构状态系统:整合所有旧状态到 MainGraphState,修复所有节点
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m35s
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m35s
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
from typing import Any, Dict
|
||||
from langchain_core.runnables.config import RunnableConfig
|
||||
from app.main_graph.state import MessagesState
|
||||
from app.main_graph.state import MainGraphState
|
||||
from app.memory.mem0_client import Mem0Client
|
||||
from app.logger import info
|
||||
|
||||
|
||||
def _get_attr(state, attr_name, default=None):
|
||||
"""通用方法:兼容 dict 和 dataclass 两种状态格式"""
|
||||
if isinstance(state, dict):
|
||||
return state.get(attr_name, default)
|
||||
else:
|
||||
return getattr(state, attr_name, default)
|
||||
|
||||
|
||||
# 全局变量,在 GraphBuilder 中注入
|
||||
_mem0_client: Mem0Client = None
|
||||
|
||||
@@ -22,12 +14,12 @@ def set_mem0_client(client: Mem0Client):
|
||||
_mem0_client = client
|
||||
|
||||
|
||||
async def memory_trigger_node(state, config: RunnableConfig) -> Dict[str, Any]:
|
||||
async def memory_trigger_node(state: MainGraphState, config: RunnableConfig) -> Dict[str, Any]:
|
||||
"""检测用户消息中的记忆指令,若命中则主动调用 Mem0 存储"""
|
||||
if _mem0_client is None:
|
||||
return {}
|
||||
|
||||
messages = _get_attr(state, "messages", [])
|
||||
messages = state.messages
|
||||
if not messages:
|
||||
return {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user