This commit is contained in:
@@ -24,13 +24,15 @@ def create_summarize_node(mem0_client: Mem0Client):
|
||||
异步节点函数
|
||||
"""
|
||||
|
||||
async def summarize_conversation(state: MessagesState, runtime: Runtime[GraphContext]) -> Dict[str, Any]:
|
||||
from langchain_core.runnables.config import RunnableConfig
|
||||
|
||||
async def summarize_conversation(state: MessagesState, config: RunnableConfig) -> Dict[str, Any]:
|
||||
"""
|
||||
记忆存储节点 - 使用 Mem0
|
||||
|
||||
Args:
|
||||
state: 当前对话状态
|
||||
runtime: LangGraph 运行时上下文
|
||||
config: 运行时配置
|
||||
|
||||
Returns:
|
||||
重置计数器的状态更新
|
||||
@@ -42,7 +44,8 @@ def create_summarize_node(mem0_client: Mem0Client):
|
||||
debug("📝 [记忆添加] 对话过短,跳过")
|
||||
return {"turns_since_last_summary": 0}
|
||||
|
||||
user_id = runtime.context.user_id
|
||||
# 从 metadata 中获取 user_id
|
||||
user_id = config.get("metadata", {}).get("user_id", "default_user")
|
||||
|
||||
# 确保 Mem0 已初始化(懒加载)
|
||||
if not mem0_client._initialized:
|
||||
@@ -83,4 +86,4 @@ def create_summarize_node(mem0_client: Mem0Client):
|
||||
log_state_change("summarize", state, "离开")
|
||||
return {"turns_since_last_summary": 0}
|
||||
|
||||
return summarize_conversation
|
||||
return summarize_conversation
|
||||
Reference in New Issue
Block a user