Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions agentscope-distribution/agentscope-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-autocontext-memory</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-memory-bailian</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions agentscope-distribution/agentscope-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@
<version>${project.version}</version>
</dependency>

<!-- AgentScope Extensions Auto Context Memory -->
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-autocontext-memory</artifactId>
<version>${project.version}</version>
</dependency>

<!-- AgentScope Extensions Bailian Long Term Memory -->
<dependency>
<groupId>io.agentscope</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2024-2026 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-mem</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>agentscope-extensions-autocontext-memory</artifactId>
<name>AgentScope Java - Extensions - AutoContext Memory</name>
<description>Auto context compression and offload for AgentScope Java</description>

<dependencies>
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-core</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Copyright 2024-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.memory.autocontext;

/** Configuration for auto context compression. */
public class AutoContextConfig {

long largePayloadThreshold = 5 * 1024;
long maxToken = 128 * 1024;
double tokenRatio = 0.75;
int offloadSinglePreview = 200;
int msgThreshold = 100;
int lastKeep = 50;
int minConsecutiveToolMessages = 6;
double currentRoundCompressionRatio = 0.3;
int minCompressionTokenThreshold = 5000;
private PromptConfig customPrompt;

public long getLargePayloadThreshold() {
return largePayloadThreshold;
}

public long getMaxToken() {
return maxToken;
}

public double getTokenRatio() {
return tokenRatio;
}

public int getOffloadSinglePreview() {
return offloadSinglePreview;
}

public int getMsgThreshold() {
return msgThreshold;
}

public int getLastKeep() {
return lastKeep;
}

public int getMinConsecutiveToolMessages() {
return minConsecutiveToolMessages;
}

public double getCurrentRoundCompressionRatio() {
return currentRoundCompressionRatio;
}

public int getMinCompressionTokenThreshold() {
return minCompressionTokenThreshold;
}

public PromptConfig getCustomPrompt() {
return customPrompt;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private final AutoContextConfig config = new AutoContextConfig();

public Builder largePayloadThreshold(long largePayloadThreshold) {
config.largePayloadThreshold = largePayloadThreshold;
return this;
}

public Builder maxToken(long maxToken) {
config.maxToken = maxToken;
return this;
}

public Builder tokenRatio(double tokenRatio) {
config.tokenRatio = tokenRatio;
return this;
}

public Builder offloadSinglePreview(int offloadSinglePreview) {
config.offloadSinglePreview = offloadSinglePreview;
return this;
}

public Builder msgThreshold(int msgThreshold) {
config.msgThreshold = msgThreshold;
return this;
}

public Builder lastKeep(int lastKeep) {
config.lastKeep = lastKeep;
return this;
}

public Builder minConsecutiveToolMessages(int minConsecutiveToolMessages) {
config.minConsecutiveToolMessages = minConsecutiveToolMessages;
return this;
}

public Builder currentRoundCompressionRatio(double currentRoundCompressionRatio) {
config.currentRoundCompressionRatio = currentRoundCompressionRatio;
return this;
}

public Builder minCompressionTokenThreshold(int minCompressionTokenThreshold) {
config.minCompressionTokenThreshold = minCompressionTokenThreshold;
return this;
}

public Builder customPrompt(PromptConfig customPrompt) {
config.customPrompt = customPrompt;
return this;
}

public AutoContextConfig build() {
Comment thread
guslegend0510 marked this conversation as resolved.
validate();
AutoContextConfig result = new AutoContextConfig();
result.largePayloadThreshold = config.largePayloadThreshold;
result.maxToken = config.maxToken;
result.tokenRatio = config.tokenRatio;
result.offloadSinglePreview = config.offloadSinglePreview;
result.msgThreshold = config.msgThreshold;
result.lastKeep = config.lastKeep;
result.minConsecutiveToolMessages = config.minConsecutiveToolMessages;
result.currentRoundCompressionRatio = config.currentRoundCompressionRatio;
result.minCompressionTokenThreshold = config.minCompressionTokenThreshold;
result.customPrompt = config.customPrompt;
return result;
}

private void validate() {
requirePositive(config.largePayloadThreshold, "largePayloadThreshold");
requirePositive(config.maxToken, "maxToken");
requireRatio(config.tokenRatio, "tokenRatio");
requireNonNegative(config.offloadSinglePreview, "offloadSinglePreview");
requirePositive(config.msgThreshold, "msgThreshold");
requireNonNegative(config.lastKeep, "lastKeep");
requirePositive(config.minConsecutiveToolMessages, "minConsecutiveToolMessages");
requireRatio(config.currentRoundCompressionRatio, "currentRoundCompressionRatio");
requirePositive(config.minCompressionTokenThreshold, "minCompressionTokenThreshold");
}

private void requirePositive(long value, String fieldName) {
if (value <= 0) {
throw new IllegalArgumentException(fieldName + " must be positive");
}
}

private void requirePositive(int value, String fieldName) {
if (value <= 0) {
throw new IllegalArgumentException(fieldName + " must be positive");
}
}

private void requireNonNegative(int value, String fieldName) {
if (value < 0) {
throw new IllegalArgumentException(fieldName + " must be non-negative");
}
}

private void requireRatio(double value, String fieldName) {
if (value <= 0.0 || value > 1.0) {
throw new IllegalArgumentException(fieldName + " must be in (0.0, 1.0]");
}
}
}
}
Loading
Loading