diff --git a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java index 8a9e4fba..b438fec1 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java +++ b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java @@ -151,6 +151,11 @@ public interface Constant { */ String MEMORY_NO_MEM = "Memory_nomem"; + /** + * 仅上报聊天记录(不总结记忆) + */ + String MEMORY_MEM_REPORT_ONLY = "Memory_mem_report_only"; + /** * 火山引擎双声道语音克隆 */ diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentChatSummaryServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentChatSummaryServiceImpl.java index 38fef94b..26e601ec 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentChatSummaryServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentChatSummaryServiceImpl.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.RequiredArgsConstructor; +import xiaozhi.common.constant.Constant; import xiaozhi.modules.agent.dto.AgentChatHistoryDTO; import xiaozhi.modules.agent.dto.AgentChatSummaryDTO; import xiaozhi.modules.agent.dto.AgentMemoryDTO; @@ -90,21 +91,28 @@ public class AgentChatSummaryServiceImpl implements AgentChatSummaryService { @Override public boolean generateAndSaveChatSummary(String sessionId) { try { - // 1. 生成总结 - AgentChatSummaryDTO summaryDTO = generateChatSummary(sessionId); - if (!summaryDTO.isSuccess()) { - log.info("生成总结失败: {}", summaryDTO.getErrorMessage()); - return false; - } - - // 2. 获取设备信息(通过会话关联的设备) + // 1. 获取设备信息(通过会话关联的设备) DeviceEntity device = getDeviceBySessionId(sessionId); if (device == null) { log.info("未找到与会话 {} 关联的设备", sessionId); return false; } - // 3. 更新智能体记忆 + // 2. 检查记忆模型类型,如果是仅上报聊天记录模式则跳过总结 + String memModelId = agentService.getAgentById(device.getAgentId()).getMemModelId(); + if (memModelId != null && memModelId.equals(Constant.MEMORY_MEM_REPORT_ONLY)) { + log.info("会话 {} 使用仅上报聊天记录模式,跳过记忆总结", sessionId); + return true; + } + + // 3. 生成总结 + AgentChatSummaryDTO summaryDTO = generateChatSummary(sessionId); + if (!summaryDTO.isSuccess()) { + log.info("生成总结失败: {}", summaryDTO.getErrorMessage()); + return false; + } + + // 4. 更新智能体记忆 AgentMemoryDTO memoryDTO = new AgentMemoryDTO(); memoryDTO.setSummaryMemory(summaryDTO.getSummary()); diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java index 049387c3..fe6df77f 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelProviderServiceImpl.java @@ -95,6 +95,7 @@ public class ModelProviderServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("model_type", StringUtils.isBlank(modelType) ? "" : modelType); + queryWrapper.orderByAsc("sort"); List providerEntities = modelProviderDao.selectList(queryWrapper); return ConvertUtils.sourceToTarget(providerEntities, ModelProviderDTO.class); } diff --git a/main/manager-api/src/main/resources/db/changelog/202603231036.sql b/main/manager-api/src/main/resources/db/changelog/202603231036.sql new file mode 100644 index 00000000..686b9b44 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202603231036.sql @@ -0,0 +1,6 @@ + +delete from `ai_model_provider` where `id` = 'SYSTEM_Memory_mem_report_only'; +delete from `ai_model_config` where `id` = 'Memory_mem_report_only'; + +INSERT INTO `ai_model_provider` VALUES ('SYSTEM_Memory_mem_report_only', 'Memory', 'mem_report_only', '仅上报聊天记录', '[]', 4, 1, NOW(), 1, NOW()); +INSERT INTO `ai_model_config` VALUES ('Memory_mem_report_only', 'Memory', 'mem_report_only', '仅上报聊天记录', 0, 1, '{"type": "mem_report_only"}', NULL, NULL, 3, NULL, NULL, NULL, NULL); \ No newline at end of file diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index efdf68d4..0a30c341 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -571,3 +571,10 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202603111131.sql + - changeSet: + id: 202603231036 + author: rainv123 + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202603231036.sql \ No newline at end of file diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index c60c1a4a..90c9704e 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -751,8 +751,8 @@ class ConnectionHandler: memory_type = self.config["Memory"][self.config["selected_module"]["Memory"]][ "type" ] - # 如果使用 nomen,直接返回 - if memory_type == "nomem": + # 如果使用 nomen 或 mem_report_only,直接返回 + if memory_type == "nomem" or memory_type == "mem_report_only": return # 使用 mem_local_short 模式 elif memory_type == "mem_local_short": diff --git a/main/xiaozhi-server/core/providers/memory/mem_report_only/mem_report_only.py b/main/xiaozhi-server/core/providers/memory/mem_report_only/mem_report_only.py new file mode 100644 index 00000000..2fd1fdff --- /dev/null +++ b/main/xiaozhi-server/core/providers/memory/mem_report_only/mem_report_only.py @@ -0,0 +1,20 @@ +""" +仅上报聊天记录,不进行记忆总结 +""" + +from ..base import MemoryProviderBase, logger + +TAG = __name__ + + +class MemoryProvider(MemoryProviderBase): + def __init__(self, config, summary_memory=None): + super().__init__(config) + + async def save_memory(self, msgs, session_id=None): + logger.bind(tag=TAG).debug("mem_report_only mode: No memory saving or summarization is performed.") + return None + + async def query_memory(self, query: str) -> str: + logger.bind(tag=TAG).debug("mem_report_only mode: No memory query is performed.") + return "" \ No newline at end of file