Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void main(String[] args) {
.apiBaseUrl("https://api.mem0.ai");
Mem0LongTermMemory longTermMemory = builder.build();
AutoContextConfig autoContextConfig =
AutoContextConfig.builder().tokenRatio(0.3).lastKeep(10).build();
AutoContextConfig.builder().tokenRatio(0.4).lastKeep(10).build();
AutoContextMemory memory = new AutoContextMemory(autoContextConfig, chatModel);

Toolkit toolkit = new Toolkit();
Expand All @@ -83,7 +83,7 @@ public static void main(String[] args) {
.enablePlan()
.toolkit(toolkit)
.build();
String sessionId = "session1234567";
String sessionId = "session000005";
// Set up session path
Path sessionPath =
Paths.get(System.getProperty("user.home"), ".agentscope", "examples", "sessions");
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class AutoContextConfig {
/** Minimum number of consecutive tool messages required for compression. */
int minConsecutiveToolMessages = 6;

/** Compression ratio (0.0-1.0) for current round messages. Default is 0.3 (30%). */
double currentRoundCompressionRatio = 0.3;

public long getLargePayloadThreshold() {
return largePayloadThreshold;
}
Expand Down Expand Up @@ -110,6 +113,14 @@ public void setMinConsecutiveToolMessages(int minConsecutiveToolMessages) {
this.minConsecutiveToolMessages = minConsecutiveToolMessages;
}

public double getCurrentRoundCompressionRatio() {
return currentRoundCompressionRatio;
}

public void setCurrentRoundCompressionRatio(double currentRoundCompressionRatio) {
this.currentRoundCompressionRatio = currentRoundCompressionRatio;
}

/**
* Creates a new Builder instance for constructing AutoContextConfig.
*
Expand Down Expand Up @@ -142,6 +153,7 @@ public static class Builder {
private int msgThreshold = 100;
private int lastKeep = 50;
private int minConsecutiveToolMessages = 6;
private double currentRoundCompressionRatio = 0.3;

/**
* Sets the threshold (in characters) for large payload messages to be offloaded.
Expand Down Expand Up @@ -220,6 +232,19 @@ public Builder minConsecutiveToolMessages(int minConsecutiveToolMessages) {
return this;
}

/**
* Sets the compression ratio (0.0-1.0) for current round messages.
* Default is 0.3 (30%), meaning the compressed output should be approximately
* 30% of the original token count.
*
* @param currentRoundCompressionRatio the compression ratio (0.0-1.0)
* @return this builder instance for method chaining
*/
public Builder currentRoundCompressionRatio(double currentRoundCompressionRatio) {
this.currentRoundCompressionRatio = currentRoundCompressionRatio;
return this;
}

/**
* Builds and returns a new AutoContextConfig instance with the configured values.
*
Expand All @@ -234,6 +259,7 @@ public AutoContextConfig build() {
config.msgThreshold = this.msgThreshold;
config.lastKeep = this.lastKeep;
config.minConsecutiveToolMessages = this.minConsecutiveToolMessages;
config.currentRoundCompressionRatio = this.currentRoundCompressionRatio;
return config;
}
}
Expand Down
Loading
Loading