Merge pull request #3102 from xinnan-tech/fix-title-summary

fix:将标题总结从记忆流程中拆分为独立接口,支持异步执行
This commit is contained in:
wengzh
2026-04-16 17:24:56 +08:00
committed by GitHub
9 changed files with 63 additions and 21 deletions
@@ -150,6 +150,13 @@ public class AgentController {
}
}
@PostMapping("/chat-title/{sessionId}/generate")
@Operation(summary = "根据会话ID生成聊天标题")
public Result<Void> generateAndSaveChatTitle(@PathVariable String sessionId) {
agentChatSummaryService.generateAndSaveChatTitle(sessionId);
return new Result<Void>().ok(null);
}
@PutMapping("/{id}")
@Operation(summary = "更新智能体")
@RequiresPermissions("sys:role:normal")
@@ -12,4 +12,12 @@ public interface AgentChatSummaryService {
* @return 保存结果
*/
boolean generateAndSaveChatSummary(String sessionId);
/**
* 根据会话ID生成聊天标题并保存
*
* @param sessionId 会话ID
* @return 是否成功
*/
boolean generateAndSaveChatTitle(String sessionId);
}
@@ -104,7 +104,6 @@ public class AgentChatSummaryServiceImpl implements AgentChatSummaryService {
if (memModelId == null || memModelId.equals(Constant.MEMORY_MEM_REPORT_ONLY)) {
log.info("会话 {} 使用仅上报聊天记录模式,跳过记忆总结", sessionId);
generateAndSaveChatTitle(sessionId, agentId);
return true;
}
@@ -128,7 +127,6 @@ public class AgentChatSummaryServiceImpl implements AgentChatSummaryService {
log.info("会话 {} 使用 {} 模式,跳过记忆总结", sessionId, memModelId);
}
generateAndSaveChatTitle(sessionId, agentId);
return true;
} catch (Exception e) {
@@ -137,16 +135,24 @@ public class AgentChatSummaryServiceImpl implements AgentChatSummaryService {
}
}
private void generateAndSaveChatTitle(String sessionId, String agentId) {
@Override
public boolean generateAndSaveChatTitle(String sessionId) {
try {
// 自动获取agentId
String agentId = findAgentIdBySessionId(sessionId);
if (StringUtils.isBlank(agentId)) {
log.warn("会话 {} 无法获取智能体信息,跳过标题生成", sessionId);
return false;
}
List<AgentChatHistoryDTO> chatHistory = getChatHistoryBySessionId(sessionId);
if (chatHistory == null || chatHistory.isEmpty()) {
return;
return false;
}
List<String> meaningfulMessages = extractMeaningfulMessages(chatHistory);
if (meaningfulMessages.isEmpty()) {
return;
return false;
}
StringBuilder conversation = new StringBuilder();
@@ -160,9 +166,12 @@ public class AgentChatSummaryServiceImpl implements AgentChatSummaryService {
if (StringUtils.isNotBlank(title)) {
agentChatTitleService.saveOrUpdateTitle(sessionId, title);
log.info("成功保存会话 {} 的标题: {}", sessionId, title);
return true;
}
return false;
} catch (Exception e) {
log.error("生成会话 {} 的标题时发生错误: {}", sessionId, e.getMessage());
return false;
}
}
@@ -90,6 +90,7 @@ public class ShiroConfig {
filterMap.put("/agent/chat-history/report", "server");
filterMap.put("/agent/chat-history/download/**", "anon");
filterMap.put("/agent/chat-summary/**", "server");
filterMap.put("/agent/chat-title/**", "server");
filterMap.put("/agent/play/**", "anon");
filterMap.put("/voiceClone/play/**", "anon");
filterMap.put("/**", "oauth2");