AS AgentScopeAPI 手册 / API Reference

CompactionConfig

public class CompactionConfig
源码Source 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_TOKENS
staticfinal
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_PROMPT
staticfinal
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
staticfinal

回退 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).

源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:67

DEFAULT_SUMMARY_PROMPT

public static final String DEFAULT_SUMMARY_PROMPT
staticfinal

默认摘要提示词字段。声明为 public static final String DEFAULT_SUMMARY_PROMPT。

Default summary prompt with structured format.

源码Source 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).

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:151–153

getTriggerTokens

public int getTriggerTokens()

获取 getTriggerTokens。

Estimated token count above which compaction is triggered.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:159–161

getReserved

public int getReserved()

获取 getReserved。

Token buffer reserved for the compaction process itself (summary prompt + output).

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:167–169

getKeepMessages

public int getKeepMessages()

获取 getKeepMessages。

Number of recent conversation messages (non-SYSTEM) to preserve verbatim.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:175–177

getKeepTokens

public int getKeepTokens()

获取 getKeepTokens。

Token budget for the preserved tail.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:188–190

getKeepTokensMin

public int getKeepTokensMin()

获取 getKeepTokensMin。

Returns the keep tokens min.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:192–194

getKeepTokensMax

public int getKeepTokensMax()

获取 getKeepTokensMax。

Returns the keep tokens max.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:196–198

getKeepTokensRatio

public double getKeepTokensRatio()

获取 getKeepTokensRatio。

Returns the keep tokens ratio.

返回Returns double
返回数值结果。Returns a numeric result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:200–202

getSummaryPrompt

public String getSummaryPrompt()

获取摘要提示词。

Prompt template used for the summarization LLM call.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:207–209

isFlushBeforeCompact

public boolean isFlushBeforeCompact()

判断是否 isFlushBeforeCompact。

Whether to flush long-term memories from the prefix before compaction.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:212–214

isOffloadBeforeCompact

public boolean isOffloadBeforeCompact()

判断是否到卸载原始消息到会话 JSONL 之前压缩。

Whether to offload raw messages to the session JSONL before compaction.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:217–219

getTruncateArgsConfig

public TruncateArgsConfig getTruncateArgsConfig()

获取 getTruncateArgsConfig。

Configuration for the lightweight pre-summarization argument truncation pass.

返回Returns TruncateArgsConfig
返回TruncateArgsConfig。Returns truncate args config.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:225–227

getPruneConfig

public PruneConfig getPruneConfig()

获取修剪配置。

Configuration for aggregate tool-result pruning.

返回Returns PruneConfig
返回PruneConfig。Returns prune config.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:232–234

getModel

public Model getModel()

获取模型。

Optional model override for compaction (summarization).

返回Returns Model
返回模型。Returns model.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:240–242

withEffective

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.

参数Parameters
名称Name类型Type说明Description
effectiveTriggerTokensinteffective Trigger 令牌数(类型 `int`)。The effective trigger tokens.
effectiveKeepTokensinteffective Keep 令牌数(类型 `int`)。The effective keep tokens.
返回Returns CompactionConfig
返回CompactionConfig。Returns compaction config.
源码Source io/agentscope/harness/agent/memory/compaction/CompactionConfig.java:248–265

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/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 TruncateArgsConfig

Truncate 参数配置,保存相关配置项。位于 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.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.