From 7b014765d6ee19295861b56a61664c6038dd8b08 Mon Sep 17 00:00:00 2001 From: let5sne Date: Sat, 25 Jul 2026 23:58:30 +0800 Subject: [PATCH] fix(agent): answer follow-up questions instead of asking to clarify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The planner falls back to CLARIFY whenever no keyword matches and the model plan is unavailable or malformed. Mid-conversation that produced a dead end: a follow-up such as "如果我要报销,一般需要查哪几个文件?" was answered with a clarification request even though the previous turn had established context. When a non-media request carries a conversationId and a contextVersion above zero (i.e. at least one turn has completed), route CLARIFY to KNOWLEDGE_QA with a grounded knowledge search. Tradeoff: this also suppresses the deliberate CLARIFY for explicitly vague phrasing ("你看着办", "帮我处理一下") from the second turn onward, which will now run a knowledge search instead of asking back. Blank input is still rejected earlier by requireQuestion. Co-Authored-By: Claude Opus 5 (1M context) --- .../dromara/aihr/agent/AihrAgentOrchestrator.java | 10 ++++++++++ .../aihr/agent/AihrAgentOrchestratorTest.java | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/agent/AihrAgentOrchestrator.java b/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/agent/AihrAgentOrchestrator.java index 4f5c80fe..2df5a9b4 100644 --- a/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/agent/AihrAgentOrchestrator.java +++ b/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/agent/AihrAgentOrchestrator.java @@ -26,6 +26,10 @@ import java.time.OffsetDateTime; import java.util.List; import java.util.UUID; +import static org.dromara.aihr.agent.AihrAgentDto.Intent.KNOWLEDGE_QA; +import static org.dromara.aihr.agent.AihrAgentDto.ResponseStyle.GROUNDED; +import static org.dromara.aihr.agent.AihrAgentDto.Tool.KNOWLEDGE_SEARCH; + @Service @RequiredArgsConstructor public class AihrAgentOrchestrator { @@ -58,6 +62,12 @@ public class AihrAgentOrchestrator { throw new ServiceException("附件不能为空", 400); } plan = planner.plan(request.question(), media); + if (!media && plan.intent() == Intent.CLARIFY + && request.contextVersion() != null && request.contextVersion() > 0 + && request.conversationId() != null && !request.conversationId().isBlank()) { + plan = new AgentPlan(KNOWLEDGE_QA, request.question().trim(), KNOWLEDGE_SEARCH, + false, false, GROUNDED); + } principal = principalResolver.current(); response = media ? executeMedia(plan, request, file, principal) diff --git a/backend/ruoyi-modules/ruoyi-aihr/src/test/java/org/dromara/aihr/agent/AihrAgentOrchestratorTest.java b/backend/ruoyi-modules/ruoyi-aihr/src/test/java/org/dromara/aihr/agent/AihrAgentOrchestratorTest.java index a9de865a..54c2fbf6 100644 --- a/backend/ruoyi-modules/ruoyi-aihr/src/test/java/org/dromara/aihr/agent/AihrAgentOrchestratorTest.java +++ b/backend/ruoyi-modules/ruoyi-aihr/src/test/java/org/dromara/aihr/agent/AihrAgentOrchestratorTest.java @@ -87,6 +87,21 @@ class AihrAgentOrchestratorTest { assertEquals(0, query.callCount); } + @Test + void clarificationAfterACompletedTurnUsesConversationAwareKnowledge() { + var query = new CapturingQueryService(response("通常需要查报销制度和费用标准。", null, false)); + var service = orchestrator(query); + var followUp = new AgentRequest( + "如果我要报销,一般需要查哪几个文件?", "conversation_1", 1L, "P1", null, false); + + var result = service.handle(followUp); + + assertEquals(KNOWLEDGE_QA, result.intent()); + assertEquals(followUp.question(), query.lastRequest.queryText()); + assertEquals(AgentStatus.COMPLETED, result.status()); + assertEquals(1, query.callCount); + } + @Test void unavailableDataIsNotReportedAsNoTasks() { var query = new CapturingQueryService(response(