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: