🔄 多轮对话
# 基本原理
多轮对话的关键是让多次调用使用同一个 conversationId,同时保持同一个 Agent 的 agentKey 不变(默认 nodeId 已满足)。
只要多次执行解析出的 (conversationId, agentKey) 相同,Agent 就会复用同一份 memory。
# 方式 1:显式传入 conversationId
// 第一轮
LiteflowResponse first = flowExecutor.execute2Resp(
"deepseekChain",
"LiteFlow是什么?",
ExecuteOption.of().conversationId("chat-user-1-conv-1")
);
// 第二轮(Agent 能记住第一轮的对话内容)
LiteflowResponse second = flowExecutor.execute2Resp(
"deepseekChain",
"它能做哪些事情?",
ExecuteOption.of().conversationId("chat-user-1-conv-1")
);
# 方式 2:按业务对象自动生成
@Override
protected String resolveConversationId() {
ChatRequest req = getSlot().getChainReqData(getSlot().getChainId());
return "chat-" + req.getUserId() + "-" + req.getConversationId();
}
# 跨 JVM 重启恢复
是否能跨 JVM 重启恢复历史记忆,取决于 liteflow.agent.session.memory.mode:
JVM或NONE:无法恢复LOCAL_FILE、REDIS、MYSQL:可以恢复
详见 记忆持久化。
帮助我们改善此文档 (opens new window)
上次更新: 2026/05/24, 14:26:24


