fix(graph): preserve clarification turns in context#541
Open
dwyyyyy wants to merge 1 commit into
Open
Conversation
Before this change, clarification turns could be lost from the backend multi-turn context. When FeasibilityAssessmentNode classified a user request as needing clarification, the graph streamed the clarification response and then ended before entering PlannerNode. MultiTurnContextManager only persisted turns that had PlannerNode output, so finishTurn discarded these clarification turns. That meant a follow-up such as "按点击数" was sent as a new query with no record of the original question or the assistant's clarification prompt in MULTI_TURN_CONTEXT. The model therefore could not reliably understand that the follow-up was answering the previous clarification. This change records assistant output for the pending turn as a fallback when no planner output is produced. Planner output is still saved as AI计划. If a turn ends before PlannerNode but streamed an assistant response, it is now saved as AI回复 together with the original user question. Empty turns are still skipped. With this context preserved, the next request on the same thread can see both the original question and the clarification prompt, so short follow-ups such as "按点击数" can be interpreted as clarification answers instead of isolated new queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
修复多轮对话中“用户澄清后无法稳定续接上一轮问题”的问题。
当前流程里,如果
FeasibilityAssessmentNode将用户请求判断为“需要澄清”,Graph 会流式输出澄清问题,然后在进入PlannerNode之前结束本轮执行。例如:
找出最受欢迎的网络小说请问您指的“最受欢迎”是按“评分”还是“点击数”来衡量呢?按点击数修复前,
MultiTurnContextManager只会保存有PlannerNode输出的轮次。由于“需要澄清”的轮次没有进入PlannerNode,finishTurn会直接丢弃这一轮上下文,导致下一轮的按点击数会作为一个孤立的新 query 处理,MULTI_TURN_CONTEXT中没有上一轮原始问题和澄清提示。这会导致模型无法稳定判断用户是在回答上一轮澄清问题。
Does this pull request fix one issue?
NONE
Describe how you did it
本 PR 调整了多轮上下文记录逻辑:
MultiTurnContextManager中新增 assistant 输出缓存。GraphServiceImpl中,PlannerNode的流式输出仍然写入 planner 输出;非PlannerNode的流式输出会写入 assistant 输出。finishTurn时:AI计划AI回复这样即使流程在澄清阶段结束,也会把本轮用户问题和 assistant 澄清回复保存到多轮上下文中。
修复后,下一轮同一个
threadId的请求可以在MULTI_TURN_CONTEXT中看到:因此用户继续输入
按点击数时,模型可以结合上下文理解这是对上一轮澄清问题的回答,而不是孤立的新 query。Describe how to verify it
可以通过以下场景验证:
找出最受欢迎的网络小说threadId下继续输入:按点击数MULTI_TURN_CONTEXT中包含上一轮用户问题和 assistant 澄清回复按点击数理解为上一轮问题的补充条件已补充
MultiTurnContextManagerTest,覆盖无PlannerNode输出但有 assistant 回复时应保存上下文的场景。本地尝试执行:
./mvnw -pl data-agent-management -Dtest=MultiTurnContextManagerTest test但当前本地环境 Maven wrapper 执行超时,未能完成测试运行。
Special notes for reviews
本次修改保持原有 planner 输出逻辑不变,仅在没有 planner 输出但存在 assistant 输出时,额外保存该轮上下文,避免澄清轮次丢失。