fix(agent): bound user questions
This commit is contained in:
+3
@@ -177,6 +177,9 @@ public class AihrAgentOrchestrator {
|
||||
if (request == null || request.question() == null || request.question().isBlank()) {
|
||||
throw new ServiceException("问题不能为空", 400);
|
||||
}
|
||||
if (request.question().trim().length() > 1000) {
|
||||
throw new ServiceException("问题长度必须为 1-1000 字", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean needsKnowledge(String question) {
|
||||
|
||||
+15
@@ -21,6 +21,7 @@ import static org.dromara.aihr.agent.AihrAgentDto.Intent.KNOWLEDGE_QA;
|
||||
import static org.dromara.aihr.agent.AihrAgentDto.Intent.LIVE_MY_WORK;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@Tag("dev")
|
||||
@@ -104,6 +105,20 @@ class AihrAgentOrchestratorTest {
|
||||
assertEquals("opaque-draft", result.actionDraft().draftId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void questionLongerThanKnowledgeBoundaryIsRejectedBeforePlanning() {
|
||||
var query = new CapturingQueryService(response("unused", null, false));
|
||||
|
||||
var error = assertThrows(
|
||||
org.dromara.common.core.exception.ServiceException.class,
|
||||
() -> orchestrator(query).handle(request("A".repeat(1001)))
|
||||
);
|
||||
|
||||
assertEquals(400, error.getCode());
|
||||
assertTrue(error.getMessage().contains("1-1000"));
|
||||
assertEquals(0, query.callCount);
|
||||
}
|
||||
|
||||
private static AihrAgentOrchestrator orchestrator(CapturingQueryService query) {
|
||||
return orchestrator(query, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user