From 141de353eac40dc18bd386c8be0b8c7dbb6f7824 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Wed, 20 Aug 2025 13:48:30 +0800 Subject: [PATCH] fix: AI dialogue node calls MCP, AI's reply content is included in the code block of MCP call result, markdown parsing error #3846 (#3894) --- .../ai_chat_step_node/impl/base_chat_node.py | 19 +++++++++++++++---- ui/src/workflow/common/NodeContainer.vue | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py index 00871a8dc..05ab5009c 100644 --- a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py +++ b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py @@ -11,7 +11,6 @@ import json import re import time from functools import reduce -from types import AsyncGeneratorType from typing import List, Dict from django.db.models import QuerySet @@ -33,13 +32,25 @@ tool_message_template = """ Called MCP Tool: %s -```json %s -``` + """ +tool_message_json_template = """ +```json +%s +``` +""" + + +def generate_tool_message_template(name, context): + if '```' in context: + return tool_message_template % (name, context) + else: + return tool_message_template % (name, tool_message_json_template % (context)) + def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str, reasoning_content: str): @@ -109,7 +120,7 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers): response = agent.astream({"messages": message_list}, stream_mode='messages') async for chunk in response: if isinstance(chunk[0], ToolMessage): - content = tool_message_template % (chunk[0].name, chunk[0].content) + content = generate_tool_message_template(chunk[0].name, chunk[0].content) chunk[0].content = content yield chunk[0] if isinstance(chunk[0], AIMessageChunk): diff --git a/ui/src/workflow/common/NodeContainer.vue b/ui/src/workflow/common/NodeContainer.vue index 8d845333a..990eb96c1 100644 --- a/ui/src/workflow/common/NodeContainer.vue +++ b/ui/src/workflow/common/NodeContainer.vue @@ -297,7 +297,6 @@ function clickNodes(item: any) { x: anchorData.value?.x + width / 2 + 200, y: anchorData.value?.y - item.height }) - console.log(nodeModel) props.nodeModel.graphModel.addEdge({ type: 'app-edge', sourceNodeId: props.nodeModel.id,