|
|
@@ -497,6 +497,7 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
Map<String, Object> fullGraph = buildFullGraphPayload(
|
|
|
input == null ? null : input.toString(), graphCaseId, graphUserId);
|
|
|
if (fullGraph != null) {
|
|
|
+ process.graphData.put(e.getToolCallId(), fullGraph);
|
|
|
Map<String, Object> graphFrame = new LinkedHashMap<>();
|
|
|
graphFrame.put("type", "graph_data");
|
|
|
graphFrame.put("toolCallId", e.getToolCallId());
|
|
|
@@ -528,7 +529,7 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
} else if (event instanceof AgentResultEvent e) {
|
|
|
// AI 回复落库(异步,不阻塞事件流);工具调用事件与思考过程一并持久化
|
|
|
resultPersisted.set(true);
|
|
|
- String toolEventsJson = buildToolEventsJson(toolInputs, toolResults, toolNames);
|
|
|
+ String toolEventsJson = buildToolEventsJson(toolInputs, toolResults, toolNames, process.graphData);
|
|
|
String thinkingJson = buildThinkingMetadata(accumulatedThinking.get().toString());
|
|
|
Mono.fromRunnable(() -> persistAssistantMessage(sessionId, e.getResult(), toolEventsJson, thinkingJson))
|
|
|
.subscribeOn(Schedulers.boundedElastic())
|
|
|
@@ -542,7 +543,7 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
// 用户主动中止:若 AgentResultEvent 尚未到达,保存已流式输出的部分内容
|
|
|
if (!resultPersisted.get()) {
|
|
|
String partialText = accumulatedText.get().toString().trim();
|
|
|
- String toolEventsJson = buildToolEventsJson(toolInputs, toolResults, toolNames);
|
|
|
+ String toolEventsJson = buildToolEventsJson(toolInputs, toolResults, toolNames, process.graphData);
|
|
|
String thinkingJson = buildThinkingMetadata(accumulatedThinking.get().toString());
|
|
|
if (!partialText.isEmpty() || !toolEventsJson.isEmpty()) {
|
|
|
Mono.fromRunnable(() -> persistPartialMessage(sessionId, partialText, toolEventsJson, thinkingJson))
|
|
|
@@ -713,7 +714,7 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
// 避免同轮的时间线/产物在历史里出现两份
|
|
|
boolean processLost = process != null && !process.resultPersisted.get();
|
|
|
String toolEventsJson = processLost
|
|
|
- ? buildToolEventsJson(process.toolInputs, process.toolResults, process.toolNames) : null;
|
|
|
+ ? buildToolEventsJson(process.toolInputs, process.toolResults, process.toolNames, process.graphData) : null;
|
|
|
String thinkingJson = processLost
|
|
|
? buildThinkingMetadata(process.thinking.get().toString()) : null;
|
|
|
AgentMessage msg = new AgentMessage();
|
|
|
@@ -864,7 +865,8 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
*/
|
|
|
private static String buildToolEventsJson(Map<String, StringBuilder> toolInputs,
|
|
|
Map<String, StringBuilder> toolResults,
|
|
|
- Map<String, String> toolNames) {
|
|
|
+ Map<String, String> toolNames,
|
|
|
+ Map<String, Object> graphData) {
|
|
|
if (toolNames.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -879,6 +881,11 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
// 兜底再解一层:个别工具的 delta 可能在累积时才成完整字符串字面量
|
|
|
ev.put("result", result != null ? unwrapJsonString(result.toString()) : "");
|
|
|
ev.put("status", "done");
|
|
|
+ Object graph = graphData == null ? null : graphData.get(toolCallId);
|
|
|
+ if (graph != null) {
|
|
|
+ // 会话复原用:把本次查询的全量图谱随 tool_events 落库(查询条件已在 input 里)
|
|
|
+ ev.put("graphData", graph);
|
|
|
+ }
|
|
|
events.add(ev);
|
|
|
}
|
|
|
try {
|
|
|
@@ -1010,6 +1017,8 @@ public class AgentChatServiceImpl extends ServiceImpl<AgentChatSessionMapper, Ag
|
|
|
final Map<String, StringBuilder> toolInputs = new ConcurrentHashMap<>();
|
|
|
final Map<String, StringBuilder> toolResults = new ConcurrentHashMap<>();
|
|
|
final Map<String, String> toolNames = new ConcurrentHashMap<>();
|
|
|
+ /** 全量图谱按 toolCallId 暂存:随 tool_events 落库,供历史会话复原 */
|
|
|
+ final Map<String, Object> graphData = new ConcurrentHashMap<>();
|
|
|
final AtomicReference<StringBuilder> text = new AtomicReference<>(new StringBuilder());
|
|
|
final AtomicReference<StringBuilder> thinking = new AtomicReference<>(new StringBuilder());
|
|
|
/** 完整回答是否已落库(落库后出错不再重复携带过程数据) */
|