feat: 增加 system 消息格式配置
- 模型管理支持选择字符串或内容块数组格式 - 验证连接携带 system 消息并复用正式运行时模型配置 - 补充配置映射与验证消息角色测试
This commit is contained in:
@@ -4,6 +4,7 @@ import com.easyagents.agent.runtime.memory.AgentMemoryPolicy;
|
||||
import com.easyagents.agent.runtime.model.AgentGenerationOptions;
|
||||
import com.easyagents.agent.runtime.model.AgentHttpVersionPolicy;
|
||||
import com.easyagents.agent.runtime.model.AgentModelSpec;
|
||||
import com.easyagents.agent.runtime.model.AgentSystemContentFormat;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import tech.easyflow.agent.entity.Agent;
|
||||
@@ -66,6 +67,36 @@ public class AgentRuntimeCompilerModelConfigTest {
|
||||
Assert.assertEquals(AgentHttpVersionPolicy.AUTO, spec.getHttpVersionPolicy());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证模型 options 中的 system content 格式会编译到中立模型声明。
|
||||
*
|
||||
* @throws Exception 反射调用失败时抛出
|
||||
*/
|
||||
@Test
|
||||
public void modelSystemContentFormatShouldCompileFromOptions() throws Exception {
|
||||
Model model = model(Map.of("agentSystemContentFormat", "TEXT_PARTS"));
|
||||
AgentRuntimeCompiler compiler = compiler(model);
|
||||
|
||||
AgentModelSpec spec = invokeModelSpec(compiler);
|
||||
|
||||
Assert.assertEquals(AgentSystemContentFormat.TEXT_PARTS, spec.getSystemContentFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证未知 system content 格式安全回退到字符串。
|
||||
*
|
||||
* @throws Exception 反射调用失败时抛出
|
||||
*/
|
||||
@Test
|
||||
public void unknownSystemContentFormatShouldFallbackToString() throws Exception {
|
||||
Model model = model(Map.of("agentSystemContentFormat", "PARTS"));
|
||||
AgentRuntimeCompiler compiler = compiler(model);
|
||||
|
||||
AgentModelSpec spec = invokeModelSpec(compiler);
|
||||
|
||||
Assert.assertEquals(AgentSystemContentFormat.STRING, spec.getSystemContentFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 EasyFlow 忽略新旧消息数阈值,仅保留 Token 压缩配置。
|
||||
*
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.easyagents.agent.runtime.model.AgentModelSpec;
|
||||
import io.agentscope.core.message.Base64Source;
|
||||
import io.agentscope.core.message.ImageBlock;
|
||||
import io.agentscope.core.message.Msg;
|
||||
import io.agentscope.core.message.MsgRole;
|
||||
import io.agentscope.core.message.TextBlock;
|
||||
import io.agentscope.core.model.ChatResponse;
|
||||
import io.agentscope.core.model.GenerateOptions;
|
||||
@@ -48,6 +49,7 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
||||
Assert.assertEquals("HTTP_1_1", result.getEffectiveHttpVersion());
|
||||
Assert.assertEquals(List.of(false, true), factory.getFactoryStreams());
|
||||
Assert.assertEquals(List.of(false, true), factory.getRequestStreams());
|
||||
Assert.assertEquals(List.of(MsgRole.SYSTEM, MsgRole.USER), factory.getMessageRoles().get(0));
|
||||
Assert.assertEquals(List.of(false, false), factory.getEnableThinkingValues());
|
||||
Assert.assertEquals(List.of(false, false), factory.getChatTemplateThinkingValues());
|
||||
}
|
||||
@@ -190,6 +192,8 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
||||
private final List<Boolean> requestStreams = new ArrayList<>();
|
||||
/** 模型请求收到的消息。 */
|
||||
private final List<Msg> messages = new ArrayList<>();
|
||||
/** 各阶段请求消息的角色顺序。 */
|
||||
private final List<List<MsgRole>> messageRoles = new ArrayList<>();
|
||||
/** OpenAI-compatible 请求中的思考开关。 */
|
||||
private final List<Object> enableThinkingValues = new ArrayList<>();
|
||||
/** GPUStack 模板参数中的思考开关。 */
|
||||
@@ -241,7 +245,8 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
||||
List<ToolSchema> tools,
|
||||
GenerateOptions options) {
|
||||
requestStreams.add(Boolean.TRUE.equals(options.getStream()));
|
||||
messages.add(inputMessages.get(0));
|
||||
messages.add(inputMessages.get(inputMessages.size() - 1));
|
||||
messageRoles.add(inputMessages.stream().map(Msg::getRole).toList());
|
||||
return responses;
|
||||
}
|
||||
|
||||
@@ -284,6 +289,15 @@ public class AgentScopeChatModelConnectivityVerifierTest {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取各阶段请求消息的角色顺序。
|
||||
*
|
||||
* @return 消息角色顺序
|
||||
*/
|
||||
private List<List<MsgRole>> getMessageRoles() {
|
||||
return messageRoles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 OpenAI-compatible 请求中的思考开关。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user