fix: harden agent prompt handling
This commit is contained in:
@@ -897,26 +897,8 @@ public class ConversationApplicationServiceImpl extends AbstractTaskExecuteServi
|
||||
return errorOutput(errorOutput, conversationDto);
|
||||
}
|
||||
|
||||
if (agentConfigDto.getModelComponentConfig().getTargetConfig() == null) {
|
||||
String errorMsg = I18nUtil.systemMessage("Backend.Chat.Error.AgentModelNotConfiguredOrOffline");
|
||||
errorOutput.setError(errorMsg);
|
||||
agentExecuteResult.setError(errorMsg);
|
||||
return errorOutput(errorOutput, conversationDto);
|
||||
}
|
||||
|
||||
// 用户数据权限
|
||||
UserDataPermissionDto userDataPermission = userDataPermissionRpcService.getUserDataPermission(RequestContext.get().getUserId());
|
||||
|
||||
//判断agent是否被管控,若被管控需判断有没有权限
|
||||
if (agentConfigDto.getAccessControl() != null && agentConfigDto.getAccessControl().equals(YesOrNoEnum.Y.getKey()) && !agentConfigDto.getCreatorId().equals(RequestContext.get().getUserId())) {
|
||||
if (userDataPermission.getAgentIds() == null || !userDataPermission.getAgentIds().contains(agentConfigDto.getId())) {
|
||||
String errorMsg = I18nUtil.systemMessage("Backend.Chat.Error.NoAgentPermission");
|
||||
errorOutput.setError(errorMsg);
|
||||
agentExecuteResult.setError(errorMsg);
|
||||
return errorOutput(errorOutput, conversationDto);
|
||||
}
|
||||
}
|
||||
|
||||
Object targetConfig = agentConfigDto.getModelComponentConfig().getTargetConfig();
|
||||
// 模型变化后是否需要重启智能体(通用智能体需要重启生效);全局模型在开启代理的情况下无需重启
|
||||
String selectedKey = "agent.model.selected:" + RequestContext.get().getUserId() + ":" + agentConfigDto.getId();
|
||||
@@ -959,6 +941,23 @@ public class ConversationApplicationServiceImpl extends AbstractTaskExecuteServi
|
||||
}
|
||||
}
|
||||
|
||||
if (targetConfig == null) {
|
||||
String errorMsg = I18nUtil.systemMessage("Backend.Chat.Error.AgentModelNotConfiguredOrOffline");
|
||||
errorOutput.setError(errorMsg);
|
||||
agentExecuteResult.setError(errorMsg);
|
||||
return errorOutput(errorOutput, conversationDto);
|
||||
}
|
||||
|
||||
//判断agent是否被管控,若被管控需判断有没有权限
|
||||
if (agentConfigDto.getAccessControl() != null && agentConfigDto.getAccessControl().equals(YesOrNoEnum.Y.getKey()) && !agentConfigDto.getCreatorId().equals(RequestContext.get().getUserId())) {
|
||||
if (userDataPermission.getAgentIds() == null || !userDataPermission.getAgentIds().contains(agentConfigDto.getId())) {
|
||||
String errorMsg = I18nUtil.systemMessage("Backend.Chat.Error.NoAgentPermission");
|
||||
errorOutput.setError(errorMsg);
|
||||
agentExecuteResult.setError(errorMsg);
|
||||
return errorOutput(errorOutput, conversationDto);
|
||||
}
|
||||
}
|
||||
|
||||
//付费检查,评估是否可以继续执行,当前只要积分大于零,且订阅过智能体就可以执行
|
||||
PriceEstimate priceEstimate = estimatePrice(agentConfigDto, tryReqDto, Objects.equals(conversationDto.getDevMode(), YesOrNoEnum.Y.getKey()), isDefaultModel);
|
||||
if (!priceEstimate.isPass()) {
|
||||
|
||||
@@ -174,7 +174,7 @@ public class SandboxAgentClient {
|
||||
SandboxServerConfig.SandboxServer sandboxServer = sandboxServerConfigService.selectServer(agentContext.getTenantConfig(), agentContext.getUserId(), agentContext.getConversation().getSandboxServerId());
|
||||
// Start sandbox service
|
||||
if (sandboxServer.getScope() == SandboxScopeEnum.USER) {
|
||||
checkAgentIfAlive(agentContext, sandboxServer)
|
||||
continueAfterAgentStatusCheck(checkAgentIfAlive(agentContext, sandboxServer))
|
||||
.doOnSuccess(res0 -> {
|
||||
// agent not started, append prompt
|
||||
try {
|
||||
@@ -183,7 +183,6 @@ public class SandboxAgentClient {
|
||||
sink.error(e);
|
||||
}
|
||||
})
|
||||
.onErrorResume(throwable -> Mono.just(false))
|
||||
.subscribe();
|
||||
} else {
|
||||
startSandbox(agentContext, sandboxServer)
|
||||
@@ -196,7 +195,7 @@ public class SandboxAgentClient {
|
||||
}
|
||||
return;
|
||||
}
|
||||
checkAgentIfAlive(agentContext, sandboxServer)
|
||||
continueAfterAgentStatusCheck(checkAgentIfAlive(agentContext, sandboxServer))
|
||||
.doOnSuccess(res0 -> {
|
||||
// agent not started, append prompt
|
||||
try {
|
||||
@@ -205,7 +204,6 @@ public class SandboxAgentClient {
|
||||
sink.error(e);
|
||||
}
|
||||
})
|
||||
.onErrorResume(throwable -> Mono.just(false))
|
||||
.subscribe();
|
||||
})
|
||||
.onErrorResume(Mono::error).doOnError(sink::error)
|
||||
@@ -232,6 +230,10 @@ public class SandboxAgentClient {
|
||||
return sseFlux;
|
||||
}
|
||||
|
||||
static Mono<Boolean> continueAfterAgentStatusCheck(Mono<Boolean> statusProbe) {
|
||||
return statusProbe.onErrorResume(throwable -> Mono.just(false));
|
||||
}
|
||||
|
||||
private static Mono<Boolean> checkAgentIfAlive(AgentContext agentContext, SandboxServerConfig.SandboxServer sandboxServer) {
|
||||
return Mono.create(sink -> {
|
||||
//Query agent startup status/computer/agent/status
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xspaceagi.agent.core.infra.component.agent;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
class SandboxAgentClientTest {
|
||||
|
||||
@Test
|
||||
void statusProbeFailureContinuesAsNotAlive() {
|
||||
StepVerifier.create(SandboxAgentClient.continueAfterAgentStatusCheck(Mono.error(new RuntimeException("probe failed"))))
|
||||
.expectNext(false)
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user