🗂️ 聊天历史
# 查询和删除聊天记录
历史记录默认开启。需要在业务接口中查询时,导入服务配置:
import com.yomahub.liteflow.agent.conversation.AgentConversationConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import(AgentConversationConfiguration.class)
public class ConversationConfiguration {
}
注入 com.yomahub.liteflow.agent.conversation.AgentConversationService,即可调用:
var sessions = conversations.list(0, 20);
var messages = conversations.messages(conversationId, 0, 50);
if (messages.hasMore()) {
var nextPage = conversations.messages(conversationId, messages.nextCursor(), 50);
}
conversations.update(conversationId, "新的会话标题", java.util.Map.of());
分页数据通过 items() 取出,limit 为 1~200。展示历史与模型续聊状态分开保存,长对话压缩不会因此删掉聊天记录。
调用 conversations.delete(conversationId) 会清理展示消息和已关联的 Agent 状态;工作区文件与快照仍需按业务需要清理。已删除的 ID 不再复用,新对话使用新 ID。
# 历史记录与续聊状态
liteflow.agent.conversation-history-enabled 默认为 true。展示用的消息历史和模型续聊状态分别保存;关闭历史记录不影响模型状态的保存,长对话压缩也不会删除展示历史。
多 Agent 链只想展示最终答复时,可先通过 conversations.create(conversationId, "标题", false) 创建会话,关闭该会话的自动消息记录,再由业务调用 append(...) 保存用户输入与最终结果。全局历史配置仍保持开启,以便追踪会话关联的 Agent。
查询、更新和删除接口均应校验业务访问权限。删除会话不代表清理了该会话的全部文件,工作区、快照和业务保存的附件需按各自保留策略处理。
帮助我们改善此文档 (opens new window)
上次更新: 2026/09/20, 11:49:27



