CompactionConfig
public class CompactionConfig
io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:61–607压缩配置,保存相关配置项。位于 io.agentscope.harness.agent.memory.compaction 包。核心成员包括 getTriggerMessages、getTriggerTokens、getReserved、getKeepMessages、getKeepTokens、getKeepTokensMin。
Configuration for conversation compaction (summarization).
-
trigger — when to run compaction (by token count or message count)
-
keep — how many recent messages to preserve verbatim after compaction
Defaults (dynamic mode):
-
Trigger dynamically when estimated token count reaches
model.contextWindow - reserved(20k). Falls back to {@value #FALLBACK_TRIGGER_TOKENS} tokens when the model does not report its context window, or at 50 messages (whichever comes first) -
Keep tail: dynamically computed as
min(8k, max(2k, usable * 0.25))tokens. Falls back to 20 messages when the model does not report its context window -
Prune: enabled by default — aggregates old tool result outputs and trims them when the prunable total exceeds 20k tokens (protects the most recent 40k tokens)
-
Summarization is enabled; memory flush and offload are both enabled before summary
Memory prompt landscape
The harness has three LLM-driven memory operations, each with its own prompt; they live in two complementary config classes:
-
Compaction summary — distills the conversation prefix into one summary message before reasoning. Prompt:
#getSummaryPrompt()on this class. -
Flush — extracts long-term memories into today's daily ledger. Prompt:
MemoryConfig.flushPrompt(). -
Consolidation — periodically merges daily ledgers into
MEMORY.md. Prompt:MemoryConfig.consolidationPrompt().
Configure the latter two via HarnessAgent.builder().memory(MemoryConfig...).
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 A class in io.agentscope.harness.agent.memory.compaction that persists and restores session and memory data across calls. |
TruncateArgsConfig | 类class | Truncate 参数配置,保存相关配置项。 Configuration for the lightweight argument-truncation pass that runs before
summarization. |
PruneConfig | 类class | 修剪配置,保存相关配置项。 Configuration for aggregate tool-result pruning. |
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
FALLBACK_TRIGGER_TOKENSstaticfinal | int | 回退 TRIGGER 令牌数字段。 Fallback trigger threshold (in tokens) when the model does not report its context window
and `triggerTokens` is set to dynamic mode (0). |
DEFAULT_SUMMARY_PROMPTstaticfinal | String | 默认摘要提示词字段。 Default summary prompt with structured format. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public int getTriggerMessages() | 获取 `getTriggerMessages`。 Message count above which compaction is triggered (0 = disabled). |
public int getTriggerTokens() | 获取 `getTriggerTokens`。 Estimated token count above which compaction is triggered. |
public int getReserved() | 获取 `getReserved`。 Token buffer reserved for the compaction process itself (summary prompt + output). |
public int getKeepMessages() | 获取 `getKeepMessages`。 Number of recent *conversation* messages (non-SYSTEM) to preserve verbatim. |
public int getKeepTokens() | 获取 `getKeepTokens`。 Token budget for the preserved tail. |
public int getKeepTokensMin() | 获取 `getKeepTokensMin`。 Returns the keep tokens min. |
public int getKeepTokensMax() | 获取 `getKeepTokensMax`。 Returns the keep tokens max. |
public double getKeepTokensRatio() | 获取 `getKeepTokensRatio`。 Returns the keep tokens ratio. |
public String getSummaryPrompt() | 获取摘要提示词。 Prompt template used for the summarization LLM call. |
public boolean isFlushBeforeCompact() | 判断是否 `isFlushBeforeCompact`。 Whether to flush long-term memories from the prefix before compaction. |
public boolean isOffloadBeforeCompact() | 判断是否到卸载原始消息到会话 JSONL 之前压缩。 Whether to offload raw messages to the session JSONL before compaction. |
public TruncateArgsConfig getTruncateArgsConfig() | 获取 `getTruncateArgsConfig`。 Configuration for the lightweight pre-summarization argument truncation pass. |
public PruneConfig getPruneConfig() | 获取修剪配置。 Configuration for aggregate tool-result pruning. |
public Model getModel() | 获取模型。 Optional model override for compaction (summarization). |
public CompactionConfig withEffective(int effectiveTriggerTokens, int effectiveKeepTokens) | 执行 `withEffective` 方法。 Creates a resolved copy with effective trigger and keep values computed from a model's
context window. |
public static Builder builder()static | 返回构建器实例。 Returns the builder. |
字段详情Field Detail
FALLBACK_TRIGGER_TOKENS
public static final int FALLBACK_TRIGGER_TOKENS
回退 TRIGGER 令牌数字段。声明为 public static final int FALLBACK_TRIGGER_TOKENS。
Fallback trigger threshold (in tokens) when the model does not report its context window and triggerTokens is set to dynamic mode (0).
io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:67DEFAULT_SUMMARY_PROMPT
public static final String DEFAULT_SUMMARY_PROMPT
默认摘要提示词字段。声明为 public static final String DEFAULT_SUMMARY_PROMPT。
Default summary prompt with structured format.
io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:70–116方法详情Method Detail
getTriggerMessages
public int getTriggerMessages()
获取 getTriggerMessages。
Message count above which compaction is triggered (0 = disabled).
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:151–153getTriggerTokens
public int getTriggerTokens()
获取 getTriggerTokens。
Estimated token count above which compaction is triggered.
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:159–161getReserved
public int getReserved()
获取 getReserved。
Token buffer reserved for the compaction process itself (summary prompt + output).
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:167–169getKeepMessages
public int getKeepMessages()
获取 getKeepMessages。
Number of recent conversation messages (non-SYSTEM) to preserve verbatim.
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:175–177getKeepTokens
public int getKeepTokens()
获取 getKeepTokens。
Token budget for the preserved tail.
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:188–190getKeepTokensMin
public int getKeepTokensMin()
获取 getKeepTokensMin。
Returns the keep tokens min.
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:192–194getKeepTokensMax
public int getKeepTokensMax()
获取 getKeepTokensMax。
Returns the keep tokens max.
intio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:196–198getKeepTokensRatio
public double getKeepTokensRatio()
获取 getKeepTokensRatio。
Returns the keep tokens ratio.
doubleio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:200–202getSummaryPrompt
public String getSummaryPrompt()
获取摘要提示词。
Prompt template used for the summarization LLM call.
Stringio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:207–209isFlushBeforeCompact
public boolean isFlushBeforeCompact()
判断是否 isFlushBeforeCompact。
Whether to flush long-term memories from the prefix before compaction.
booleanio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:212–214isOffloadBeforeCompact
public boolean isOffloadBeforeCompact()
判断是否到卸载原始消息到会话 JSONL 之前压缩。
Whether to offload raw messages to the session JSONL before compaction.
booleanio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:217–219getTruncateArgsConfig
public TruncateArgsConfig getTruncateArgsConfig()
获取 getTruncateArgsConfig。
Configuration for the lightweight pre-summarization argument truncation pass.
TruncateArgsConfigio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:225–227getPruneConfig
public PruneConfig getPruneConfig()
获取修剪配置。
Configuration for aggregate tool-result pruning.
PruneConfigio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:232–234getModel
public Model getModel()
获取模型。
Optional model override for compaction (summarization).
Modelio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:240–242withEffective
public CompactionConfig withEffective(int effectiveTriggerTokens, int effectiveKeepTokens)
执行 withEffective 方法。
Creates a resolved copy with effective trigger and keep values computed from a model's context window.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
effectiveTriggerTokens | int | effective Trigger 令牌数(类型 `int`)。The effective trigger tokens. |
effectiveKeepTokens | int | effective Keep 令牌数(类型 `int`)。The effective keep tokens. |
CompactionConfigio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:248–265builder
public static Builder builder()
返回构建器实例。
Returns the builder.
Builderio/agentscope/harness/agent/memory/compaction/CompactionConfig.java:267–269嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.harness.agent.memory.compaction 包。核心成员包括 triggerMessages、triggerTokens、reserved、keepMessages、keepTokens、keepTokensMin。
A class in io.agentscope.harness.agent.memory.compaction that persists and restores session and memory data across calls. Declared in io.agentscope.harness.agent.memory.compaction.
TruncateArgsConfig
public static class TruncateArgsConfigTruncate 参数配置,保存相关配置项。位于 io.agentscope.harness.agent.memory.compaction 包。核心成员包括 getTriggerMessages、getTriggerTokens、getKeepMessages、getKeepTokens、getMaxArgLength、getTruncationText。
Configuration for the lightweight argument-truncation pass that runs before summarization.
When triggered, large string arguments of ToolUseBlocks in older messages
(before the keep window) are clipped to #getMaxArgLength() characters.
This is a cheap, non-LLM operation that prevents context ballooning from verbose
tool invocations (e.g., write_file, edit_file).
Defaults (when enabled via Builder#truncateArgs(TruncateArgsConfig)):
-
Trigger at 25 messages or 40 000 tokens
-
Keep the 20 most recent messages untouched
-
Max argument length: 2 000 characters
PruneConfig
public static class PruneConfig修剪配置,保存相关配置项。位于 io.agentscope.harness.agent.memory.compaction 包。核心成员包括 defaults、getProtectTokens、getMinimumTokens、getMaxOutputChars、getExcludedTools、builder。
Configuration for aggregate tool-result pruning.
Prune walks backward through tool-result messages, protecting the most recent
#getProtectTokens() tokens of tool output. Older tool results beyond that
protection window are replaced with a head+tail preview when the total prunable
amount exceeds #getMinimumTokens().
This is a lightweight, non-LLM operation that runs inside
ConversationCompactor#compactIfNeeded before summarization.