Skip to content

Commit 9fbcf5f

Browse files
committed
feat: Optimize the logic for AI nodes invoking agents.
1 parent 46bd97f commit 9fbcf5f

14 files changed

Lines changed: 1046 additions & 797 deletions

File tree

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# coding=utf-8
22
"""
3-
@project: MaxKB
4-
@file: tool_aggregator.py
5-
@date:2026/7/22 16:24
6-
@desc: ToolContent 聚合器
3+
@project: MaxKB
4+
@file: tool_aggregator.py
5+
@date:2026/7/22 16:24
6+
@desc: ToolContent 聚合器
77
"""
8+
89
from application.workflow.message.aggregator.content_aggregator import ContentAggregator
910
from application.workflow.message.struct.tool_content import ToolContent
1011

@@ -18,36 +19,38 @@ class ToolAggregator(ContentAggregator[ToolContent]):
1819
def aggregate(self, prev: ToolContent, chunk: ToolContent) -> ToolContent:
1920
"""
2021
聚合工具内容
21-
22+
2223
@param prev: 之前的内容
2324
@param chunk: 新的内容块
2425
@return: 合并后的内容
2526
"""
2627
if prev is None:
2728
return chunk
2829

29-
# 合并 content (tool_name)
30-
prev_content = prev.content if prev.content else ""
31-
chunk_content = chunk.content if chunk.content else ""
32-
merged_content = chunk_content if chunk_content else prev_content
30+
# 合并 name (tool_name):取新回退旧
31+
prev_name = prev.name if prev.name else ""
32+
chunk_name = chunk.name if chunk.name else ""
33+
merged_name = chunk_name if chunk_name else prev_name
3334

34-
# 合并 arguments
35+
# 合并 arguments:拼接
3536
prev_arguments = prev.arguments if prev.arguments else ""
3637
chunk_arguments = chunk.arguments if chunk.arguments else ""
3738
merged_arguments = prev_arguments + chunk_arguments
3839

39-
# 合并 result
40-
prev_result = prev.result if prev.result else ""
41-
chunk_result = chunk.result if chunk.result else ""
42-
merged_result = prev_result + chunk_result
40+
# 合并 content(即 result 结果):拼接
41+
prev_content = prev.content if prev.content else ""
42+
chunk_content = chunk.content if chunk.content else ""
43+
merged_content = prev_content + chunk_content
4344

4445
# 合并基础字段
4546
merged_id = chunk.id if chunk.id else prev.id
4647
merged_status = chunk.status if chunk.status else prev.status
4748
merged_node_info = chunk.node_info if chunk.node_info else prev.node_info
4849
merged_position = chunk.position if chunk.position else prev.position
4950

50-
result = ToolContent(merged_id, merged_content, merged_arguments, merged_result,
51-
merged_status, merged_node_info, merged_position)
51+
# ToolContent(_id, tool_name, arguments, result, status, node_info, position)
52+
result = ToolContent(
53+
merged_id, merged_name, merged_arguments, merged_content, merged_status, merged_node_info, merged_position
54+
)
5255

5356
return result
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
# coding=utf-8
22
"""
3-
@project: MaxKB
4-
@Author:虎虎
5-
@file: tool_content.py
6-
@date:2026/6/30 16:17
7-
@desc:
3+
@project: MaxKB
4+
@Author:虎虎
5+
@file: tool_content.py
6+
@date:2026/6/30 16:17
7+
@desc:
88
"""
9+
910
from application.workflow.content_type import ContentType
1011
from application.workflow.message.struct.content import Content, NodeInfo, Position
1112
from application.workflow.status import Status
1213

1314

1415
class ToolContent(Content):
15-
def __init__(self, _id, tool_name: str, arguments: str, result: str, status: Status, node_info: NodeInfo,
16-
position: Position, **kwargs):
17-
self.content = tool_name
16+
def __init__(
17+
self,
18+
_id,
19+
tool_name: str,
20+
arguments: str,
21+
result: str,
22+
status: Status,
23+
node_info: NodeInfo,
24+
position: Position,
25+
**kwargs,
26+
):
27+
self.name = tool_name
1828
self.arguments = arguments
19-
self.result = result
29+
self.content = result
2030
super().__init__(_id, status, ContentType.TOOL, node_info, position, **kwargs)
2131

2232
def to_dict(self):
2333
result = super().to_dict()
24-
result['content'] = self.content
25-
result['arguments'] = self.arguments
26-
result['result'] = self.result
34+
result["content"] = self.content
35+
result["arguments"] = self.arguments
36+
result["name"] = self.name
2737
return result

0 commit comments

Comments
 (0)