fix: 仅按 Token 阈值压缩上下文
- EasyFlow 调用方忽略新旧消息数压缩配置 - 保留最小 Token 阈值与最近消息保留数量 - 隐藏智能体配置页的消息数阈值
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package tech.easyflow.agent.runtime;
|
||||
|
||||
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;
|
||||
@@ -65,6 +66,36 @@ public class AgentRuntimeCompilerModelConfigTest {
|
||||
Assert.assertEquals(AgentHttpVersionPolicy.AUTO, spec.getHttpVersionPolicy());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 EasyFlow 忽略新旧消息数阈值,仅保留 Token 压缩配置。
|
||||
*
|
||||
* @throws Exception 反射调用失败时抛出
|
||||
*/
|
||||
@Test
|
||||
public void memoryCompressionShouldIgnoreMessageThresholdConfiguration() throws Exception {
|
||||
AgentRuntimeCompiler compiler = new AgentRuntimeCompiler();
|
||||
Map<String, Object> compressionConfig = Map.of(
|
||||
"enabled", true,
|
||||
"msgThreshold", 12,
|
||||
"lastKeep", 8,
|
||||
"minCompressionTokenThreshold", 128000
|
||||
);
|
||||
Map<String, Object> memoryConfig = Map.of(
|
||||
"compressionParameter", compressionConfig,
|
||||
"maxAttachedMessageCount", 12,
|
||||
"historyLimit", 12
|
||||
);
|
||||
|
||||
AgentMemoryPolicy policy = invokeMemoryPolicy(compiler, memoryConfig);
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(Integer.MAX_VALUE),
|
||||
policy.getCompressionParameter().getMsgThreshold());
|
||||
Assert.assertEquals(Integer.valueOf(128000),
|
||||
policy.getCompressionParameter().getMinCompressionTokenThreshold());
|
||||
Assert.assertEquals(8, policy.getCompressionParameter().getLastKeep());
|
||||
Assert.assertEquals(50, policy.getMaxAttachedMessageCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建已注入模型服务的编译器。
|
||||
*
|
||||
@@ -127,4 +158,19 @@ public class AgentRuntimeCompilerModelConfigTest {
|
||||
method.setAccessible(true);
|
||||
return (AgentModelSpec) method.invoke(compiler, agent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用私有记忆策略编译方法。
|
||||
*
|
||||
* @param compiler 编译器
|
||||
* @param config 记忆配置
|
||||
* @return 记忆策略
|
||||
* @throws Exception 反射调用失败时抛出
|
||||
*/
|
||||
private AgentMemoryPolicy invokeMemoryPolicy(AgentRuntimeCompiler compiler,
|
||||
Map<String, Object> config) throws Exception {
|
||||
Method method = AgentRuntimeCompiler.class.getDeclaredMethod("buildMemoryPolicy", Map.class);
|
||||
method.setAccessible(true);
|
||||
return (AgentMemoryPolicy) method.invoke(compiler, config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user