fix(agent): preserve broadcast consultation context
This commit is contained in:
+2
@@ -1,5 +1,6 @@
|
||||
package org.dromara.aihr.agent;
|
||||
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgeQueryDto.BroadcastContext;
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgeQueryDto.Citation;
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgeQueryDto.Resource;
|
||||
|
||||
@@ -95,6 +96,7 @@ public final class AihrAgentDto {
|
||||
List<SourceSummary> sourceSummary,
|
||||
List<Citation> citations,
|
||||
List<Resource> resources,
|
||||
BroadcastContext broadcastContext,
|
||||
Object data,
|
||||
ActionDraft actionDraft,
|
||||
Clarification clarification,
|
||||
|
||||
+4
-4
@@ -147,7 +147,7 @@ public class AihrAgentOrchestrator {
|
||||
return new AgentResponse(
|
||||
runId(), response.conversationId(), response.contextVersion(), plan.intent(), status, answer,
|
||||
sources,
|
||||
response.citations(), response.resources(), response.data(), actionDraft, null, List.of()
|
||||
response.citations(), response.resources(), response.broadcastContext(), response.data(), actionDraft, null, List.of()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class AihrAgentOrchestrator {
|
||||
return new AgentResponse(
|
||||
runId(), request.conversationId(), request.contextVersion(), plan.intent(), status, answer,
|
||||
List.of(new SourceSummary("WEB", response.provider(), OffsetDateTime.now().toString())),
|
||||
List.of(), List.of(), response, null,
|
||||
List.of(), List.of(), null, response, null,
|
||||
status == AgentStatus.NEEDS_INPUT
|
||||
? new Clarification("是否同意查询全网?", List.of())
|
||||
: null,
|
||||
@@ -199,7 +199,7 @@ public class AihrAgentOrchestrator {
|
||||
Clarification clarification) {
|
||||
return new AgentResponse(
|
||||
runId(), null, null, plan.intent(), status, answer, List.of(), List.of(), List.of(),
|
||||
null, null, clarification, List.of()
|
||||
null, null, null, clarification, List.of()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public class AihrAgentOrchestrator {
|
||||
return new AgentResponse(
|
||||
runId(), request == null ? null : request.conversationId(),
|
||||
request == null ? null : request.contextVersion(), plan.intent(), status, "",
|
||||
List.of(), List.of(), List.of(), null, null, null, List.of()
|
||||
List.of(), List.of(), List.of(), null, null, null, null, List.of()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ class AihrAgentAuditServiceTest {
|
||||
return new AgentResponse("agent_run_test", "conversation_1", 1L, Intent.LIVE_MY_WORK,
|
||||
AgentStatus.COMPLETED, "敏感答案",
|
||||
List.of(new SourceSummary("LIVE_DATA", "我的待办", "2026-07-24T20:00:00+08:00")),
|
||||
List.of(), List.of(), null, null, null, List.of());
|
||||
List.of(), List.of(), null, null, null, null, List.of());
|
||||
}
|
||||
|
||||
private static final class CapturingJdbcTemplate extends JdbcTemplate {
|
||||
|
||||
+20
-1
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.dromara.aihr.agent.AihrAgentDto.AgentRequest;
|
||||
import org.dromara.aihr.agent.AihrAgentDto.AgentStatus;
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgePrincipal;
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgeQueryDto.BroadcastContext;
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgeQueryDto.QueryRequest;
|
||||
import org.dromara.aihr.knowledge.domain.AihrKnowledgeQueryDto.QueryResponse;
|
||||
import org.dromara.aihr.knowledge.service.AihrKnowledgePrincipalResolver;
|
||||
@@ -64,6 +65,18 @@ class AihrAgentOrchestratorTest {
|
||||
assertTrue(result.sourceSummary().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void broadcastConsultationPreservesServerVerifiedContext() {
|
||||
var query = new CapturingQueryService(response("按高温作业规定执行。", null, false,
|
||||
new BroadcastContext(42L, "高温作业提醒", "2026-07-24T09:00:00")));
|
||||
|
||||
var result = orchestrator(query).handle(new AgentRequest(
|
||||
"这条消息里的高温规定是什么?", "conversation_1", 0L, null, 42L, false));
|
||||
|
||||
assertEquals(42L, query.lastRequest.broadcastMessageId());
|
||||
assertEquals(42L, result.broadcastContext().messageId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void socialAndClarificationDoNotInvokeKnowledge() {
|
||||
var query = new CapturingQueryService(response("unused", null, false));
|
||||
@@ -147,8 +160,14 @@ class AihrAgentOrchestratorTest {
|
||||
}
|
||||
|
||||
private static QueryResponse response(String answer, Object data, boolean noEvidence) {
|
||||
return response(answer, data, noEvidence, null);
|
||||
}
|
||||
|
||||
private static QueryResponse response(String answer, Object data, boolean noEvidence,
|
||||
BroadcastContext broadcastContext) {
|
||||
return new QueryResponse("request-1", "question", answer, List.of(), List.of(), noEvidence,
|
||||
"test", null, data, "conversation_1", 1L, "QA", "question", List.of());
|
||||
"test", null, data, "conversation_1", 1L, "QA", "question", List.of(), null,
|
||||
broadcastContext);
|
||||
}
|
||||
|
||||
private static final class CapturingQueryService extends AihrKnowledgeQueryService {
|
||||
|
||||
Reference in New Issue
Block a user