From 510723e8d3c09ef6f34d597d9c703c76f2669ca6 Mon Sep 17 00:00:00 2001 From: martsforever Date: Thu, 11 Sep 2025 01:41:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E5=88=A4=E6=96=ADlan?= =?UTF-8?q?ggraph=5Fnode=E4=BB=A5=E5=8F=8A=E6=B6=88=E6=81=AF=E6=98=AFAIMes?= =?UTF-8?q?sage=E8=BF=98=E6=98=AFToolMessage=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=98=AFAIMessage=E5=B0=B1=E8=B7=B3=E8=BF=87=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E6=9D=A5=E8=A7=84=E9=81=BF=E8=BF=99=E4=B8=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/add_langgraph_chat_route.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controller/add_langgraph_chat_route.py b/app/controller/add_langgraph_chat_route.py index 0d6cfc0..14ea4f1 100644 --- a/app/controller/add_langgraph_chat_route.py +++ b/app/controller/add_langgraph_chat_route.py @@ -3,7 +3,7 @@ import time from typing import Union from fastapi import FastAPI -from langchain_core.messages import AIMessage, ToolMessage +from langchain_core.messages import AIMessage, ToolMessage, AIMessageChunk from langgraph.graph.state import CompiledStateGraph from langgraph.prebuilt import create_react_agent from langgraph.types import Command @@ -122,6 +122,14 @@ def add_langgraph_chat_route(app: FastAPI): emit_chunk = {"stream_type": chunk[0], } if emit_chunk['stream_type'] == "messages": + + if isinstance(chunk[1], tuple): + if isinstance(chunk[1][1], dict): + langgraph_node = chunk[1][1].get("langgraph_node") + if langgraph_node == "tools" and isinstance(chunk[1][0], AIMessage): + print("忽略工具中的message消息") + continue + # messages模式流式输出,此时 chunk[1][0] 为AIMessageChunk chunk_message = chunk[1][0] if not chunk_message.content: