fix: 仅按 Token 阈值压缩上下文

- EasyFlow 调用方忽略新旧消息数压缩配置

- 保留最小 Token 阈值与最近消息保留数量

- 隐藏智能体配置页的消息数阈值
This commit is contained in:
2026-07-23 19:49:25 +08:00
parent 8b4ba65e1c
commit 417e846cbd
3 changed files with 60 additions and 34 deletions

View File

@@ -54,6 +54,11 @@ public class AgentRuntimeCompiler {
private static final Logger LOG = LoggerFactory.getLogger(AgentRuntimeCompiler.class);
private static final int LOG_TEXT_MAX_LENGTH = 500;
/**
* EasyFlow 仅按 Token 阈值触发压缩,消息数阈值固定为不可达上限。
*/
private static final int DISABLED_MESSAGE_COMPRESSION_THRESHOLD = Integer.MAX_VALUE;
private static final Pattern MCP_INPUT_PATTERN = Pattern.compile("\\$\\{input:([A-Za-z0-9_.-]+)}");
@Resource
@@ -147,6 +152,14 @@ public class AgentRuntimeCompiler {
return options;
}
/**
* 编译 Agent 记忆策略。
*
* <p>EasyFlow 侧统一关闭按消息数触发压缩,已保存的旧消息阈值配置不会进入运行时。</p>
*
* @param config 记忆配置
* @return 运行时记忆策略
*/
private AgentMemoryPolicy buildMemoryPolicy(Map<String, Object> config) {
AgentMemoryPolicy policy = new AgentMemoryPolicy();
policy.setType(memoryTypeValue(config, "type"));
@@ -159,17 +172,7 @@ public class AgentRuntimeCompiler {
if (enabled != null) {
parameter.setEnabled(enabled);
}
Integer msgThreshold = intValue(compressionConfig, "msgThreshold");
if (msgThreshold == null) {
msgThreshold = intValue(config, "maxAttachedMessageCount");
}
if (msgThreshold == null) {
msgThreshold = intValue(config, "historyLimit");
}
if (msgThreshold != null) {
parameter.setMsgThreshold(msgThreshold);
policy.setMaxAttachedMessageCount(msgThreshold);
}
parameter.setMsgThreshold(DISABLED_MESSAGE_COMPRESSION_THRESHOLD);
Integer lastKeep = intValue(compressionConfig, "lastKeep");
if (lastKeep != null) {
parameter.setLastKeep(lastKeep);