From f3bcb01777b6956bc2413b6a5906be5ad86c2053 Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Fri, 1 May 2026 00:54:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20process=5Fmessage?= =?UTF-8?q?=5Fstream=20=E4=B8=AD=E7=BC=BA=E5=B0=91=20GraphContext=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 在 9d4cf15 提交中只更新了 process_message 方法,但没有更新 process_message_stream 方法 - process_message_stream 还在使用旧代码中的 GraphContext,导致报错 'name GraphContext is not defined' 修复: - 移除了 GraphContext 的使用 - 更新 input_state 为新的 MainGraphState 格式 - 从 graph.astream() 中移除了 context 参数 --- backend/app/agent/agent_service.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/app/agent/agent_service.py b/backend/app/agent/agent_service.py index 552f711..555c6b2 100644 --- a/backend/app/agent/agent_service.py +++ b/backend/app/agent/agent_service.py @@ -14,6 +14,7 @@ from ..model_services.chat_services import get_all_chat_services, LocalVLLMChatP from app.main_graph.utils.rag_initializer import init_rag_tool from app.core.intent_classifier import get_intent_classifier from app.logger import info, warning +from app.main_graph.state import MainGraphState, CurrentAction class AIAgentService: def __init__(self, checkpointer): @@ -120,8 +121,12 @@ class AIAgentService: "configurable": {"thread_id": thread_id}, "metadata": {"user_id": user_id} } - input_state = {"messages": [{"role": "user", "content": message}]} - context = GraphContext(user_id=user_id) + input_state = { + "user_query": message, + "messages": [{"role": "user", "content": message}], + "user_id": user_id, + "current_action": CurrentAction.NONE + } # ========== 新增:混合路由 ========== intent_result = await self.intent_classifier.classify(message) @@ -161,7 +166,6 @@ class AIAgentService: async for chunk in graph.astream( input_state, config=config, - context=context, stream_mode=["messages", "updates", "custom"], version="v2", subgraphs=True