Skip to content

Commit a3a5259

Browse files
committed
fix: AI dialogue node calls MCP, AI's reply content is included in the code block of MCP call result, markdown parsing error #3846
1 parent c743520 commit a3a5259

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import re
1212
import time
1313
from functools import reduce
14-
from types import AsyncGeneratorType
1514
from typing import List, Dict
1615

1716
from django.db.models import QuerySet
@@ -33,13 +32,25 @@
3332
<strong>Called MCP Tool: <em>%s</em></strong>
3433
</summary>
3534
36-
```json
3735
%s
38-
```
36+
3937
</details>
4038
4139
"""
4240

41+
tool_message_json_template = """
42+
```json
43+
%s
44+
```
45+
"""
46+
47+
48+
def generate_tool_message_template(name, context):
49+
if '```' in context:
50+
return tool_message_template % (name, context)
51+
else:
52+
return tool_message_template % (name, tool_message_json_template % (context))
53+
4354

4455
def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str,
4556
reasoning_content: str):
@@ -109,7 +120,7 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers):
109120
response = agent.astream({"messages": message_list}, stream_mode='messages')
110121
async for chunk in response:
111122
if isinstance(chunk[0], ToolMessage):
112-
content = tool_message_template % (chunk[0].name, chunk[0].content)
123+
content = generate_tool_message_template(chunk[0].name, chunk[0].content)
113124
chunk[0].content = content
114125
yield chunk[0]
115126
if isinstance(chunk[0], AIMessageChunk):

ui/src/workflow/common/NodeContainer.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ function clickNodes(item: any) {
297297
x: anchorData.value?.x + width / 2 + 200,
298298
y: anchorData.value?.y - item.height
299299
})
300-
console.log(nodeModel)
301300
props.nodeModel.graphModel.addEdge({
302301
type: 'app-edge',
303302
sourceNodeId: props.nodeModel.id,

0 commit comments

Comments
 (0)